It is said "Write Once, Run Anywhere". This is Java! Unlike any other programming language, Java is to be written once and can be compiled in any corner of the world. It is platform independent.
How Java works?
The aim is to write one program and make it work on whatever device your peers have!
How Java works?
The aim is to write one program and make it work on whatever device your peers have!
- Create a source document using java
- Run your document through a source code compiler. The compiler checks for errors and won't let you compile until its satisfied that everything will run well.
- The copiler creates a new document, coded into java bytecode. Any device capable of running will be able to interpret/translate this file into something runnable. Rephrasing, the compiled bytecode is platform independent.
- Now, you can wish your friend "Happy Holi". Your friends don't have a physical java machine but the all have a virtual java machine running inside their electronic devices. The virtual machine reads and runs the byte code.
So, what will you do in Java?
You'll type a source code file, compile it using the javac compiler, and then run the compiled bytecode on a Java Virtual Machine.
Following example will help you understand the above statement, a little bit!
(Do not worry about when,how, why the program is written! It will be explained later on.)
Type your source code and save as example1.java at your desired location.
Compile the example1.java file by running javac(the compiler application). If you don't have errors, you'll get a second document named example1.class (compiler generated bytecode).
Tip : save the name of file as the name of class, because java compiler searches for the class name in the file through the file name.
Run the program by starting the JVM(java virtual machine) with the eample1.class file. The JVM translates the bytecode into a something the platform understands, and runs the program.
Comments
Post a Comment