Learn Java - Learn Java Quickly

Ads
 
Tutorials   
What are the prerequisites for learning Java? How to replace all occurrences of a string in JavaScript? How to convert a stack trace to a string? Example code of reading file line by line in Java with Apache Commons IO library How to store unique values in Java using Set? java.nio ShortBuffer Example How to use Java Path class? Java NIO Package Tutorial How to limit object creation in Java? Java 11 String lines function example to split it in lines Top upcoming features of JDK 11 Java/JDK 11 Tutorial How to install JDK 10 in Ubuntu 18.04? Install JDK 10 on Windows Java 10 features Processing large file in Java Learning Java for non programmers Why You Should Learn Java in 2018? Installing JDK 9 on Windows 10 How to convert binary to decimal in Java? How to add two numbers in Java? What is Applet in Java with Example? What is nested class in Java with Example? Exception handling in Java Programming Examples What is Constructor Overloading in Java? How to display image in Swing? What is Java programming used for? How to create custom exception in Java? How to set CLASSPATH in Java? What is Multithreading in Java? IO Streams in Java with Examples How to convert String Date to Timestamp in Java? Best Java Tutorial for Beginners Read user input in Java using Scanner Java Programming Examples Read file line by line in Java 8 What are the benefits of learning Java Programming? A brief history and future of Java programming language Importance of Java for Mobile Application Development How To Become A Good Software Developer?

Learn Java - Learn Java Quickly

Java is an object oriented programming language developed by Sun Microsystems.

Java is an object oriented programming language developed by Sun Microsystems.

Learn Java - Learn Java Quickly

     

Java is an object oriented programming language developed by Sun Microsystems. This is freely available to public for all purposes from personal website development to big enterprises. It looks lot like C and C++ but has various extra-developed features that make it safer, easier and more useful than other object oriented languages. It is now most demanded programming skill used for developing various web-based application in e-commerce and universities.

The most important feature of Java is that it can run on different types of computer without any modification. This feature is popularly known as ?Write once, run anywhere?. Again, it is used widely with Server Side web programming, where the program runs on the web server and the user can see the page using any web browser.  Also programs developed by using Java technology can be sold without paying or consulting to the Sun Microsystems.

Java Virtual Machine (JVM)

It is the principal component of Java architecture that provides the cross platform functionality and security to Java. This is a software process that converts the compiled Java byte code to machine code. Byte code is an intermediary language between Java source and the host system.

Most programming language like C and Pascal translate the source code into machine code for one specific type of machine as the machine language vary from system to system. So most complier produce code for a particular system but Java compiler produce code for a virtual machine. The translation is done in two steps. First the programs written in Java or the source code translated by Java compiler into byte code and after that the JVM converts the byte code into machine code for the computer one wants to run.

So the programs files written in Java are stored in .java files and the .java files are compiled by the Java compiler into byte code that are stored in .class file. The JVM later convert it into machine code. In fact the byte code format is same on all platforms as it runs in the same JVM and it is totally independent from the operating system and CPU architecture. JVM is a part of Java Run Time Environment that is required by every operating system requires a different JRE. JRE consists of a number of classes based on Java API and JVM, and without JRE, it is impossible to run Java. So its portability really made it possible in developing write once and run anywhere software.

In the following figure you can see the function of JVM

How to write your First Java program

Ok, now you know the basics of Java programming and have downloaded the Java Development Kit (JDK), then its time to write your first Java program.

Create a source code program in any of the text editor available like jEdit, Notepad, TextPad etc. Java program is a class with a main method in it. The main method is the starting point for every Java application. So first define the class name and lets take it as FirstProgram and write it in the text editor like below

public class FirstProgram

{

   public static void main(String[] args)

   {

  System.out.println("Hey! you are going to compile and run your first Java program");

   }

}

Here System.out.println is the incantation that one uses to get codes sent to the console. Now save the file with same name as the public class just adding the extension ?.java? . Here for example FirstProgram.java. If you use a different name other than the existing class name then you will face while compiling.

After completing the above, open a doss command window and type cd to the directory in which your source file exists. Type the following code to compile the file. This should be like this:

javac FirstProgram.java

If you compile it successfully, then you can find a class file in your directory with the same name, which is the bytecode form of Java program. Now type FirstProgram.java  to run the program.

The JVM now will run the bytecode in the FirstProgram.class file. Now you will see the output on your screen as:

Hey! you are going to compile and run your first Java program

Congratulation! Now you have successfully developed your first Java program. 

Ads

Ads