Java 11 Developer Certification - Understanding the Java Language

September 26, 2020

What we are covering in this lesson

Basic features of Java programming language

Below are the key features of java

  1. Architecture neutral
  2. Object Oriented
  3. Statically Typed
  4. Dynamic Programming Language
  5. Supports Multi-threaded processing
  6. Supports Distributed Computing
  7. JVM does the memory management
  8. What are the differences between JRE, JDK and JVM?

Architecture neutral

Java was designed to enhance C++, an object oriented programming language. Code written in C/C++ is compiled to machine specific (OS dependent) assembly language (object file), which means if you compile the same program on a Linux machine and on a Windows machine, the both the object files will be different.

Java was designed keeping in mind write once run anywhere logic. Java source code is compiled to a byte code (class file) which is same for windows, linux or any other OS. This byte code is interpreted by the Java Virtual Machine (JVM) using just-in-time compiler. This is why Java is called Architecture Neutral or Platform Independent.

Java programmers removed complicated features like pointers, multiple inheritance and destructors. On the brighter side, the have added automatic garbage collection by the JVM for better memory management, and multi-threaded environment, with library support for network programming.

Object Oriented

Java is not a pure Object Oriented language since it supports some primitive data types for optimization of performance.

It supports abstraction, encapsulation, inheritance and polymorphism, the fundamental principles of Object Oriented language.

It has access specifiers for access control. You may choose to hide the implementation details or data from child classes.

Java also supports dynamic binding or late binding or runtime binding, which delayes the determination of code to be executed until runtime.

Java supports both overloaded and overridden methods. When we override a method, we use polymorphism, declaring that the class may have its own behavior for a particulat method, or some additional behaviour with respect to the parent method, and this will be determined at runtimes.

Java supports both the Inheritance and Composition feature of Object Oriented language. A class can extend another class or be subtype of other class, this is inheritance or ‘IS A’ feature in OO language. A class data can also be of any other defined class type, which is composition or ‘HAS A’ feature.

Note: Java does not support multiple inheritance, meaning a class can only extends one class or have only a single parent class. Although, java supports multiple inheritance of type, which means java allows classes to extend another class, as well as implement other classes.

Statically Typed

Java is a statically typed language, meaning we have to declare the data types of the variables before using them. The type checking is performed at compile time. In case of dynamically typed languages, the type checks happen at runtime.

Java is more strongly typed than C/C++ since it removed pointers but not as strongly typed as compared to other languages as it does implicit data-type conversions.

Dynamic Programming Language

Any language which allows to add new code, extend objects and definitions, and modify the type systems can be considered a dynamic programming language. Java is a statically types language but considered a dynamic programming language because it supports runtime execution, reflection, and inheritance.

Supports Multi-threaded processing

Java supports multi threaded execution but it has to be user-defined. The default program starts with a single thread, called the main thread. This thread can be used to create additional threads.

Supports Distributed Computing

Java has many features that support communication across distributed systems. It contains extensive TCP/IP networking facilities and library routines support protocal like HTTP and FTP.

JVM does the memory management

If you have worked with C/C++, you would surely know the pain of writing destructors. Java has removed the concept of destructors and has introduced garbage collection mechanism.

Definition: Garbage collection is the process of looking at the heap memory, identifying unused objects and deleting them so as to reclaim the underlying memory and use the same for future object allocation.

Multiple garbage collectors (GC) are available and for a high end application, Java’s GC could impact the performace of the application since it could tie up the much needed resources for cleanup while it is executing. So the user must tune the right garbage collector for such application enviroments.

Few of the available garbage collectors are listed below:

  • The Serial GC (default for Java 5 and 6)
  • The Parallel GC
  • The Concurrent Mask Sweeper (CMS) Collector
  • Garbage First (G1) GC (Available from Java 7 onwards)

Difference between JRE, JDK and JVM

  • JDK or Java Development Kit contains the development tools, compiler, debugger, etc along with the JRE. We dont need a JDK to run a java program.
  • JRE or Java Runtime Environment contains only class libraries and executables required to run a java program.
  • JVM or Java Virtual Machine is a virtual machine which provides an environment to execute java bytecode.