Java Oops Concepts1
Java Oops Concepts1
• The object is Real-world entities i.e Pen, Paper, computer, watch, fan,
etc.
• Object-Oriented Programming is a methodology to implement real-
world entities by designing a program using classes and objects.
• OOPS(Object-Oriented programming System) provides a paradigm to
simplifies the development and maintenance of a Software.
Main concepts of OOPS
• Object
• Class
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
• Dynamic binding
• Message passing
OBJECT
• Suppose if you are in class room that time you behave like a student,
when you are in market at that time you behave like a customer,
when you at your home at that time you behave like a son or
daughter, Here one person present in different-different behaviors.
• Sometime your mobile behaves as a phone, sometime
as a camera, sometime as a radio etc. Here the same
mobile phone has different forms, so we can say the
mobile object is polymorphic in nature.
MESSAGE PASSING
DYNAMIC BINDING
• Abstract methods are methods with no implementation and without a method body. They do not
contain any method statement.
• The child classes which inherit the abstract class must provide the implementation
of these inherited abstract methods.
• {
• {
• }
• public voidshow2()
• {
INTERFACES
• Defining Interfaces:
• Interface is a kind of a class but contain only final variables and abstract
methods.
• Interfaces do not specify any code to implement these methods and data fields contain
only constants.
• It is the responsibility of the class that implements an interface to define the code
for implementation of these methods.
• Syntax:
• interface <interfacename>
• {
• }
FINAL keyword
• The final keyword declared with variable, method, and class indicates that “This cannot be
modified”.
• Final is a keyword that is used to restrict the user in Java programming.
• Java Final keyword has three different uses:
1. To create constant.
2. To prevent inheritance.
3. To prevent method from being overridden.
Final key word
Difference between abstract class
and interface
constructor
Garbage collection in java
• The java Standard library (API) includes lots of classes and packages
1. Language support package.
2. Utilities package
3. Input/output package
4. Networking package
5. AWT package
6. Applet package
JAVA Vs C
• Examples:
number = new int[5];
average = new float[10];
INITIALIZATION OF ARRAYS
In this step values are put into the array created. This process is
known as initialization.
arrayname[subscript] = value;
Example:
number[0]=35;
number[1]=40;
.............
number[n]=19;
• int[ ] primes = {2, 3, 5, 7, 11, 13, 17};
Points to ponder:
• In this, the first index selects the row and the second index
selects the column within that row.
• For creating two-dimensional array, same steps are to be
followed as that of simple arrays.
• Example:
int myArray[ ][ ];
myArray = new int [3] [4];
Collections in java
Difference between array and arraylist
Exception handling
• Java Exceptions
• When executing Java code, different errors can occur:
coding errors made by the programmer, errors due to
wrong input, or other unforeseeable things.
• When an error occurs, Java will normally stop and
generate an error message. The technical term for this
is: Java will throw an exception (throw an error).
Java try and catch