Chamal Weerasinghe

Apr 28, 2021

3 min read

What is Java?

Photo by Michael C on Unsplash

“History is who we are and why we are the way we are.” — David McCullough

Little Bit of History of Java

Java was invented in 1995, However, Its developments started around 1990 by James Gosling with his colleagues Mike Sheridan and Patrick Naughton in Sun Microsystems at that time. The reason they develop Java is the team working on writing programs into digital devices and their main language was C++, Due to the complexity and manual memory management there are often leads to errors, So they want a programming language that does not depend on the CPU architecture and run programs without having to write different implementation from one device to another. That’s where the famous “Write once Run Anywhere” concept started. Later it matured from digital devices to a wide area of platforms including modern cloud environments.

Java’s Principles are: “Simple, Robust, Portable, Platform-independent, Secured, High Performance, Multithreaded, Architecture Neutral, Object-Oriented, Interpreted, and Dynamic”

What Actually is Java?

Simply Java is a programming language, is that all? Yes and No. 😀

Java is a high-level, class-based object-oriented programming language that is based on a syntactically similar approach to C and C++.

Why Java is Not a Pure OOP Language

Though Java is object-oriented, And it is not a purely object-oriented programming language, Before finding out why not we have to take a look at the factors that make a pure OOP language,

  1. Abstraction.
  2. Inheritance.
  3. Polymorphism.
  4. Encapsulation.
  5. All user-defined types are objects.
  6. All predefined types are objects.
  7. All operations performed on objects must be only through methods exposed at objects.

Well, when it comes to the last three points there is a bit of confusion, Let’s take the 5th and 6th points, All user-defined types and predefined types are objects. in Java this is false, Java uses 8 primitive types which consider as non-objects.

int x = 10;
char y = 'c';

So what about the wrapper classes? “Integer”, “Boolean”, “Float” and “Double” But when it comes to the mathematical operators in numeric primitives the values should be converted back to the respective primitive and back to the wrapper class when needed using the concepts Unboxing and Autoboxing.

Now to the 7th point, All the operations performed in objects through methods exposed at the object. Java uses the “static” keyword to define elements that belong to the class context, these variables or methods shared between all the instances of the class. But without having to create an object we can call these static methods or variables directly,

As an example first, we create a class with a static method and a variable.

public class JokeService {    public static String joke = "COVID-19 will be gone in no time!";    public static void sayMyName(String name){
System.out.println(name);
}
}

Now we calling it in another class without creating an object

public class Runner{    public static void main(String[] args) {
System.out.println(JokeService.joke);
JokeService.joke = "New Joke";
JokeService.sayMyName("John");
}
}

By looking at this code which proves it’s possible to invoke methods, get value, or set value from variables without actually creating an instance of a class (Object), making the 7th point invalidate and making Java, not a pure OOP language

But that does not mean the only way of writing Java programs is the class-based OOP or there is no way of using other programming paradigms, Java is also capable of writing programs using Functional Programming and Reactive Programming Approaches.