Showing posts with label Java Basic. Show all posts
Showing posts with label Java Basic. Show all posts

Thursday, September 21, 2017

oops-concepts-in-java-interview-questions

(1) What is OOPS in Java?
The object-oriented programming system(oops) is a methodology which provides us certain concepts. By using these concepts we can easily design our application with related to the real-world entity.

(2) What are some core concepts of OOPS in java?
There are some different core concepts of oops and these are
Class
Object
Polymorphism
Inheritance
Encapsulation
Aggreagation
Composition
Association
Abstraction

What is class in Java?
A class is a blueprint or template of an object in java which can have field, constructors, methods, objects. The class is a logical entity.

What is an object?
An object is an instance of a class and it is dynamic memory allocation of class. An entity that has properties(state) and behavior is known as object e.g fan, pen, laptop, mobile, etc.

What is are the characteristics of the object?
1) State

Instance variables(i.e data member) is known as object state.

2) Behavior

An instance method is known as object behavior.

3) Identity

An object identity is implemented via unique ID. This unique id is internally used by JVM to identify each object uniquely. Identity is the hashcode of an object and it is a 32-bit integer number.

What is Polymorphism?
In simple word, Polymorphism means one name many forms e.g A child in home behave(work) like a son and in school behave(work) like a student so there is one name child but producing different-different behaviors in different-different circumstances.

Types of Polymorphism?
There are 2 types of polymorphism.
Compile-time or Static polymorphism.
Run-time or Dynamic polymorphism.

What is Method Overloading?
Method overloading is also known as compile-time polymorphism in java. Method overloading, whenever we have more than one method with the same name but the different number of parameters or the different type of parameter in the same class is known as method overloading.

What is Method Overriding?
Method overriding is also known as runtime polymorphism in java. To achieve method overriding there must be a parent-child relationship(inheritance) i.e Is-a relationship. Whenever we have same name method in both parent and child class with the same number of parameters and types is known as method overriding.

What is inheritance?
Inheritance means re-usability and it is basically used to achieve runtime polymorphism or dynamic binding in java. In this concept, there is parent-child relationship i.e Is-a relationship and child can inherit or reuse all the methods and properties of its parent class by using "extends" keyword.

Types of Inheritance?
1. Single Level Inheritance
2. Multilevel Inheritance
3. Multiple Inheritance
4. Heirarchical Inheritance
5. Hybrid Inheritance

Does Java Support Multiple Inheritance?
Java does not support multiple inheritance through the class but it is possible through the interface.

What is Abstraction in Java?
Abstraction is also an object-oriented feature of java which shows only functionality or useful data to the user and hides internal working or internal implementation details to the user.

for example: Suppose you driving a car and you using all the functions of a car but you don't know how internally this function works.



How to Achieve Abstraction in Java?
There are two ways you can achieve abstraction and these are


1. Abstract class(0 to 100%)
2. Interface(100%)
What is Encapsulation?
Encapsulation is a process of wrapping or combining the data and function into a single unit. You can use access modifiers for variables so other classes may not access it directly but it can be accessed only through public methods of the class. By using private variables you can create fully encapsulated class.

Difference Between Abstraction and Encapsulation?
Abstraction is a process which shows the functionality to the user and hides its implementation details whereas Encapsulation provides a barrier to access of data and methods.

What is Aggregation?
An aggregation is a special form of association. When one object contains another object is called aggregation in java. An aggregation represents HAS-A relationship.

For example:

class Student
{
int rollno;
String name;
Address address;//contains another object like street, city, country.

What is composition?
Composition is a special form of aggregation. If the object contains another object and contained object cannot exist without container object is known as composition.

For example:

Bus has an engine but without a bus engine cannot exist.

What is Association?
Association is a relationship between two objects. It define association between object such as one-to-one, one-to-many, many-to-one, many-to-many.

What is Static Binding?
Static binding is also known as early binding and it resolved at compile-time. Method overloading is the best example of static binding.

What is Dynamic Binding?
Dynaic binding is also known as late binding and it resolved at run-time. Method overriding is the best example of dynamic binding.

Here we have learned 4 major principles of object-oriented programming such as polymorphism, inheritance , encapsulation, abstraction, etc.

Friday, January 27, 2017

Tuesday, January 24, 2017

Sorting number using class and interface--




A small program use java object oriented program


Sunday, January 15, 2017

inheritance in java

Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.

The class which inherits the properties of other is known as subclass (derived class, child class) and the class whose properties are inherited is known as superclass (base class, parent class).


Inheritance represents the IS-A relationship, also known as parent-child relationship.


Example of Single Inheritance






Example of Multilevel Inheritance




Example of Heirarchical Inheritance




Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Any Java object that can pass more than one IS-A test is considered to be polymorphic


There are two types of polymorphism in java: compile time polymorphism and runtime polymorphism. We can perform polymorphism in java by method overloading and method overriding.


Example of method overloading




Example of method overriding




Tuesday, January 10, 2017

Introduction to OOP :

What Is an Object?

An object is a software bundle of related state and behavior. Software objects are often used to model the real-world objects that you find in everyday life. 

What Is a Class?

A class is a blueprint or prototype from which objects are created. 

What Is Inheritance?

Inheritance provides a powerful and natural mechanism for organizing and structuring your software. 

What Is an Interface?

An interface is a contract between a class and the outside world. When a class implements an interface, it promises to provide the behavior published by that interface. 

What Is a Package?

A package is a namespace for organizing classes and interfaces in a logical manner. Placing your code into packages makes large software projects easier to manage.

Monday, December 19, 2016

super keyword use in Java || জাভায় super কিওয়ার্ড ব্যবহার

জাভায় super কিওয়ার্ড ব্যবহার

java super কিওয়ার্ড  ব্যবহার করা হয় parent class এর object .

super কিওয়ার্ড ব্যবহার:
  1. super is used to refer immediate parent class instance variable.
  2. super() is used to invoke immediate parent class constructor.
  3. super is used to invoke immediate parent class method.


super is used to refer immediate parent class instance variable




super() is used to invoke immediate parent class constructor.



super is used to invoke immediate parent class method

Sunday, December 18, 2016

final keyword use in java || জাভায় final কিওয়ার্ড ব্যবহার

 জাভায় final কিওয়ার্ড ব্যবহারঃ


জাভায় final কিওয়ার্ডটি বিভিন্ন contexts এ ব্যবহার করা হয়। জাভায় final কিওয়ার্ড ব্যবহারে সীমাবদ্ধ করে দেয় একজন ব্যবহারকারিকে । final হতে পারে।
১. Variable
২. Method
৩. Class
১. final Variable:  একটি final variable একবারই assign করা হয়। যদি final variable টি একবার রেফারেন্স করে দেওয়া হয় তাহলে অন্য কোন object দিয়ে পুনরায় ঐ variable কে re-bound হতে পারে না।
উদাহরণ দেখা যাকঃ-



বিঃদ্রঃ c++ const variable এবং জাভা final variable এর মধ্যে পার্থক্য আছে। সি ++  const variable  যখন ডিক্লার করা হয় তখনই assign করে দিতে হয়। কিন্তু জাভার ক্ষেত্রে final variable assign প্রথমে না করলে হবে এটার প্রয়োজন নাই। তবে পরবর্তীতে assign করা যায়। অব্যশই একবার assign করতে হবে।
নিচের উদাহরণটি লক্ষ্য করা যাকঃ-


Final Mehod: একটি final method কে subclass দ্বারা overridden করতে পারা যায় না।
আমারা যদি subclass দ্বারা final method কে  overridden করতে যায় সেক্ষেত্রে ভুল গুলো নিচের প্রোগ্রামে লক্ষ্য করি।


Final class: final class কে সম্প্রাসারিত  (inherited) করতে পারা যায় না।
নিচের প্রোগ্রামটি লক্ষ্য করিঃ-


লেখার মধ্যে কিছু ভুল হলে আমাকে comment করেন জানাবেন। এছাড়া উপরের আলোচিত টপিক্স আর উপর আরও তথ্য আমাকে শেয়ার করতে পারেন।
ভাল থাকুন অন্য কোন topics নিয়ে অন্য কোন সময় আলোচনা করা হবে।

Tuesday, December 13, 2016

Java Basic -How JVM Works – JVM Architecture?

JVM(Java Virtual Machine) acts as a run-time engine to run Java applications. JVM is the one that actually calls the main method present in a java code. JVM is a part of JRE(Java Run Environment).
Java applications are called WORA (Write Once Run Everywhere). This means a programmer can develop Java code on one system and can expect it to run on any other Java enabled system without any adjustment. This is all possible because of JVM.
When we compile a .java file, a .class file(contains byte-code) with the same filename is generated by the Java compiler. This .class file goes into various steps when we run it. These steps together describe the whole JVM.



Image Source : https://en.wikipedia.org/wiki/Java_virtual_machine