Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Sunday, 18 May 2014

What happen while execute the java program ?


Virtual machine start-up

      A Java virtual machine starts execution by invoking the method main of some specified class, passing it a single argument, which is an array of strings. 
     
d:\app1\src\>java Test

   The steps the virtual machine may take to execute Test class are loading, linking, and initialization processes that are described further in this section.


Load the Class

    To execute the main method  of  Test class discovers that the class Test is loaded or not means that the virtual machine currently contain a binary representation for this class or not .If class not loaded then ,the virtual machine uses a class loader to attempt to find such a binary representation. If this process fails, then an error is thrown.
 
Link : Verify, Prepare

   Verification checks that the code that implements Test obeys the semantic requirements of the Java programming language and the Java virtual machine. If a problem is detected during verification, then an error is thrown.
  Preparation involves allocation of static storage and any data structures that are used internally by the virtual machine, such as methods.

Initializ : Execute Initializers

  Initialization consists of execution of any class variable initializers and static initializers of the class Test.But before Test can be initialized, its direct superclass must be initialized, as well as the direct superclass of its direct superclass, and so on.

Invoke : main method

   Finally, after completion of the initialization for class Test (during which other consequential loading, linking, and initializing may have occurred), the main method of Test is invoked. The method main must be declared public, static, and void. It must accept a single argument that is an array of strings. This method can be declared as


public static void main(String[] args)


Friday, 16 May 2014

What Happen While Compile Java Code

What Happen While Compile Java Source Code ?

In the previous post, we have learned about how to develop ,compile and run a java program,how to compile and how to run the first java program.

Here, we are going to learn, what happens while compiling hello world  program.
While compiling java source code is converted into Byte Code by java compiler.


Now this byte code is platform independent which can be run on any platform.
Byte code provide java's most important feature platform independent which means compile code once and run any where(write once run any where).

Thursday, 15 May 2014

Hello world program


How to develop A Hello world Progaram ?

Let's see the development of Hello world program.

Develop the program as show below.

class Test
{
     public static void main(String[] args) 
     {
        System.out.println("Hello World!");
     }
}

Here in bule color all are keywords , red are inbuilt classes and pink is the string literal.
More about keywords,identifiers and basic syntax click here.
Save this code with file name as Test.java .

Here Test is class name and .java is the file extension for java files.

e.g D:\app1\src\Test.java

Start the command prompt and follow the procedure

C:\Users\xyz>D:

D:\>cd app1\src

D:\app1\src\>javac Test.java

D:\app1\src>java Test

Hello world!

Download this File

Internal process of compilation stage click here

Tuesday, 13 May 2014

How to install JDK and configure environment variable

  1.  Download JDK from the Oracle site
  2.  Double click on the downloaded exe file and install it to your system.
  3.  Envirnment variable setting .
  4. Right click on my computer and select properties.

   5. Click on Advanced system setting.


   6. Click on Environment Variables.


   7. Add new user variable with name is path and value is where your jdk's bin directory .


   8. After setting environment variable start command prompt and run javac command if you see
       following output then you have successfully set the environment variable




History Of Java

History OF Java

1. Java is a computer programming language that is concurrent, class-based, object-oriented, and    specifically designed to have as few implementation dependencies as possible. It is intended to let
James Gosling creator of java
 application developers "
write once, run anywhere" (WORA), meaning that code that runs on one  platform does not need to be recompiled to run on another.

2. James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June  1991.
3. The language was initially called Oak after an oak tree that stood outside Gosling's office
4. After that is was renamed to Green.
5. And finally it was renamed to java from java Coffee.

Principles Of Java

  1. It should be "simple, object-oriented and familiar".
  2. It should be "robust and secure".
  3. It should be "architecture-neutral and portable".
  4. It should execute with "high performance".
  5. It should be "interpreted, threaded, and dynamic".

Version Of Java

  • JDK 1.0 (January 21, 1996)
  • JDK 1.1 (February 19, 1997)
  • J2SE 1.2 (December 8, 1998)
  • J2SE 1.3 (May 8, 2000)
  • J2SE 1.4 (February 6, 2002)
  • J2SE 5.0 (September 30, 2004)
  • Java SE 6 (December 11, 2006)
  • Java SE 7 (July 28, 2011)
  • Java SE 8 (March 18, 2014)