Java is an object-oriented programming language with a high level of abstraction and as few implementation dependencies as feasible. It is a general-purpose programming language that allows application developers to write once and run anywhere, which means that generated Java code may run on any platform that supports Java without the need to recompile. Java programmes are usually compiled to bytecode, which may execute on any Java virtual machine (JVM), independent of the computer architecture. Java has a syntax that is comparable to C and C++, although it has less low-level features than any of these languages.
Traditional compiled languages lack dynamic capabilities like as reflection and runtime code change, which are accessible in the Java runtime. According to GitHub, as of 2019, Java was one of the most popular programming languages in use, especially for client-server web applications, having 9 million developers.
Simple Java Program
public class FirstJavaProgram { public static void main(String[] args){ System.out.println("This is my first program in java"); }//End of main }//End of FirstJavaProgram Class
How can I compile and run the programme above?
Prerequisite: Java must be installed on your computer. Here’s where you can obtain the Java.
Step 1: Open a text editor on your computer, such as Notepad for Windows or TextEdit for Mac. Copy and paste the above programme into a text editor.
Step 2: Name the file FirstJavaProgram.java and save it. You might be asking why we called the file FirstJavaProgram; the reason is that the file should always be named the same as the public class name.
Step 3: In this step, we will compile the programme. To do this, open command prompt (cmd) on Windows, or Terminal on Mac OS.
Type the following command and click enter to compile the programme.
javac FirstJavaProgram.java
Set Path in Windows:
Open the command prompt (cmd), navigate to the location where you installed Java on your machine, and find the bin directory. Copy the whole path and paste it into the command like this.
set path=C:Program FilesJavajdk1.8.0_121bin
When attempting to compile the programme, you may receive the following error: “javac’ is not recognised as an internal or external command, operable programme, or batch file“. When your system’s java path isn’t configured, you’ll get this error.
Set Path in Mac OS X
To use Terminal, open it and type the following command followed by the return key.
export JAVA_HOME=/Library/Java/Home
To confirm the path, run the following command on the terminal.
echo $JAVA_HOME
The instructions above are for temporarily setting up the route, which means the path settings will be lost when you exit the command prompt or terminal, and you will have to establish the path again the next time you use it. In the next tutorial, I’ll show you how to set up a permanent route.
Step 4: The.java file is converted into a.class file after compilation (byte code). We may now start the programme. To start the application, type and click enter the following command:
java FirstJavaProgram