Determine what package from a class object ???

Source code below will print name for package that belong to it's own class object. It should print null because class object that create from java file below not belong to any package.

************************************************************
COMPLETE SOURCE CODE FOR : DeterminePackageForClassObject.java
************************************************************


public class DeterminePackageForClassObject
{
public static void main(String[]args)
{
try
{
Class temp=Class.forName("DeterminePackageForClassObject");
System.out.println("PACKAGE FOR THIS CLASS OBJECT IS :"+temp.getPackage());
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


************************************************************
JUST COMPILE AND EXECUTE IT
************************************************************

Get all interface from a class object

This program will print name of interface that implemented by this class

**********************************************************
COMPLETE SOURCE CODE FOR : ListingAllInterfaceFromClassObject.java
**********************************************************


import java.awt.event.ActionListener;//INTERFACE 1
//Runnable-INTERFACE 2
import java.awt.event.ActionEvent;

public class ListingAllInterfaceFromClassObject implements ActionListener,Runnable
{
public void actionPerformed(ActionEvent evt)
{
//NO IMPLEMENTATION
}

public void run()
{
//NO IMPLEMENTATION
}

public static void main(String[]args)
{
try
{
Class temp=Class.forName("ListingAllInterfaceFromClassObject");
Class[]allInterface=temp.getInterfaces();
int allInterfaceLength=allInterface.length;
int temp2=0;
while(temp2!=allInterfaceLength)
{
System.out.println("INTERFACE "+(temp2+1)+" :"+(allInterface[temp2].getSimpleName()));
temp2=temp2+1;
}
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


**********************************************************
JUST COMPILE AND EXECUTE IT
**********************************************************

Get superclass for an object class ???

Source code below will get superclass for it's own object class. It will print name for it's superclass.

*****************************************************************
COMPLETE SOURCE CODE FOR : GettingSuperclass.java
*****************************************************************


public class GettingSuperclass
{
public static void main(String[]args)
{
try
{
Class temp=Class.forName("GettingSuperclass");
Class thisIsSuper=temp.getSuperclass();

System.out.println("Superclass for this class is : "+thisIsSuper.getSimpleName());
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


*****************************************************************
JUST COMPILE AND EXECUTE IT
*****************************************************************

Determine what is represent by a class object, whether an interface or a class ???

This tutorial will use CreateInterface.java to determine whether class object from it, is an interface or a class. You can get it at Java Interface ( Part 1). Before you compile and execute source code below, you must make sure CreateInterface.class is locate same location with this java file.

***********************************************************
COMPLETE SOURCE CODE FOR : DetermineClassObjectIsClassOrInterface.java
***********************************************************


public class DetermineClassObjectIsClassOrInterface
{
public static void main(String[]args)
{
try
{
Class temp=Class.forName("CreateInterface");
if(temp.isInterface())
{
System.out.println("THIS CLASS OBJECT IS REPRESENT AN INTERFACE");
}
else
{
System.out.println("THIS CLASS OBJECT IS REPRESENT AN CLASS");
}
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


***********************************************************
JUST COMPILE AND EXECUTE IT
***********************************************************

Java Interface (Part 2)

This tutorial will show you, how to use a java interface that we create in my previous post. When we want to use a java interface, we must overwrite abstract method that contain in the interface. Source code below will overwrite abstract method in java interface (CreateInterface) called print(). Before we can use a java interface we must put implements keyword followed by interface name. You also must import interface into your program. In the example below, i don't import the interface because, it's location is same with this java file.

*******************************************************
COMPLETE SOURCE CODE FOR : UseJavaInterface.java
*******************************************************


public class UseJavaInterface implements CreateInterface
{
public void print()
{
System.out.println("HI");
}
}


*******************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************

Java Interface (Part 1)

Source code below will create a java interface, named CreateInterface. When you want to create an interface, you just change "class" keyword after "public" keyword to "interface" keyword and after that followed by your java file name. In a java interface, all method is only abstract method. You don't need to put access modifier to abstract method in a java interface. This is because all of it will be set to public. So when you want to overwrite an abstract method from an interface you must know, access modifier that you must use is public, not private or protected. After that put return type followed by name for the abstract method. In source code below, abstract method is print(). What is java abstract method ??? The answer is, an abstract method is a method without body. If you can see, abstract method print() end after ")" ,not contain any implementation code. Where to put implementation code for a java abstract method ??? You will put it's implementation code in java concrete class that implements this interface by overwrite it.

*****************************************************************
COMPLETE SOURCE CODE FOR : CreateInterface.java
*****************************************************************


public interface CreateInterface
{
void print();
}


*****************************************************************
JUST COMPILE AND EXECUTE IT
*****************************************************************

Get class name from class object ???

*****************************************************************
COMPLETE SOURCE CODE FOR : GetClassNameFromClassObject.java
*****************************************************************


public class GetClassNameFromClassObject
{
public static void main(String[]args)
{
try
{
//For example of this source code, we will use java predefined class named Object

//You can change class name instead of java.lang.Object
Class a=Class.forName("java.lang.Object");

//Now we will print the name of the class
System.out.println("IT'S NAME IS : "+a.getSimpleName());
}

catch(Exception exception)
{
exception.printStackTrace();
}
}
}


*****************************************************************
JUST COMPILE AND EXECUTE IT
*****************************************************************

Change java radio button text color

*********************************************************************
COMPLETE SOURCE CODE FOR : ChangeJavaRadioButtonTextColor.java
*********************************************************************


import javax.swing.JFrame;
import javax.swing.JRadioButton;

import java.awt.FlowLayout;
import java.awt.Color;

public class ChangeJavaRadioButtonTextColor
{
public static void main(String[]args)
{
JRadioButton a=new JRadioButton("I AM A RADIO BUTTON");
JFrame b=new JFrame("CHANGE RADIO BUTTON TEXT COLOR");
b.setLayout(new FlowLayout());

//METHOD setForeground will change radio button's text color
//You can see more color in Color class on Java API
a.setForeground(Color.GREEN);

b.add(a);

b.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.setSize(400,400);
b.setVisible(true);
}
}


*********************************************************************
JUST COMPILE AND EXECUTE IT
*********************************************************************

Source code to get class object ???

*******************************************************
COMPLETE SOURCE CODE FOR : GetClassObject.java
*******************************************************


public class GetClassObject
{
public static void main(String[]args)
{
try
{
//This program will get class object for Object class
Class a=Class.forName("java.lang.Object");
}
catch(Exception exception)
{
exception.printStackTrace();
}
}
}


*******************************************************
JUST COMPILE AND EXECUTE IT
*******************************************************

How to know all method that contain in a java class file ???

How to know all method that contain in a java class file ???
Source code below will list all method that contain in java predefined class, named Object. For your information ,all java program will be subclass to Object class. If you write a java program, your java program will be subclass to Object class automatically. You may be, not see how it's happen but it is truly happen.

RELAXING NATURE VIDEO