Java Programming

What is Java Programming?

Java programming language is an OOP – Object Oriented Programming Language that is used to represent anything in the form of an object.  The concept of Object makes a significant change in the programming industry which let developers to represent real problems in a set of Objects Where the object is represented with a set of object properties and behaviors.

The simplicity of the object oriented makes the programming practice easier to add new things, inherit existing behaviors and properties, increase flexibility, efficiency as well code maintenance.

Java programming language is most popular programming language, and it has been used for desktop, mobile, and data processing and embedded system. For this reason, more than 3 billion devices worldwide are using Java programming language.

There are a lot of features to discuss in Java programming in the coming Chapter starting from a simple concept to a more advanced, and complex real problem solving. Let get start

Precondition

Before we start discussing about Java Programming, It is mandatory to install Java in our machine. This could help us to write code in Java / develop, run and debug our program. The Java kit called Java Development Kit (JDK) and available on the Oracle Oracle website and install b downloading the appropriate OS compatible for your machine [ IOS, Microsoft, Linux, Ubuntu]

Configure Environment Variables

Environment variable is a must to configure the installed JDK. The main purpose of setting environment variable is to let the Java accessible in order to execute compile or use any java commands.

The configuration starts by accessing or creating a file ~/.bash_profile. To open or create the file use the command nano ~/.bash_profile. Then add in the file the  JAVA_HOME and PATHas follow. Finally Press Ctrl + X to exit, then Press Y to save the changes, and Enter to confirm the filename.

STEP-1
nano ~/.bash_profile
STEP-2
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH

Figure 1.1 – Setting Environment Variable

After the configuration of the environment variable, it is possible to check the Java version using the command java –version. This could show the version of Java and confirm as well the correct configuration Java Development Kit – [JDK] in your local machine.

Writing Your First Java Program

We are now ready to write down a simple Java Code. In order to write the first Java program, create a file and write down the following Java program inside the file, and save the file with the file extension .Java. The file name should have the same name of the className. And the class name should include the main method where the execution suppose to begin. Detail of Java Program will be discussed in the next topics. of our discussion.

class  HelloWorld{
    public static void main (String [] ags){
        System.out.println("Hello");
    }
 }

The next step to compile the file where the file is created and stored.

java HelloWorld.java

After successful compilation, execution of the program will be the next action. In order to run the program, apply the following command

java HelloWorld
Scroll to Top