Java Technology Platforms

Java Technology

WORA ( Write Once Run Anywhere)

WORA Concept

  • Source : create a source document. Use an established protocol.
  • Compiler : Run your document through a source code compiler.The Compiler checks for errors and won't let you compile until it's satisfied that everything will run correctly.
  • output: The compiler creates a new document coded into Java bytecode. Any device capable of running Java will be able to interpret/translate this file into something. It can run. The compiled bytecode is platform-independent.
  • Virtual Machines: Your friends don't have a physical Java Machine but they all have a virtual Java Machine (implemented in software) running inside their electronic gadgets. The Virtual machine reads and runs the bytecode.

Writing First Java Program

Step -1 Write Source Code
  • Example
class Test{
	public static void main(String args[]){
		System.out.println("Hello Java !");
	}
}
Step- 2 Save Code with class Name
  • Test.java
Step-3 Compile the code
  • javac Test.java
  • Note:when you compile the code it will generate an intermediate code (Byte code) it is not a machine code.
Step-4 run the Program
  • java Test
  • Note:Running the program by starting the JVM with the A.class. The JVM translates the bytecode into something the underlying platform understands , and runs your program.
OUTPUT
  • Hello Java !

Program Observation

We can observe our program that how it executes and what steps are done by the JVM to run Java program.


  • When the JVM starts running , it looks for the class that is at the command line. Then it starts looking for a specially written method that looks exactly like:
public static void main(String args[])
{
	/*	Your Code Here */
}
Note: Every Java application have at least one class, and at least one main method.
You can define main method in the following ways
public static void main(String args[]){}
static public void main(String args[]){} 
/*  Allowed in JDK 1.5 or higher */
public static void main(String ...a){} 
/* Allowed in jdk1.5 or higher */  
static public void main(String ...a){}  
  • The main method is public , because java is package centric language.
  • Now JVM has to access your main method from outside package. That's why it set to as public.
  • The main method also static , because static is loaded on the compile Time and not required to instantiate.
  • The main method is void , because it is not required to return any thing to the JVM.
  • Main is the name of the method and String args[] is used for command line arguments , where String is a Java class.

Clarification of an Exception - javac is not recognised as internal or external Command.

Java Exception Example

  • This exception occured for fresher level while they forget to set the path of JDK.
  • You can rectify this exception after Setting the path of JDK.
System.out.println() Observation
  • Where System is a final class, found in java.lang package. Out is a object of PrintStream class and it declare static in the System Class.
  • println(String msg) this is a method define in the PrintStream class. Used to print on console and print in new line
Java Coding Convention
  • Class and Interfaces : The First letter should be capital, and first letter of the inner words should be Capital.
  • Example :

    • Account
    • PrintWriter
    • Emp

  • Methods: The First Letter should be lowercase, and then normal camelCase rules should be used.
  • Example :

    • getBalance
    • setCustomerName

  • Variables : Same rule as Method Rule ,Variables follows camelCase rules.
  • Example :

    • String empName;
    • String DeptName;

  • Constants : Same rule as Method Rule Constants All in Uppercase.
  • Example :

    • MIN_HEIGHT