Posts Introduction to Object Oriented Programming and Java
Post
Cancel

Introduction to Object Oriented Programming and Java

Have you ever come across the term “Object-Oriented Programming?” Do you know what that actually means? Your questions will be answered.

As the name suggests, object-oriented programming aims at dealing with real-life objects in the programming world. An object, in programming terms, is something which has a state and a behavior. Let’s consider Fruit. Now there are different types of fruits, Apples, Bananas, Oranges, Kiwis etc. These are different from each other in many ways like the color, taste etc.

Now here, the state of the Fruit can be it’s Color, Number of Seeds, Shape etc., and its behavior can be its taste (sweet, sour etc) or if it’s ripe or not. So it’s state and behavior help in identifying the object better. Essentially, this is how we deal with objects in an OOP. We’ll talk more about this in the coming lessons.

So what makes OOP so efficient? What are the features of object-oriented programming?

Features of Objected Oriented Programming-

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

As the word encapsulate means binding or wrapping things into a single object, similarly in OOP, encapsulation essentially means to bind all the data together and hide your data in order to make it safe from any modification. One of the examples can be a class. Thus in a particular Fruit class, we can add all the features, attributes required. By declaring the attributes private you’re making sure that the data can be accessed only by its class members and no one outside it. This leads to code re-usability and avoiding writing long pieces of code and is more secure.

  • Abstraction

Data abstraction in OOP, more like information hiding i.e, reducing the code complexity.

  • Inheritance

This enables to establish a relationship between various classes and acquire its properties.   It provides code re-usability. It is used to achieve runtime polymorphism. Example: Consider an Animal class and a Dog Class. Now we define an Animal, based on number of legs, habitat, herbivore, carnivore etc. Now a Dog has 4 legs, is a carnivore and has all the features which will be defined in the Animal class. Thus we can inherit Dog from Animal class thus reducing the code.

  • Polymorphism

Performing one task in many ways is known as polymorphism. Like Method overloading, operator overloading. We’ll talk about this more in detail in the coming lessons.

 

So now that you have understood how an OOP actually works. Let’s dive right into Java. Java is an object-oriented language developed by James Gosling at Sun MicroSystems in 1995, which was later taken over by Oracle.

In Java, all the programs/ source code is written in a .java extension file. Example: hello.java.

The execution of a .java file is however different from other programming languages. We know that a compiler generates code which can run on a specific device. That is, if a program is compiled in a Windows machine, the executable file cannot run on other platforms or rather other operating systems such as MAC, Linux etc., which means they’re platform dependent. Java, however, is platform independent. That is the java compiler doesn’t create an executable file, but it creates a .class file (bytecode file). So a bytecode file can easily run on all platforms. This conversion is done through a virtual machine (bytecode acts as an object file for a virtual machine) and thus the Java compiler is Java Virtual Machine (JVM). To execute a bytecode file, we use a Java interpreter, which is available in every platform as every platform its own Java interpreter.

Thus because of the platform independent feature of Java, we call the Java applications as WORA. (Write Once, Run Anywhere)

That’s all for today. If you have any doubts, you can comment down below.

In the next lesson, you’ll learn about JDK, how to install it and write your first Java program! See ya soon :)

This post is licensed under CC BY 4.0 by the author.
Recent Update
Trending Tags

Trending Tags