









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










Java is a class-based, object-oriented programming (OOP) language for building web and desktop applications. It is the most popular programming language and the language of choice for Android programming.
A class is a blueprint or a set of instructions to build a specific type of object. It is a basic concept of object-oriented programming, which revolves around real-life entities. A class in Java determines how an object will behave and what the object will contain. A class is a group of objects which have common properties. It is a template or blueprint from which objects are created. It is a logical entity. It cannot be physical.
An object is an instance of a class. OR An entity that has state and behavior is known as an object. An object has three characteristics: State Behavior
Identity · Differences between Objects and Classes: There are many differences between objects and classes. A list of differences between objects and classes is given below: No. Object Class
public My Class {public void write Text(String text) { System. out. print(text); //prints the text parameter to System.
The parameters are placed in a parameter list inside the parentheses that follow the method name. For each parameter used by the method, you list the parameter type followed by the parameter name. If you need more than one parameter, you separate the parameters with commas. public void getGrade ( int marks) { Final.getGrade(59);
A loop is a structure, series, or process whose end is connected to its beginning.
(A) for loop (initialize; conditions; inc/dec) { //code (B) Enhanced for loop (C) while loop while (Condition) {
(D) do-while loop Do {
} while(Condition);
The switch statement or switch case in Java is a multiway branch statement. Based on the value of the expression given, different parts of code can be executed quickly. The given expression can be of a primitive data type such as int, short, byte, or char.
The switch case in Java is used to select one of many code blocks for execution.
Syntax is the arrangement of words and phrases to create well-formed sentences in a language.
A constructor is a special method that is used to initialize a newly created object and is called just after memory is allocated for the object. It can be used to initialize the objects to desired values or default values at the time of object creation. It is not mandatory for the coder to write a constructor for a class.
There are three types of constructors: a. Default constructor b. No-arg constructor c. Parameterized constructor OOP CONCEPTS IN JAVA OBJECT-ORIENTED PROGRAMMING (OOP)
=> Inheritance => Abstraction => Encapsulation => Polymorphism Inheritance in Java OOP: Learn Different Types with Examples
Inheritance is a mechanism in which one class acquires the properties of another class. For example, a child inherits the traits of his/her parents. With inheritance, we can reuse the fields and methods of the existing class. Hence, inheritance facilitates reusability and is an important concept of OOP.
Here are the different types of inheritance in Java: Syntax: Class A(child) extends Class B(parent)
(B) Multiple Inheritance: Multiple inheritance is a type of inheritance in Java in which one class extends more than one class. Java does not support multiple inheritance. Java Multiple Inheritance As shown in the above diagram, Class C extends both Class A and Class B.
(C) Multilevel Inheritance: In multilevel inheritance, one class can inherit from a derived class. Hence, the derived class becomes the base class for the new class. Multilevel Inheritance As shown in the diagram, Class C is a subclass of Class B, and Class B is a subclass of Class A. (D) Hierarchical Inheritance:
Hybrid Inheritance in Java As shown in the above example, all the public and protected members of Class A are inherited into Class D, first via Class B and then via Class C. Note: Java doesn’t support hybrid/multiple inheritance. Abstraction in Java OOP | Abstract Class & Method with an Example
Abstraction in Java shows only the essential attributes and hides unnecessary details of the object from the user. In Java, abstraction is accomplished using
abstract classes, abstract methods, and interfaces. Abstraction helps in reducing programming complexity and effort. An abstract method in Java is a method that has just the method definition but does not contain an implementation. A method without a body is known as an abstract method. It must be declared in an abstract class. The abstract method will never be final because the abstract class must implement all the abstract methods. What is an Interface in Java? How to Implement an Interface with an Example Encapsulation in Java OOP with an Example
Encapsulation in Java is a mechanism to wrap up variables (data) and methods (code) together as a single unit. It is the process of hiding information details and protecting the data and behavior of the object. It is one of the four important OOP concepts. The encapsulated class is easy to test, so it is also better for unit testing.
Getters and setters in Java are two conventional methods used to retrieve and update values of a variable. They are mainly used to create, modify, delete, and view the variable values. The setter method is used for updating values, and the
Try-Catch in Java: Exception Handling Example
An exception in Java is an event that interrupts the execution of program instructions and disturbs the normal flow of program execution. It is an object that wraps information about an error event that occurred within a method, and it is passed to the runtime system. In Java, exceptions are mainly used for indicating different types of error conditions.
A static variable in Java is a variable that belongs to the class and is initialized only once at the start of the execution. It is a variable which belongs to the class and not to an object (instance). Static variables are initialized only once, at the start of the execution. These variables will be initialized first, before the initialization of any instance variables. A single copy is shared by all instances of the class. A static variable can be accessed directly by the class name and doesn’t need an object.