Showing posts with label CONCEPTS. Show all posts
Showing posts with label CONCEPTS. Show all posts

Friday, 29 July 2011

How to run Java program


A First Simple Program
/*
This is a simple program Call this file “Example.java”.
*/
Class Example
{
//Your program begins with a call to main ().
Public static void main (String args[])
{
System.out.println (“This is a simple Java program “);
}
}


Entering the program
-The name of a source file is very important
-In Java, all code must reside inside a class. By convention ,the name of that class should match the name of the file that holds the program
-A source file use the .java filename extension

Compilling the Program
C:>\javac Example .java
-The javac compiler creates a file called Example .class, that contain the Bytecode version of the program
-To actually run program, you must use the Java interpreter, called java
C:>\java Example
-When java source code is compiled, each individual class is put into its own output file named after the class and using the .class extension
A closer look at the first program
-All Java application begin execution by calling main()
-A complex program will have dozens of classes, only one of which will need to have a main() method to get things started
-Java applets don’t have any main() method
-Java interpreter run only main() method
-Java interpreter run only the class that have a main method
-println() is a built in method
-System is a predefined class that provides access to the system,and out is the output stream that is connected to the console.

Tuesday, 26 July 2011

Java’s Magic: The Bytecode


The secrets behind the security and portability of Java is that the output of a Java computer is not executable code.Rather, it is Bytecode  
Bytecode is a highly optimized set of instructions designed to be executed by the Java run-time system, which is called the Java Virtual Machine (JVM)
JVM is an interpreter of Bytecode        
Java systems contain:
-Environment
-Language
-APIs
-Class libraries
Java programs normally undergo five phases
(1)    Edit
-Programmer writes program )and stores program on disk)
(2)    Complete
-Compiler creates bytecodes from program
(3) Load
-Class loader stores bytecodes in memory
(4)Verify
-Verifier ensures bytecodes do not violate security requirements
(5)Execute
-Interpreter translates bytecodes into machine language
Benefits of Bytecode
-Translating a Java program into Bytecode helps makes it much easier to run a program in a wide variety of environments
-Only JVM needs to be implemented for each platform
-Once the run time package exists for a given system, any java program can run on it

      

Twitter Delicious Facebook Digg Stumbleupon Favorites More