Features of Java

Features of Java

Well, java is rich with many interesting features, and we are going to now study some different features related to java. Let’s list them first –

  • Java is simple (easy to learn)
  • Java is secured
  • Java is a platform-independent programming language
  • Java is Portable
  • architecture-neutral
  • Java is an Object Oriented Programming language
  • Java is robust
  • It supports Multi-threading
  • Java supports exception handling
  • Default garbage collection in java
  • Java is a compiled as well as an interpreted programming language
  • With Java, we can create distributed applications
  • High performance

Features of Java

So, now let’s have a brief discussion about all the above-stated features so that we get a clearer picture of them.

  • Java is simple –

Java is a very simple, easy-to-learn programming language. Anyone who wants to learn java can learn java. No prerequisites are required. But if you are familiar with some programming language already, it surely adds up to your learning process.

  • Java is a secured programming language –

Let’s understand what we mean when we say that java is secured. We have seen how some java source code is converted to machine code. JVM also does code verification by checking whether the code is properly formatted, or even if the code is compiled by a valid java compiler. Also, there is no concept like a pointer, to avoid security problems.

Because it may happen that some human has intentionally written the byte-code to inject viruses into your computers. Now, if there is any kind of problem with the byte-code, then it won’t be executed, with raising a VerifyError. This is just an example of why java is secure. There are many other factors as well, which make java secure, but we are not going to discuss them right here. This was just some brief about security in java.

  • Java is a platform-independent programming language –

When we saw how the java source code is converted into machine code, we had a discussion about byte-code, and there it was mentioned that the byte-code can be executed on any platform regardless of system architecture. This means that if some java source code was written and compiled inside a windows machine, and now if the byte-code is taken to a machine with Mac OS and executed, it is going to execute in a fine way.

The byte-code is the platform-independent thing. It can be executed in any environment with help of JVM. Earlier, we have seen why some other languages like C are not platform-independent, so we will not discuss it here again.

  • Java is Portable –

Well, just as we have stated above, that java is a platform-independent programming language. So, the thing is that we can comfortably take the byte-code from the machine with a windows OS to another machine that contains another OS like Mac for example, without really making any changes to the code. This explains the feature of portability.

  • Java is Architecture-Neutral –

Let’s understand what this feature has to say. First of all, we remember that Java is platform-independent. Now, we need to understand from this thing, that the java byte-code can be executed on any machine with any configuration(provided that the machine has JVM). So, consider that if you have some Intel i5 processor, and now you wish to upgrade to an i9 processor, still on that machine, the java application will execute. By changing the architecture of the machine, you need not change the code. This refers to architecture-neutral.

  • Java is an Object Oriented Programming language –

Well, you might have heard of Object-Oriented Programming at some point in your life. Don’t worry if you haven’t heard of it till now. Since Java is Object-Oriented Programming, we are going to have a look at different concepts related to Object-Oriented Programming. But let’s have a brief statement here, so we can proceed further.

Well, here, we mean that java follows the object-oriented programming paradigm, which is a completely separate topic, that we are going to learn ahead. But, just to put a statement here, you can consider that there are some classes and objects, and some principles related to them. To put an example, it is like there is a class of humans, and all the humans are objects of the class human. They have certain attributes like gender, hobbies, birth date, etc, and certain behaviors like walking, talking, sleeping, etc. When we will learn about Object-Oriented Programming, we will be able to visualize it in a more clear way.

  • Java is Robust –

When we say robust, we mean that java is strong. There are some parameters that make java strong –

Excessive checking for errors at compile-time and runtime –

Well, while some other programming languages are either compiled or interpreted, Java is both compiled as well as interpreted. Firstly, the java source code is compiled to a byte code. Now, at the compile-time only, the program is extensively checked for any Compile-time errors, and the byte-code is not generated if the program doesn’t compile. The runtime errors are also watched, which raises the second point, exception handling.

Java Supports Exception Handling –

The exceptions might be the ones that are spotted during the execution of the program(or in some cases, during the compilation as well, they are checked exceptions. Anyways, we are going to deal with them quite later).

The program has compiled successfully, which means that there is no syntactical mistake. But now, if some issue is detected during the execution of the program, a runtime error/exception might occur. The runtime exceptions are often handled by something called exception handling. The errors cannot be handled, and we cannot do anything about them.

Let’s understand this thing with help of an example. Let’s say that you are writing a simple program for performing division between two numbers. The program has compiled fine and runs fine. But the moment you put the denominator as zero, the runtime exception occurs, saying that you tried dividing some number by zero, which is undefined. We can handle this exception using the concept of exception handling at the runtime. We just need to make some changes to a normal program, but as of now, we don’t have to bother about what is exception handling. We will deal with it later on.

Automatic garbage collection in java –

What do we mean by the garbage in our real life? It is something that is a waste, or not of use. The same thing is here. Just imagine that you have a chair that uses some space, but is broken. What you can do instead is re-selling it to a scrap dealer, so that you get that space freed. The example was a bit weird, but something similar is happening here too. If there are some unreferenced objects, the garbage collector will automatically destroy them so as to free the memory that they have occupied at the runtime.

So, all the above parameters explain why is java so strong.

  • Java supports Multithreading –

Well, as the name says, Multi-threading, by which, we mean that at a time, multiple threads would be running to do some task. This is a completely separate topic, So we are going to discuss this ahead, If you wish to explore this concept, you can freely do it. Let’s now move ahead to explore more features.

  • Java supports Exception Handling –

As already mentioned before, with exception handling, we can handle the exceptions. You can again refer to the above example of the division of a number by zero. There are many exceptions that can occur at runtime, like –

ArrayIndexOutOfBoundsException
ClassNotFoundException
ArithmeticException
and more…
We are going to discuss the concept in greater detail ahead, so don’t worry.

  • Default garbage collection in java –

As we have already gone through this feature just before, we have defined it in a pretty simple way – it is the process of destroying unused objects, so as to free memory at runtime. This is also a quite interesting feature.

  • Java is a compiled as well as an interpreted programming language –

There are many programming languages, out of which, some are compiled, and others are interpreted. But when it comes to java, it is Compiled, as well as interpreted. The java source code is first compiled into byte-code, and then the byte-code is interpreted into machine code.

  • With Java, we can create distributed applications –

Java allows us to write distributed applications. Now if you are not familiar with what is distributed applications, think of them as one whole application, instead of running on a dedicated system, run on different systems cooperating doing different tasks. This is like one task is divided into different computers connected to a network, to achieve a common goal. We can use RMI (remote method invocation) or EJB (Jakarta Enterprise beans) in order to develop distributed applications in java.

This is a completely different topic, so let’s keep it aside because we are currently at a basic step.

  • Java has High performance –

Well, when we say that java is a high-performance, we mean that it is fast. The reason behind this is JIT(Just in time) compiler.

Let’s discuss the idea in brief. Just imagine that there is some method in your byte-code, which will be traditionally interpreted line by line. Now, if you call this method once, it will do the same thing (interpreting the whole code of the method line by line). You call it repeatedly inside your program.

Now, if your JVM has a JIT compiler, it will consider the method that you are calling frequently as a hot method, as soon as it passes a particular threshold value. Once it is tagged as a hot method (hotspot), the entire method will be Just In Time compiled to the machine code, instead of interpreting every time the method is called. This is done by the JIT compiler. The basic idea is to handle the hot block of code in a different way.

So, above were some of the features in java. I hope that you have understood the features, or at least got a broad idea of these features. You can further explore, and the thing is that as we move ahead, the picture will become more clear, as right now, there may be some concepts that we haven’t covered yet, so you might not have got a complete picture of all the features. But with time, you will be able to relate things.