Java has many important features that makes java one of the most useful programming language today. As the time passes, java has emerged as one of the most preferable programming language for different types of need. This tutorial will cover some of it's features which makes it one of the most useful language.
1. Java is Platform Independent
Java is a platform independent language. In java you can write and compile your program on one machine(eg. windows) and then you can run the compiled
.class file) on any other machine(eg. linux or macos).
That is what the platform independent means in java, program written and compiled on one machine can be
run on any other machine.
In order to run your program on new machine, all you need is, a JVM(Included in JRE software) installed
on new machine as per it's operating system and the generated
.class file from previous machine.
This is why we also say java is a "Write Once - Run Anywhere"(WORA
also known as Platform Independent) language.
MyFirstProgram.class generated on any machine(OS) can be run on any other machine having same or different OS. This is why we call
java is a platform independent language.
What makes java platform independent
It's java bytecode along with JVM(specific to OS) makes java platform independent language.
2. Java is Object Oriented
Java is an object oriented programming language because java supports the principles of Object Oriented Programming(OOPs) like Encapsulation, Inheritance, Abstraction Polymorphism etc. Everything in java plays around objects, we create variables, methods etc for objects in a program. Programming languages like C, FORTRAN, PASCAL etc focuses on logics while java focuses on objects. An object contains data in the form of fields(instance variable) and code/logic in the form of methods.
Why java is not pure object oriented language ?
Java is not pure object oriented language because it supports primitive data types(
byte, int, float etc)
which are not objects.
3. Java is Simple
Java is a simple language because it's syntaxes are very similar to C++ syntaxes, it also provides automatic memory management through garbage collection, programmers don't have to focus on complex memory management. Apart from this java contains a lot of predefined class libraries to support different needs in a program. Java doesn't support some of the complex features like operator overloading, multiple inheritance etc. Also there is no concept of pointers in java that confuses programmers a lot. All these things makes java a simple language.
4. Java is Secure
Java is secure because it has features like automatic memory
management, no explicit pointer, bytecode verifier etc that
enhances the security of java programs. As java does not have
concept of pointer and provides the automatic memory management,
it reduces the chances of memory leak. Bytecode verifier
.class files are not edited explicitly, any external
edit fails the program to run. Also java
program runs in a separate java virtual machine which
enhances it's security. These features together makes java one of the most secured language.
5. Java is Portable
Java is portable because the bytecode(
.class file) of a program can be run on different
machines without any change in it. If the machine changes or the configuration(hardware,
operating system or both) of existing machine changes, same bytecode
can be executed on new machine/configuration as well. Java's
Write once - Run anywhere feature makes java a portable
language. Java was designed with a goal that if new architectures
are developed, the java environment could be ported easily. While
porting all you need to have is the
.class files of application on
existing machine. Just copy these
.class file on new machine and run your application by installing(if not already installed)
the java virtual machine on new machine.
Why java is called portable language ?
Because the bytecode of a program can be ported/transfered to other machine/configuration and it can be run there as well.
6. Java is Distributed
Java is also called a distributed language. This means java programs running on one machine can easily access the resources(files, java objects etc) of other machine on internet/network. Java provides class libraries for high-level support of networking. The java's remote method invocation(RMI) API's allow java programs to call methods of remote java objects, as if they were local objects. We can also say, same or different applications running on different JVM on different machines can interact with each other for sharing data over the internet. RMI and EJB are mostly used for distributed programming.
Here the applications running on different machines which are connected via internet/network can interact/access the resources with each other using java's pre-built libraries like RMI, EJB etc.
What is distributed application
An application or it's independent parts that runs on multiple systems is known as distributed application.
7. Java is Multithreaded
Java is a multithreaded programming language. In multithreaded programming two or more than two parts of a program can execute simultaneously inside a machine. That means a single program can do two or more than two tasks simultaneously. Each part of such program is called a thread and each thread starts a separate path of execution. Multithreading is a special form of multitasking. For example in a multithreaded program you can read a file in one thread and can write into a different file in other thread simultaneously.
What is multi threaded application
An application capable of processing more than one tasks simultaneously/parallelly is known as multithreaded application.
8. High Performance
Though java is not as fast as compiled languages like C, C++ but java still has some of the good features like just-in-time compiler, multithreading, garbage collection etc that increases the performance of java near to compiled languages.
9. Java is Robust
A language is called robust if it is reliable. The reliability comes because java strongly checks for error in program at compile and runtime both, to eliminate error-prone situations. The reliability also comes because java also has the strong memory allocation and automatic garbage collection mechanism which reduces the probability of crashing a program at runtime.
What is robust application
A robust application is an application that doesn't break easily with incorrect data/input. Such applications strongly checks for error to avoid application crash at runtime.
A language is dynamic if it is adaptable to changing environments or the code is executed/loaded as and when required at runtime. Classes in java are linked/loaded only when needed. The code can be downloaded dynamically from anywhere on the network. The runtime features like memory management, dynamic binding etc makes java a dynamic language.
Java is a highly interpreted language. At runtime java bytecode is interpreted(converted) into machine code using java interpreter(part of JVM) in order to run the program. Java has the feature of just-in-time compilation(happens at runtime) which reduces the interpretation time.
Is java interpreted or compiled
Java is both compiled and interpreted language since java programs are compiled first using java compiler then at runtime the compiled code(bytecode) is interpreted by java interpreter in order to execute the program.
12. Architecture Neutral
Java is an architecture neutral language because it does not depend on architecture(organization of processor, memory, cpu input/output etc,) of a computer. Hence java can be run on any computer architecture. As bytecode are platform independent, it also makes java as an architecture neutral language, something which is not dependent strongly on specific system configuration.
- If java was not platform independent, programmer would have to write same program differently for different operating system.
- Java is not as fast as C or C++, because these languages converts source code directly to machine code while java doesn't do the same.