JAVA and Object Oriented Programming Basic
Tags: java, oop
Published: 2018-03-07 05:42:01

---
title: JAVA and Object Oriented Programming Basic
published: true
description: JAVA and Object Oriented Programming Basic Theory In Details
tags: Java, OOP
---

**JAVA and Object Oriented Programming Basic**

Ashikur Rahman



Any real-life entity/object have two parts
-	Properties (Describes its height, weight, width etc.)
-	Functionality (Describes how it behaves)


Object-oriented programming removes some constraints of procedural programming language.
-	Modularity (Logic are modular)
-	Reusability (Code are re-usable fashion)
-	Extendable (Code are extendable)

**Object**

An object is an entity which has 
-	Identity (Names)
-	State (Values)
-	Behavior (Performance)
An object is an individual representation of a real-world entity.

**Class**

A class is a template, helps to describe common
-	Attributes (e.g. customer id, name, telephone no…)
-	Activities (e.g. purchasing an item, etc.)
Example of a real-world entity (Customer)
 
Definition of a class of different perspective:
-	A class is a blueprint/real-world entity
-	A class is a generalized representation
-	A class is an encapsulation of properties and corresponding functionality 
A program is a set of instruction to solve a problem UML (Unified Modeling Language)
A class diagram is a notation used to represent a class in a document. Class diagram is a kind of UML. UML is a language for visualizing, specifying, constructing and documenting the software.
     

**Access modifier/specifies**
 
(-) Private: Only can be accessed from inside the class where it is declared.
(+) public: Can be accessed from anywhere

 It is recommended that in a class all the variable/properties should be private and all the method/functions should be public.
Five feature of object-oriented programming:
-	Classes and objects
-	Abstractions
-	Encapsulations
-	Inheritance
-	Polymorphism


**Abstraction:**
Hiding unnecessary details and showing only necessary details. The concept of identifying the essential details to be known and ignoring the non-essential details from the perspective of an end user. 
(E.g.: Method name and parameter need to be known, we need not know the whole process) 

**Encapsulations:** 
Combining all elements into a capsule (E.g. : A class, which contains attributes and functions and all those attributes and functionality need not be exposed using access modifier we can achieve this).
The concept of hiding internal details and providing a simple interface to the user.

**Inheritance:**
Concepts of which allows defining generalized and specialized characteristic and behavior. The specialize entities automatically inherit all the properties and behavior of the generic one.
-	All the generalize details will be present in a parent class
-	All the specialize details will be present in a child class
-	A child class will extend the parent to get the generalize properties.


**Polymorphism:**
If the same method behaves different ways in different situations

Object-oriented system development:
3 main phases
-	Object-oriented analysis (OOA)
-	Object-oriented design (OOD)
-	Object-oriented programing (OOP)

**OOA:** Analysis the problem structure and identifying the number and the name of the class
**OOD:** Elaborate class structure, what should contain (attribute and functionality)
**OOP:** The process of implementing the design using the object-oriented programing language

**Member variables:** Used for representing the state of an object/attribute of a class called member variable also called global variables.

**Access modifier:** Used to access or hide the attribute and the behavior of the class

The following syntax can be used to create an object of a customer class and refer is using a reference variable.

Customer custobject= new Customer();
Custobject – Reference variable and new Customer() – is the object.

JAVA architecture is composed 3 components
-	JAVA programming language
-	JAVA byte code
-	JAVA virtual machine


.java -> .javac -> .class ->Interpreter (Win32) or Interpreter (Linux) or Interpreter (Mac)

JAVA is a byte code level platform independent
 Platform independency depends on 
-	Source code level
-	Byte code/ executable level

.cpp or c++ is a source code level platform independent but in executable level, it is not. The only component in JAVA which is platform dependent is JVM (Java virtual machine)

JVM – Converts bytecode to corresponding machine level language and executes the instructions.
JDK – Create/develop JAVA in runtime 
JRE – Runtime/ Kit just to run and compile or convert the code to bytecode
JVM – Interpreter/ Read line by line and convert byte to executable  


During the execution of a program, the storage of a program and data as follows:

-	All the java code stored in the memory called code segment
-	All the global variable we declare for a class stored in the data segment
-	All the variable which declare inside the class and outside of all the function is called member variable/ global variable
-	Life of a member variable depends on an object
-	The reference which points to a newly created object is called reference variable
-	All the details of a class should be present in the { }

Private int a;
Public void geta(){}


When we create an object it resides in the heap memory.
New keyword returns a newly created object.
The reference variable is simple variable use to access the object which is created in a heap memory.
Main is the starting point of execution of any Java program.