Introduction to Java

Tanisha Singh
7 min readApr 28, 2020

--

Illustration by SinghTanisha16

It is a third generation Object Oriented Programming Language which various features for writing program or codes or applets.

Java was first developed under the name ‘Oak’ and was renames to Java in 1995. The program developed in Java can run on any platform and platform here refers to computer system including accessories including operating system.

Highlights of this blog:

What is Object Oriented Programming?
Principles of Object Oriented Programming
Java Compilation Process
Elementary Concept of Class
Hello World!

What is Object Oriented Programming?

To understand Object Oriented Programming, we first need to understand what is an object.

What is an Object?

An object is an identifiable entity with some characteristic (or data), a state and behavior (or function) is known as an object.
For example — car, bike, chair, bank account, data, etc.

Let’s look at this sentence more closely:

Identity: The name by which an object is recognized.
State: It refers whether an object is processes or unprocessed.
Behavior: It refers to the functionalities of the object or in simple words, what it can do.

Everything around you is an object

Let’s take the example from real life. Consider yourself as an object. Your identity is your name by which you are referred. Your characteristics can be said as if you’re a girl or boy, if you are short or tall, etc. For you, the state can be if you are sleeping or you are awake. And the behavior is your capabilities.

Let’s take another example of a bike. The name of the bike Duke is the identity. Its characteristics or features are that its of black colour, the strength of its engine, the size of its tyres, etc. It has the states: on, off and out of order (not working properly).Its behavior is to start the engine, changing the gear, applying the breaks, etc.

I hope the concept of objects might be clear to you from the given examples. Now, let’s move on to OOP.

Object Oriented Programming

It is a programming methodology which helps to organize set of instructions in a proper sequence to develop a program or software is known as Object Oriented Programming (OOP).
(Programming methodology means the way of writing program)

It makes the code less complex, reusable, easier to understand and maintain.

The programming languages other than Java which support OOP are Python, C++, Visual Basic, C#, . NET, Ruby etc.

Principles of Object Oriented Programming

OOP in Java

Every OOP (Object Oriented Programming) includes objects with the following principles:

1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism

Let’s have a look at these features more closely.

1. Abstraction

The act of representing the essential features of an object without knowing the background details is known as Abstraction.

Let’s take the example of your phone. While you are using your phone, your main concern is to make calls or check social accounts. There are other features in too but this is our main concern, connecting to people. So, phone, here an object, for which our main concern is to connect with the people not on how calling works, how the OS works, how do the apps install etc. We just use it without knowing its background details.

Another important aspect of data abstraction is data hiding.

Data Hiding: The property which does not allow the data and its functions to be used publicly is known as data hiding or data abstraction.

For data hiding, let’s take the example of television. You use TV to watch serials, movies, listen to music and all. You go for its outer appearance but you don’t know what’s the components used inside of it because its not visible. It is not something for the outer world. Thus, you cannot see it, but you can feel it only. This is what data hiding is.

Don’t confuse data hiding and data abstraction. Data hiding is an aspect of data abstraction. If you will go for the difference of it, you won’t be able to differentiate it. Because they are not complimentary to each other or anything like that which makes it comparable. It’s an aspect of data abstraction. It’s a part of data abstraction. You cannot compare it.

2. Encapsulation

The act or way in which data and methods/functions are combined together in the form of a single unit is known as encapsulation.

By definition in programming, wrapping up of data members and its member functions into a single unit is known as encapsulation.

You can take the example of TV. It is an encapsulated unit that combines many components (objects) with its own behavior. You may consider various components of TV as data and their behavior as functions.

Abstraction and Encapsulation are related to each other. You’re a student, consider yourself as an object. You are an encapsulated unit in the form of details such as: your name, date of birth, father’s name, mother’s name, etc. Here, the abstraction would be considering you as a student, i.e., name, date of birth, father’s name, mother’s name, etc.are only needed and all other details are left out.

3. Inheritance

The act or process of acquiring properties from an existing class (or base class) by another class (derived class) is known as inheritance.

Base Class: The existing class whose properties are inherited by some other class is known as base/super/parent class.

Derived Class: The class that acquires properties from existing class is known as derived/sub/child class.

Now, in simple words, inheritance is acquiring the properties from an existing object to some other object.

For example, take yourself as an inherited object. You have inherited some properties from your parents/grandparents. Hence, you can be said as the derived class (you have acquired properties) and your parents/grandparents can be said as base class (from whom you have acquired properties).

Let’s take another example. Take chips as the base class. Taking chips as the base class, tomato flavour chips, chilli flavour chips, cream and onion flavour chips are the derived class.

4. Polymorphism

The act of representing an object in many forms is known as polymorphism (The word poly itself means many).

Take the example of TV. The TV is an object and LCD, LED, OLED etc are its many other forms. Take the example of a table as an object. The table also exists in many forms; dining table, studying table, round table, etc.

Java Compilation Process

Before moving on to the compilation process, these are some of the important terminologies we need to know beforehand:

Byte Code: The platform independent code generated by the Java Compiler after converting the source code. It is easily understood and executed by the compiler. It is also known as Virtual Machine Code. (Platform independent means you can run the code written in one machine to some another machine without any changes in the original code.)

Interpreter: The interpreter converts the source code (high level language) into machine code (low level language) line by line.

Compiler: The interpreter converts the source code (high level language) into machine code (low level language) at once.

Java Virtual Machine: The interpreter for Java is known as Java Virtual Machine (JVM). It interprets the byte code into machine code.

The high level language is your source code which is written in English words, understandable by human. The low level language is binary (0 and 1) which is understood by machine, not easily understandable by us.

The Compilation Process of Java

Java does the compilation process in two steps.

Step 1: The Java compiler compiles the source code and generates the byte code.

Step 2: The JVM (Java Virtual Machine) takes the byte code as input and generates the output by interpreting the byte code.

Java’s compiler works in a different as it takes the source code as input and generates the byte code. Java’s interpreter JVM interprets the compiled byte code to machine code.

Elementary Concept of Class

A class can be said as collection of objects of similar kind or a blueprint of objects.

Consider car as a class. All the different types of cars such as Swift, Breeza, WagonR etc. are the objects. Taking TV as a class, all the different types of TVs around the world are its objects.

Class, collection of objects of similar kind.

Class and Java Language

While writing a program in Java, a programmer will write his/her program in a class. The data of the class will be called as member variable or instance variable or member function. The code of the class forms member methods.

Hello World!

To print the famous hello world, write the following code in your following IDE:

public class Hello{
public static void main(){
System.out.println("Hello, World!");
}
}

The code above will print the below line as the output:

Hello, World!

You can try on experimenting and print whatever you like by make changes inside the “ ” in System.out.println().

If you found this article worthy for you and learnt something from it, please give time for hitting the clap button until it disappears. Also, don’t forget the hit the follow button. Connect with me on LinkedIn or follow me on Twitter.

--

--

Tanisha Singh

A highly empathic UI/UX Designer, creating delightful and accessible experiences for all people