Java Tutorial-Getting Started

JAVA Installation

Some PCs might have JAVA already installed. To check it, type in the search bar for “Java” or type the following in the command prompt.

C:\Users\SparkDatabox>java -version         

If JAVA is already installed, the above command will give you the version of JAVA.

If Java is not installed in the machine, it can be installed from the below link:

https://www.oracle.com/technetwork/java/javase/overview/index.html


JAVA – Quickstart

In JAVA, every program file starts with class name, and that class name should be same as the file name. A text editor (notepad) is sufficient to create a JAVA file. For example, the JAVA file “MyClass.java”, prints the “Hello World” as shown below:

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

To run the above code, firstly, save the above code with the file name “MyClass.java”. To compile the above code, the following command should be given:

C:\Users\SparkDatabox\Documents\spark-databox>javac MyClass.java             

This will compile the code. If there are no errors in the code, the command prompt take you to the next line. To run the class, the below command is given,

C:\Users\SparkDatabox\Documents\spark-databox>java MyClass            

The output for the above command is

Hence, this is how we compile and run the JAVA program.

Using Eclipse IDE will help to easily write and run the JAVA program.

Download the Eclipse IDE with the link - https://www.eclipse.org/downloads/