Features of Java

The essential goal of Java programming language creation was to make it versatile, straightforward and secure programming language. Aside from this, there are additionally some great highlights which assume a significant function in the notoriety of this language. The features of Java are otherwise called java trendy expressions.

Following are the essential features of Java language.

  1. Simple
  2. Object-Oriented
  3. Platform independent
  4. Secured
  5. Robust
  6. Robust
  7. Architecture neutral
  8. Interpreted
  9. Interpreted
  10. High Performance
  11. Multithreaded
  12. Distributed
  13. Dynamic
Simple

Java is easy to learn, and its syntax is necessary, straightforward and easy to understand. As indicated by Sun, Java language is a simple programming language in light of the fact that:

  • Syntax of java programming language is based on C++ programming language so after C++, java is the more straightforward programming language for the programmer to learn
  • Java is a simple programming language because it has removed so many complicated and rarely used features like operator overloading, explicit pointers, and many more.
  • There is an Automatic Garbage Collection in java so no need to remove unreferenced objects.
Objected oriented

You can model everything into an object which has data and behaviour. Java has incorporated various object-oriented concepts such as Abstraction, Encapsulation, Polymorphism, and inheritance.

Platform independent

Java is write-once, run-anywhere language. Once you compile java code, you can run it on any machine. For example: If you compile your code on Windows OS, you can efficiently run the same bytecode in Linux.

Portable

Java byte can be portable to any platform and can be executed on any platform.

Multithreaded

Java has provided multithreading feature which will help you to execute a various task in parallel. It has introduced the executor framework, which is more robust and easy to use.

High Performance

Java cannot be as fast as C and C++ as it is interpreted language, but it has provided various features such as Just in time compiler to increase performance.

Robust

Meaning of Robust is Strong. Java is a robust programming language because:

  • Java uses Strong memory management.
  • There is an absence of pointers that evades security issues.
  • There are programmed trash assortment in java which runs on the Java Virtual Machine to dispose of articles which are not being utilized by a Java application any longer.
  • In java there is exception handling and type checking tool.
Java Hello World Program

Hello, world program will be an elementary program that will print Hello, World! To console.

Before running the program, you need to make sure java is installed correctly on your machine.

Prerequisite for running a java program

Install the JDK if you don’t have installed it, download the JDK and install it.

/ First java hello world program

public class HelloWorld {

public static void main(String[] args) {

System.out.println(“Hello, World!”);

}

}

You need to save this file as HelloWorld.java.

How this java program works

Let’s see a detailed explanation of the Hello world program.

Class declaration

// First java hello world program

This is a comment in java, and this statement will be ignored at run time.

public class HelloWorld {

As java is object-oriented programming, every java application should have a class definition.

  • Class declaration:

    A class declaration includes the name and visibility of the class. class HelloWorld is the declaration of class which provides for keyword class, followed by identifier HelloWorld

  • Class declaration is followed by curly braces {}, which defines class’s definition.
Main Method

public static void main(String[] args) {

This is called the main method in java. This is the entry point for this program.

public: This is access modifier which is used to define visibility. Here the main method will be visible to all other classes.

static: static members belong to the class rather than any specific object. It simply means you can access the static members without object.

void: void is another keyword which defines the return type of the main method. It simply means main method does not return anything before terminating the program.

main: main is method name here.

String args[]: You can pass arguments to java program using args[] array. It is used to take user input using the command line.

Print statement

System.out.println(“Hello, World!”)

System.out.println

System.out.println is used to print literals in double quotes(“”) to console. As we have passed “Hello, World!” here, it will print Hello, World! to console.

Semicolon

As you can see, each statement is terminated with a semicolon(;). You can put new lines or spaces in the code, but statement has to be ended by a semicolon.

Compile and run the program

If you run this program in eclipse ide, you can right-click and on the run as java application.

You can compile this java program using the command line as below:

Open the command prompt and go to the location where you have saved HelloWorld.java

If you run this program in eclipse ide, you can simply right click and on the run as java application.

You can compile this java program using the command line as below:

Open the command prompt and go to the location where you have saved HelloWorld.java

javac HelloWorld.java

You can run the program using the command line as below:

java HelloWorld

When you run the above program, you will get below output:

Hello, World!

When we execute java program, we need to give full class name without .java extension.

Copyright 1999- Ducat Creative, All rights reserved.