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
*****************************************************************