Java
This is an introduction to Java programming language.
In 1991 Sun Microsystems developed the Java programming language. James Gosling is one of the inventors. Originally the programming language was named Oak by the team. Then in 1995 it was renamed to Java.
Java is an Object Oriented Programming language.
Generally computer programs are either compiled or interpreted. In case of Java we get to see both.
First a programmer writes the code in Java. Then that code is compiled by the Java compiler into what is called the Bytecode which is machine independent. Then Java interpreter converts the bytecode into machine instruction depending on the machine the interpreter is working on.
Before we start writing Java code we have to first install JDK on our machine. So, visit Oracle website and download the latest version of the JDK Java Development Kit for your operating system and then install it.
Google Java JDK latest version and you will get the link. Or, try using this link.
After installing Java you can check the version by typing java -version
command in the terminal or command prompt.
At the time of writing this tutorial I am using version 1.8
YUSUF-MBP:~ yusufshakeel$ java -version
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
To write Java code you can use any IDE or Text Editor of your choice that supports Java.
If you want to use light weight Text Editors to write Java code then check out the following.
But I will recommend you to use IDE for writing Java code if you are planning to work on a project. Some of the IDEs are listed below.
You can also check out BlueJ for writing Java code.
We save Java source code in a file with the .java
extension.
Example: helloworld.java
We will start our journey by writing the famous "Hello World" program in Java.
Open your favourite text editor or IDE for Java and create a new file by the name HelloWorld.java
and write the following code.
class HelloWorld {
public static void main(String args[]) {
System.out.println("Hello World");
}
}
Now open the terminal and compile the file by running the following command.
$ javac HelloWorld.java
This will create a .class
file. Now to run the program write the following command.
$ java HelloWorld
ADVERTISEMENT