The basic Properties of Interface


1. Interface must be declared with the key word ‘interface’.

2. All interface methods are implicitly public and abstract. In another words you dont need to atually type the public or abstract modifiers in the metod declaration, but method is still allways public and abstract.

3. All variables defined in an interface is public, static, and final. In another words, interfaces can declare only constants , not instance variables.

4. Interface methods must not be static.

5. Because interface methods are abstract, they cannot be marked final, strictfp, or native.

6. An interfaces can extend one or more other interfaces.

7. An interface cannot implement another interface or class.

8. interface types can be used polymorphically.

SCJP


This is the day i am start posting the topics on scjp. Basically i am planning to prepare for the SCJP (Sun Certified Java programmer), So that I am happy to share my preparation, I am happy to discuss each and every important point which i feel, I want to figure out the success tips to help others.

To day i am happy that  strongly decided to complete the exam in three months. Lets see what will happen.

I hope I will get your support to success.

Lets wish me once for the success.

Differences between Object and Instance


There is a lot of discussions on this topic over the internet. Some of the people says both are same and some of other says both are different. Here I am planning to share my overall view on this topic. As per my knowledge both are looks same but different. Here are the some useful points:

  • Instance is Logical but object is Physical means occupies some memory.
  • We can create an instance for abstract class as well as for interface, but we cannot create an object for those.
  • Object is instance of class and instance means representative of class i.e object.
  • Instance refers to Reference of an object.
  • Object is actually pointing to memory address of that instance.
  • You can’t pass instance over the layers but you can pass the object over the layers
  • You can’t store an instance but you can store an object
  • A single object can have more than one instance.
  • Instance will have the both class definition and the object definition where as in object it will have only the object definition.

Syntax of Object:

classname var=new classname();

But for instance creation it returns only a pointer refering to an object, syntax is :

classname varname;

 

Other Useful Links:

Difference between Abstract Class and Interface

What are the differences between EAR, JAR and WAR file?

Differences between callable statements, prepare statements, createstatements

Jar file Vs Executable Jar file


Jar file is the combination of compiled java classes.
Executable jar file is also be combination of compiled java classes with Main class.

Normal jar file can be created as

C:\> jar -cvf TestNew.jar

But while creating executable jar file we have to specify the Main-Class in a manifest file. Following are the steps to fallow while creating the executable jar file. Here its explained with a simple class in a test package.

Step 1: create a java class TestNew under package test

package test;
public class TestNew{
     public static void main(String a[]){
         System.out.println("Hello world");
     }
}

Step 2: compile the class with following command.

C:\>javac TestNew.java -d .

Note: Once you run the TestNew class you have to get “HelloWorld” in the console. To run use fallowing command.

C:\>java test.TestNew

Step 3: Create a “mainClass” file in the directory where your test folder is located . This file contains a single line specifying where the main Class is to be found in the jar file. Note that I use the package specification. Here is the single line:

Main-Class: test.TestNew
Note: specify the single line only don't specify anything

Step 4: Create the jar using fallowing command

C:\>jar cmf mainClass test.jar test

Where “c” represents the create that you are going to “create”, “m” specifies the manifest file mainClass (which adds information to the jar file on where the main class will be found) and “f ” refers to “file”.

Note: The file has to be created in your folder with the name test.jar

To view the content of the jar file you can use the fallowing command

C:\>jar tf test.jar

It displays as:

META-INF/
META-INF/MANIFEST.MF
test/
test/TestNew.class

To execute the jar file you can use the following common.

C:\>java -jar test.jar

o/p:

Hello world