Write Once Run Anywhere
Write Once Run Anywhere
Write Once Run Anywhere
ON JAVA.
WRITE ONCE RUN
ANYWHERE.
WHAT IS JAVA?
Java is a class-based, object-oriented programming language that is designed to have as few
implementation dependencies as possible. It is a general-purpose programming language
intended to let application developers write once, run anywhere (WORA), meaning that compiled
Java code can run on all platforms that support Java without the need for recompilation.
● Object
● Class
● Inheritance
● Polymorphism
● Abstraction
● Encapsulation
Features of OOPs
The Objects Oriented programming language supports all the
features of normal programming languages. In addition it
supports some important concepts and terminology which has
made it popular among programming methodology.
The important features of Object Oriented programming are:
● Inheritance
● Polymorphism
● Encapsulation
● Method Overloading
Inheritance
Inheritance can be defined as the process where one class acquires the properties (methods and fields)
of another. ... 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).
Polymorphism
The word polymorphism comes from the word poly(many) morphos (form).
It is the process in which the same entity behaves differently in different situations .
e.g: 9+5=14
hello+world= helloworld
Polymorphism is 2 types
1.Static
polymorphism:- When the polymorphism is achieved during compile time then it is known as static polymorphism.E.g:-
method overloading / function over
2.Dynamic polymorphism :- When the polymorphism is achieved during runtime or executing time then it is known as dynamic
polymorphism. E.g :-method overriding / function overriding.
Encapsulation
Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data
(methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other
classes, and can be accessed only through the methods of their current class.
Overloading
Method Overloading is a feature that allows a class to have more than one
method having the same name, if their argument lists are different. It is similar
to constructor overloading in Java, that allows a class to have more than one
constructor having different argument lists.
Reusability
Reusability is a mechanism which facilitates you to reuse the fields
and methods of the existing class when you create a new class. You can
use the same fields and methods already defined in the previous class.
DATA TYPES IN JAVA
Primitive types are the most basic data types available within the Java language. There are 8: boolean , byte
, char , short , int , long , float and double . These types serve as the building blocks of data manipulation in
Java. Such types serve only one purpose containing pure, simple values of a kind.
● for loop
● while loop
● do-while loop
Method Overloading and Overriding
(1)Overriding implements Runtime Polymorphism whereas Overloading implements Compile
time polymorphism.
(2)The method Overriding occurs between superclass and subclass. Overloading occurs
between the methods in the same class.
(3)Overriding methods have the same signature i.e. same name and method arguments.
(4)Overloaded method names are the same but the parameters are different.
(5)With Overloading, the method to call is determined at the compile-time. With overriding,
the method call is determined at the runtime based on the object type.
If overriding breaks, it can cause serious issues in our program because the effect will be
visible at runtime. Whereas if overloading breaks, the compile-time error will come and it’s
easy to fix.
Abstraction
We can perform abstraction by abstract class or interface. Abstraction is the process of
representing essential features without including the unnecessary details (background details).
Abstract Class
An abstract class is a class that is declared abstract it may or may not include abstract methods.
Abstract classes cannot be instantiated, but they can be subclassed.
Interface
An interface in Java is a blueprint of a class. It has static constants and abstract methods.The interface in Java is a
mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method
body. It is used to achieve abstraction and multiple inheritance in Java.
In other words, you can say that interfaces can have abstract methods and variables. It cannot have a method body.
Difference between Abstract class and Interface
Java Packages