1. STARTING WITH JAVA OOPS.
By alpha20edu Published Uncategorized
Java is an Object-oriented programming language. Your first question — What is Object Oriented Programming (OOPs)?
So far we have slightly understood that world of computers is different from human world. We speak English, Hindi, Bengali, Tamil, French, German & so on but computer understand only 0 & 1s. We humans have emotions but computer has no emotion. So, understand that world of circuits & programs (instructions) within your laptop box is very different from our real world.
However, computer scientists & engineers have made tremendous efforts over many years to relate the world of computer with the real world. They have made efforts to simplify the instructions which we give to computers as much as close to the real world as possible, so that any human can apprehend those instructions & the mind can easily think of creating the instructions in order to make computer do a task / solve a problem.
There have been many programming languages popular over the years. Each language had its own uniqueness & style & specialities. Like some were procedural oriented languages. They had their own pros & cons. Like C, C++ — some were procedural oriented languages.
Concept Repeat — What is programming language?
It is the system (collection) of instructions which we give. If I ask you — what is a language? It is a system (collection) of words for conveying our thoughts to other humans and understanding their thoughts. There are many languages in the world. Each language has its own collection of words.
Eg: If you need water from a shopkeeper, in English you will use following 7 words from the dictionary / vocabulary of English:
“Please give me a bottle of water.”
While in Hindi, you will use following 6 words from the dictionary of Hindi —
कृपया मुझे एक बोतल पानी दीजिए।
So, in two different languages, the words used are different. No. of words taken from the vocabulary is different.
Exactly on the similar lines, programming language is a system (collection) of words for conveying our instructions to computer. There are many programming languages in the world. Each programming language has its own collection of just computer words.
Eg: If you need to just display your name on the old device (monitor), in C++ programming language, you will use following instruction:cout << "IDepuzzled";
In Java PL, you will use following now…from here onwards, people broadly use “computer” and “entity” interchangeably.
-
* System.out.println("IDepuzzled");
-
- In C, it is
printf("IDepuzzled");
- In C, it is
Note: Here we are talking about high level language.
There are different ways based on which a programming language can be classified. To keep it simple, we will categorize high-level programming languages (PL)into
Procedural for PL – The programming language which come under this category allows you to write program in a procedural way to get your task done from computer that means your program will consist of one or more procedures each having set of statements or commands (will clarify the difference b/w the two later on. For now think it as instruction).
ANALOGY1.1:
Sam”s mother wants to get multiple tasks done by Shushil. She writes one paper containing instruction or how/what to purchase from grocery store third paper paper containing instruction instruction on how/what to purchase from clothes market So you can see Sam’s mother shared 3 set of papers each containing set of instruction. The ultimate aim is to get those things (groceries + apparel) for the market. She ordered Smartly & bifurcated the instructions into different pieces of paper. That each paper as procedure. Procedures are logically separate portion of instructions. But the ultimate goal is to get an aim/task done by expecting computer to run/execute all those procedures (instructions within those procedures to be placed).
Eg: BASIC, Pascal, C, even one Java.
2) Functional PL: The main difference between procedure & function (not the annual function in your school/college) is that procedure is set of instructions which is executed but nothing is returned to the caller of procedure so that caller may know what was the result of the execution. Whereas function is what you have read in your maths classes, i.e., y = f(x). You pass some arguments to a function & it surely returns you a data/value. So these PLs have functions instead of procedure. Again a function will have set of instructions in that programming language only but it will return some result on the completion of execution of the instructions back to caller of function so that the same can be used further…
Eg: Scala, Erlang, Haskell, F#
3) Scripting language — The PLs in this category help the user to automate the tasks which are repetitive & manually done can be inefficient & error prone. These are widely used in commercial corporates. Eg: bash (UNIX), Python, Ruby, PHP, etc.
4) Logic PL: These are new generation PL which are widely used in AI & ML.
ANALOGY 1.2: Sam’s mother is over-expecting from Sushma. She says, “Come with me for next 7 days & see how I am shopping & learn. From 8th day, I will not give you instructions, you will have to shop yourself.”
Eg: Prolog, Abyss, Datalog etc.
5) Object Oriented PL: Although Java is the best example of OOPL & the founder is James Gosling, however OOPS concept was made & its first appearance in 1960s. This PL is an effort to write computer program in oriented or aligned with real world object. That will somehow make the way for a common man easy to write instructions to solve a small problem to solve a complex problem.
Let’s talk more about OOPs concept
Note: OOPs is not Java. Java is one of the many PLs developed following the principles of OOPs. So OOPs is a theoretical concept which puts stress on programming using real-world objects.
We live on this beautiful planet Earth. We are surrounded by a lot of objects around us — sun, moon, stars, sky, cloud, trees, dog, cat, human, friends, bed, car & so on. The list is huge.
OOP scientists thought — why can’t we create such objects in computer? How will we create such objects? That is next part of the question which is a question on the implementation. But before that, what scientists analyzed/observed about real world objects which they then thought to bring into computer.
Consider one object — Car. If I ask a kid to write an essay on car, probably his essay will have some of the points from below —
-
- ① A car is a mechanical device
-
- ② It solves the problem of movement from one place to other
-
- ③ It is available in variety of colors like grey, white, black, red, etc.
-
- ④ It has 4 wheels.
-
- ⑤ It can run upto a speed of 160 km/hr
-
- ⑥ It uses petrol, diesel or electric as fuel
-
- ⑦ It ejects out smoke
-
- ⑧ It has engine with these many features.
-
- ⑨ It can apply brake
-
- ⑩ It can be of several types like hatchback, sedan, SUV, etc.
Go through the lines of essay written by the kid & think a bit. You will notice that some of the lines will tell what are the tasks/functions a car can do? While some other lines will tell us about the qualities/features of the car? Can you point out what are the lines which tell what are the tasks/functions a car does? IMO, they are point #①? No, because it is a mechanical device does not represent its function — so IMO they are ②, ⑤, ⑥, ⑦, ⑨. (Think of the rest.)
Now can you point out what are the lines which tell about the qualities/features of the car? IMO, they are ①, ③, ④, ⑥, ⑧, ⑩. Note that there can be possibility of ambiguity & some/it might fall into both categories just like it happened with ⑥.
So, to sum up we can say that an Object can have several attributes (like ①, ③, ④, ⑥, ⑧, ⑩ exhibited by car object)
…and it can show certain behaviour (as indicated by ②, ⑤, ⑥, ⑦, ⑨).
Task: Just take any object of your choice from the surroundings & apply the above understanding. Do it for 7 different objects to understand & make the concept sit in your secondary memory (permanently).
Time to little fine-tune our understanding of objects. When I said we jotted down all the things we see around us when I asked ourselves to list the objects. Think for a moment, Car is really an object? Yes, car is an object & it has its set of attributes & behaviour. If you can give a common name to more than many objects or a group of objects which have similar set of attributes & behaviour, that name will be called “class”. So if I have Tata Nano and I am asked to write the attributes & behaviour of it, I wrote x no. of lines. My neighbour has Audi and he is also asked to write the attributes & behaviour of it, he wrote y no. of lines. Upon reading both’s attributes & behaviour we could intellectually relate that both are objects as they both have attributes & behaviour.
A common name can be given because they have many similarities in attributes & behaviour. We have that name as “car”.
So, “Car” is a class & “Tata Nano” & “Audi” are the objects of the class named Car.
-
- You can think of class as an umbrella folder under which objects of similar attributes & behaviour are kept.
-
- You can think of class as a common noun while its objects as proper noun.
Eg: Boy is a common noun. Rama/Sam is a proper noun. Boy is a class. Sam is an object of a class called Boy. Caution: This is for understanding purpose only.
- You can think of class as a common noun while its objects as proper noun.
Now, there can be more enhancement to above example. We said that “Tata Nano” is an object. However, in another situation “Tata Nano” can be a class. “Vinay’s Tata Nano” can be an object of this class. “Raju’s Tata Nano” can be another object of this class.
Note: An object will always be attached/associated to a class. So, determining class & objects will depend on the project we are working & the problem we are trying to solve.
So, An object has attributes & behaviour. What these attributes an object has, will be defined in its class. The value of these attributes will then be defined/attributes within the class will vary from one object that has the same class to another.

⇒ Characteristic Features of real-world Objects
There are several characteristic features which we see real-world objects exhibit. We apply these principles in our OOP PL like Java. Understanding these are backbone to knowing Java. Let us understand these features —
1) Encapsulation — We saw examples of object. Each Object is exhibiting certain behaviour & has certain attributes. Just like in previous example, Audi object. This object has encapsulated attributes viz. color = Red, engine = X420Turbo, etc. & behaviour — move, apply brake, fill fuel within it.
2)Abstraction — The art of representing essential features without including the background details is called abstraction. God has followed abstraction inheritance properly while creating objects which He created. Human — you don’t need to see or touch the brain, heart, kidney, liver, etc. so they all are hidden. Only the essential features are visible. Similarly most of the machines designed by humans followed abstraction properly.
3) Inheritance — If we are an Object. Our parents are also Objects. We are derived from other objects (parents). Objects (us) is derived from other object (parents). This is called Inheritance.
4) Polymorphism — Poly mean many — morphos means form. Polymorphism means of many forms. For eg: A manager is an object. He has one behaviour “cattalk”. However, he talks in a different way when he talks to his wife & talks in a different way when he talks to his employees.
Remember Trick: E P I A
Having understood these concepts theoretically, we are now ready to switch ON our computer & jump into the world of Java programming. It will begin!
We will try to apply all we have read theoretically into programming so that our brain can connect the real-world object with computer & then we will be ready to solve complex problems. It all depends on how smartly we program that we are able to take advantage of the computer’s speed & accuracy. Computer is like your genie. You will have to be a smart Alladin to get your job done through computer.