Here you will learn the basics of Running a Java Program. Before that, let’s know a few things about Java:-
Running a Java Program can be accomplished using even cmd.Java is a completely Object Oriented Language. It is highly regarded because unlike other languages it is Platform Independent. Also, Java does not support Multiple Inheritance. First of all, we must understand the differences between JDK, JRE, and JVM before proceeding further to Java:-
JVM (Java Virtual Machine)
JVM is called a virtual machine because it doesn’t physically exist. It is a specification that provides a runtime environment in which Java bytecode can be executed. It can also run those programs which are written in other languages and compiled to Java bytecode.
JRE (Java Runtime Environment)
The Java Runtime Environment is a set of software tools which are used for developing Java applications. Most noteworthy, It is used to provide the runtime environment. It is the implementation of JVM. It physically exists. Finally, it contains a set of libraries + other files that JVM uses at runtime.
JDK (Java Development Kit)
JDK is an acronym for Java Development Kit. The Java Development Kit (JDK) is a software development environment which we use to develop Java applications and applets. It physically exists. It contains JRE + development tools.
The reason for telling all this is because JDK is Essential to run a Java Program. It Provides the Environment for your system to enable to Develop Java applications. Now let’s begin with the basics of Running a java program.
Running a Java Program(Part-1)
1:- Open Your Browser and search www.java.sun.com otherwise click here
2:- Click on Java SE under Top Downloads
3:- Click On Download Under Oracle JDK
4:- Accept the License Agreement, and therefore download the file with respect to your System
5:- Once the File downloads, install the software. We still can’t use Java Compiler. Before that, we’ll have to derive a path for it. After it gets Installed open go to Local Disk C, Where your files have been created for the JDK. Go inside program files you will find a folder named Java. Open it. Now open the folder that starts with JDK. Open Bin.
6:- Right click on the first applications extensions you see. After that click on Properties. Now copy the address of this file.
7:- Open Properties of My Computer.
8:- Open Advanced System Settings.
9:- Click On Environment Variables.
10:- Under User Variables, Click on New. In the Space Infront of Variable name type “Path. And in front of Variable value paste the address that you have copied. Press Enter.
11:- Open your Command Prompt and Type “java”, and then press Enter. You will see a bunch of different kinds of stuff, which shows that you have successfully installed the JDK.
Running a Java Program(Part-2)
1:- Type the Java Program on any notepad.
2:- Furthermore, store It in Local Disk C. (In My case I have stored this inside a folder name Java. The name Java is not mandatory).
3:- Open Command Prompt and type “cd\”.(Click here to watch Stars Wars using cmd)
4:- Now type “cd” and the name of your folder you have saved it in, my case it is “java”. If you have not created it inside any folder then move to step 5.
5:- Type java and then the name of your java program file. (Name of my file is apples)
6:- Press Enter and as a result, if your program does not have any errors, it will run successfully.