Introduction

Java is one of the most popular and important programming language in the world. Due to its distinct features, it is the most widely used language in every corner of the world and human life. From software and web applications to robotics, Java has become the most wanted language in today’s times.

What make Java distinguishable ?

There are many features of Java which makes it so different from other programming languages. As a result, it has become a must in software and hardware industries.

Let's have a look at some of those features.

Simple - It is designed to be easy to learn.

Object-oriented - In Java, everything is based around Object which has some data and behaviour. Java can be easily extended as it is based on Object Model.

Platform independent - This means that the same program works on any platform (operating system) without needing any modification.

Robust - Robust means strong. Java is a robust management as it has a feature of automatic garbage collection and memory management.

Portable - Programs written in Java are portable i.e., programs written for one type of computer or operating system can be run on another type of computer or operating system.

High-performance - Java enables high performance with the use of just-in-time compilers.

Applications of Java

Java is not only used in software but is also widely used in designing hardware controlling software components. According to Sun, 3 billion devices run Java.

JDK, JRE and JVM

Before moving forward, let's first understand the three terminologies - JDK, JRE and JVM.

After writing any program in Java, we need to compile and run it to see the output of the program.

When we write any program in Java language, it needs to be converted to machine language so that the computer can understand and execute it. This conversion is known as compiling and we compile a code with the help of the compiler.

Let's look at another term - platform. A platform is the hardware or software environment in which a program runs.

Unlike other programming languages such as C, C++, etc which are platform dependent, Java is a platform independent language. Platform dependent languages mean that the program written for one operating system can only run on that operating system. This means that a code written in Linux can only be run on a computer having Linux. A Java program on the other hand, can be run on any operating system.

It is a virtual machine that runs the Java bytecodes. The JVM doesn't understand Java source code (the language in which we write Java programs), so first, the source code is compiled into bytecode which can be understood by the JVM. The JVM provides a platform-independent way of executing code, thus making Java platform independent.

Java Runtime Environment (JRE)

Java Runtime Environment contains JVM, class libraries, and other supporting files. Actually, JVM runs the program and it uses the class libraries and other supporting files provided in JRE. If you want to run any Java program, you need to have JRE installed in the system

How to Start ?

Once our Java program has been written, it needs to be compiled and run. As Java is platform independent, a Java program written in any operating system can be run on all the operating systems. Now let's learn how to run a Java program on different operating systems.

Windows

Here, we will talk about running a Java code using NetBeans and Command Prompt.

You may need to install the Java Development Kit from their website. You can download it from here.

3. To check if Java is installed, type java -version and press Enter. If Java is installed, you will see a message stating what version of Java is currently installed.

If not, you may need to install the Java Development Kit from their website. You can download it from here.

4. Let's assume that you have installed Java in C:\Program files\Java directory.

Right click on My Computer and select properties.

5. Go to the Advance System Settings tab.

6. Click on the Environment Variables button.

Now alter the path variable so that it also contains the path to the JDK installed directory. Change the variable value to your folder containing Java ( C:\program files\Java\jdk1.8.0_25\bin in our case ).

7. Use the command cd followed by the directory name to change your working directory. For example, if you are operating in C:\Users\John\Project and want to get to C:\Users\John\Project\prog ,then you need to type cd prog and press Enter. ( This directory should contain your previously created Java file ( hello.java in our case )).

8. Once you are in the correct directory in which you have your program, then you can compile and run your program.

To compile, type javac filename.java ( javac hello.java in our case ) and press Enter. Here, our filename is hello.java, so we will write 'javac hello.java'. If it is showing any error, then try to remove that error from your program and then again save and compile your program.

9. Once the program is compiled, run the program by typing java classname ( java Hello in our case ) and then pressing Enter. Name of the class is Hello written after class in java file.

We will get the output as follows. Now, you are ready to go for the next chapter.

Linux

For Linux, you can write your Java program in various text editors like vim (or vi), gedit or Emacs. For running your Java program in Linux, follow the steps below.

1. Open Terminal ( ctrl+alt+T ).

If you don't have Java installed in your computer, then first install it. This is a nice tutorial to install java in Ubuntu.

2. Open a new file with .java extension in your favourite text editor ( we are using gedit ). The command is :