0% found this document useful (0 votes)
9 views31 pages

11zon Merged PDF

The document contains multiple Java programs demonstrating various concepts such as JDBC for database operations, multithreading for displaying alphabets and numbers, JSP for user interactions, and object-oriented programming principles including constructors and the use of the 'this' keyword. Each section provides code examples for tasks like inserting employee details into a database, converting numbers to words, and checking for prime numbers. Additionally, it outlines the servlet life cycle and JDBC process with explanations.

Uploaded by

m.v.ujgare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views31 pages

11zon Merged PDF

The document contains multiple Java programs demonstrating various concepts such as JDBC for database operations, multithreading for displaying alphabets and numbers, JSP for user interactions, and object-oriented programming principles including constructors and the use of the 'this' keyword. Each section provides code examples for tasks like inserting employee details into a database, converting numbers to words, and checking for prime numbers. Additionally, it outlines the servlet life cycle and JDBC process with explanations.

Uploaded by

m.v.ujgare
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

b) Write a Java Program to accept details of employee (eno, ename, salary),

store it into database and display it.


import java.sql.*;
import java.util.Scanner;

public class EmployeeDB {


public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in);
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/yourDB",
"root", "password");
PreparedStatement stmt = con.prepareStatement("INSERT INTO Employee VALUES (?, ?,
?)")) {

System.out.print("Enter Employee No: ");


stmt.setInt(1, sc.nextInt());
sc.nextLine();
System.out.print("Enter Name: ");
stmt.setString(2, sc.nextLine());
System.out.print("Enter Salary: ");
stmt.setDouble(3, sc.nextDouble());
stmt.executeUpdate();
System.out.println("Employee data inserted!");

} catch (Exception e) {
System.out.println(e);
}} }

a) Write a JDBC program to accept details of Book (B_id, B_name,


B_cost) from user & display it.

import java.sql.*;
import java.util.Scanner;

class BookJDBC {
public static void main(String[] args) throws Exception {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/library", "root",
"password");
Scanner sc = new Scanner(System.in);

System.out.print("Enter Book ID: "); int id = sc.nextInt();


sc.nextLine();
System.out.print("Enter Book Name: "); String name = sc.nextLine();
System.out.print("Enter Book Cost: "); float cost = sc.nextFloat();

PreparedStatement pst = con.prepareStatement("INSERT INTO books VALUES (?, ?, ?)");


pst.setInt(1, id); pst.setString(2, name); pst.setFloat(3, cost); pst.executeUpdate();

ResultSet rs = con.createStatement().executeQuery("SELECT * FROM books");


while (rs.next()) System.out.println(rs.getInt(1) + " " + rs.getString(2) + " " + rs.getFloat(3));
sc.close(); con.close(); } }
c) Write a JSP program to accept a number from user and convert it into
words (eg 123 – o/p  One Two Three).
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-
8859-1"%>
<%@ page import="java.util.*" %>
<html>
<head>
<title>Number to Words</title>
</head>
<body>
<form method="post">
Enter Number: <input type="text" name="num">
<input type="submit" value="Convert">
</form>
<%
String num = request.getParameter("num");
if (num != null && !num.isEmpty()) {
String[] words = {"Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight",
"Nine"};
out.print("Number in Words: ");
for (char c : num.toCharArray()) {
out.print(words[Character.getNumericValue(c)] + " ");
}
}
%>
</body>
</html>
b) Write a java program in multithreading to display all the alphabets between
‘A’ to ‘Z’. Each alphabet should display after two seconds.

class AlphabetThread extends Thread {


public void run() {
try {
for (char ch = 'A'; ch <= 'Z'; ch++) {
System.out.println(ch);
Thread.sleep(2000);
}
} catch (Exception e) {}
}
public static void main(String[] args) { new AlphabetThread().start(); }
}

c) Write a JSP script to check whether given number is perfect or not &
display the result in yellow colour.
<%@ page language="java" %>
<html>
<body style="background-color:yellow;">
<form method="post">Enter a Number: <input type="text" name="num">
<input type="submit" value="Check"></form>

<%
String numStr = request.getParameter("num");
if (numStr != null) {
int num = Integer.parseInt(numStr), sum = 0;
for (int i = 1; i < num; i++) if (num % i == 0) sum += i;
out.println("<h2>" + num + (sum == num ? " is" : " is NOT") + " a Perfect Number</h2>");
}
%>
</body>
</html>
a) Write a java program to accept N integer from user store them into suitable
collection and display only even integers.

import java.util.*;

class EvenNumbers {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Integer> numbers = new ArrayList<>();

System.out.print("Enter N: ");
int N = sc.nextInt();

System.out.println("Enter " + N + " numbers:");


for (int i = 0; i < N; i++) numbers.add(sc.nextInt());

System.out.println("Even Numbers:");
numbers.stream().filter(n -> n % 2 == 0).forEach(System.out::println);

sc.close();
}
}

b) Write a Java program to accept details of teacher (Tid, Tname, Tsubject),


store it into database and display it.

import java.sql.*;
import java.util.Scanner;

class TeacherJDBC {
public static void main(String[] args) throws Exception {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/school", "root",
"password");
Scanner sc = new Scanner(System.in);

System.out.print("ID: "); int id = sc.nextInt();


sc.nextLine();
System.out.print("Name: "); String name = sc.nextLine();
System.out.print("Subject: "); String subject = sc.nextLine();

con.prepareStatement("INSERT INTO teacher VALUES (" + id + ", '" + name + "', '" + subject
+ "')").executeUpdate();

ResultSet rs = con.createStatement().executeQuery("SELECT * FROM teacher");


while (rs.next()) System.out.println(rs.getInt(1) + " " + rs.getString(2) + " " + rs.getString(3));

sc.close(); con.close();
}
}
c) Write a JSP program to accept user name and greets the user according
to time of system.
<%@ page language="java" %>
<html>
<body>
<form method="post">
Name: <input type="text" name="user">
<input type="submit" value="Greet">
</form>
<%
String user = request.getParameter("user");
if (user != null) {
int hour = new java.util.Date().getHours();
String greet = (hour < 12) ? "Good Morning" : (hour < 18) ? "Good Afternoon" : "Good
Evening";
out.println("<h2>" + greet + ", " + user + "!</h2>");
}
%>
</body>
</html>
b) Write a java program in multithreading to display all the numbers between
1 to 10. Each number should display after 2 seconds.

class NumberThread extends Thread {


public void run() {
try {
for (int i = 1; i <= 10; i++) {
System.out.println(i);
Thread.sleep(2000);
}
} catch (Exception e) {}
}
public static void main(String[] args) { new NumberThread().start(); }
}
a) Write a jdbc program to accept details of student (RN, Name, percentage)
from user. Display that details.

import java.sql.*;
import java.util.Scanner;

class StudentJDBC {
public static void main(String[] args) throws Exception {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/college",
"root", "password");
Scanner sc = new Scanner(System.in);

System.out.print("Roll No: "); int rn = sc.nextInt();


sc.nextLine();
System.out.print("Name: "); String name = sc.nextLine();
System.out.print("Percentage: "); float perc = sc.nextFloat();

con.createStatement().executeUpdate("INSERT INTO student VALUES (" + rn + ", '" + name


+ "', " + perc + ")");

ResultSet rs = con.createStatement().executeQuery("SELECT * FROM student");


while (rs.next()) System.out.println(rs.getInt(1) + " " + rs.getString(2) + " " + rs.getFloat(3));

sc.close(); con.close();
}
}
c) Write a jsp script to check the given number is prime or not. Display the
result in blue color.
<%@ page language="java" %>
<html>
<body style="color:blue;">
<form method="post">Enter a Number: <input type="text" name="num">
<input type="submit" value="Check"></form>
<%
String numStr = request.getParameter("num");
if (numStr != null) {
int num = Integer.parseInt(numStr), i, flag = 0;
for (i = 2; i <= num / 2; i++) if (num % i == 0) { flag = 1; break; }
out.println("<h2>" + num + (flag == 0 && num > 1 ? " is" : " is NOT") + " Prime</h2>");
}
%>
</body> </html>
a) Write a java program to accept 'N' student name from user, store them in
Linked list collection and display in reverse order.

import java.util.*;

class ReverseStudents {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
LinkedList<String> students = new LinkedList<>();
System.out.print("Enter N: ");
for (int i = sc.nextInt(); i-- > 0; sc.nextLine()) students.addFirst(sc.nextLine());
students.forEach(System.out::println);
}
}

b) Write a java program to accept details of student (rollno, name,


percentage). Store it into database & display it.
import java.sql.*;
import java.util.Scanner;

class StudentJDBC {
public static void main(String[] args) throws Exception {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/college",
"root", "password");
Scanner sc = new Scanner(System.in);
System.out.print("Roll No: "); int rn = sc.nextInt();
sc.nextLine();
System.out.print("Name: "); String name = sc.nextLine();
System.out.print("Percentage: "); float perc = sc.nextFloat();
con.createStatement().executeUpdate("INSERT INTO student VALUES (" + rn + ", '" + name
+ "', " + perc + ")");
ResultSet rs = con.createStatement().executeQuery("SELECT * FROM student");
while (rs.next()) System.out.println(rs.getInt(1) + " " + rs.getString(2) + " " + rs.getFloat(3));
}
}
c) Write a JSP program to accept username & password, if username &
password is same then display "Login sucessful" message on the browser
other - wise display "Login failed" message.
<%@ page language="java" %>
<form method="post">
Username: <input type="text" name="user">
Password: <input type="password" name="pass">
<input type="submit" value="Login">
</form>

<% if (request.getParameter("user") != null)


out.println("<h2>" + (request.getParameter("user").equals(request.getParameter("pass")) ?
"Login Successful" : "Login Failed") + "</h2>");
%>

Q4
a) Life Cycle of Servlet

The Servlet Life Cycle consists of five stages managed by the Servlet Container:

1. Loading & Instantiation – The servlet class is loaded, and an instance is created.
2. Initialization (init()) – Called only once when the servlet is first loaded.
3. Request Handling (service()) – Handles client requests (doGet(), doPost()).
4. Destruction (destroy()) – Called before removing the servlet from memory.
5. Garbage Collection – The servlet object is removed when not needed.

Servlet Life Cycle Methods

public class MyServlet extends HttpServlet {


public void init() { System.out.println("Servlet Initialized"); }
public void service(HttpServletRequest req, HttpServletResponse res) {
System.out.println("Request Processed"); }
public void destroy() { System.out.println("Servlet Destroyed"); }
}

Diagram Representation:

Loading → init() → service() (multiple times) → destroy() → Garbage Collection


b) Java Program using Multi-Threading to Blink Text on Frame

This program makes text blink using Threads in a GUI Frame.

import java.awt.*;
import javax.swing.*;

public class BlinkingText extends JFrame implements Runnable {


JLabel label;
boolean visible = true;

public BlinkingText() {
label = new JLabel("Blinking Text", JLabel.CENTER);
label.setFont(new Font("Arial", Font.BOLD, 30));
add(label);
setSize(300, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
new Thread(this).start();
}

public void run() {


try {
while (true) {
visible = !visible;
label.setVisible(visible);
Thread.sleep(500);
}
} catch (InterruptedException e) {}
}

public static void main(String[] args) {


new BlinkingText();
}
}

Explanation:

1. JFrame is used to create a GUI window.


2. A JLabel displays the text.
3. A Thread toggles the label's visibility every 500 milliseconds to create a blinking effect.
c) JDBC Process with an Example

JDBC (Java Database Connectivity) Process:

JDBC allows Java programs to connect to a database and perform operations like inserting,
updating, and retrieving data.

JDBC Steps:

1. Load the Driver – Class.forName("com.mysql.cj.jdbc.Driver");


2. Establish Connection – DriverManager.getConnection()
3. Create Statement – Statement stmt = con.createStatement();
4. Execute Query – stmt.executeQuery("SELECT * FROM Employee");
5. Process Results – Using ResultSet
6. Close Connection – con.close();

JDBC Example Program:

import java.sql.*;

public class JDBCExample {


public static void main(String[] args) {
try {
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/yourDB", "root", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM Employee");

while (rs.next()) {
System.out.println(rs.getInt(1) + " " + rs.getString(2) + " " + rs.getDouble(3));
}
con.close();
} catch (Exception e) {
System.out.println(e);
}
}
}

Explanation:

1. Loads JDBC Driver to connect Java with MySQL.


2. Connects to Database using DriverManager.getConnection().
3. Executes SQL Query using executeQuery().
4. Displays Employee Data from the database.
5. Closes Connection after execution.
OOP’S_CH_2 : Objects and Classes
• Java is an object-oriented programming language. Objects and classes are the basic building blocks of OOP.
• An object is a basic unit of OOP and represents the real life entities like a house, a tree
• Classes create objects and objects use methods to communicate between them.
Object in Java:
• An object is A real-world entity that has state and behaviour.
Class in Java:
• A class is a user-defined type which groups data members.
• In Java language the data members are called fields and the functions are called methods.
CONSTRUCTORS :

• A constructor is a special method of a class in Java programming that initializes an object.


• Constructors have the same name as the class itself. A constructor is automatically called when an object is
created.
• Constructors can be classified into two types, default constructors and parametarized constructors.
Default Constructor:
• The constructor which does not accept any argument is called default constructor.
M
• In other word, when the object is created Java creates a no-argument constructor automatically known as
default constructor.
• It does not contain any parameters nor does it contain any statements in its body.
Parameterized Constructor:
• A constructor that has parameters is known as parameterized constructor.
• Parameterized constructor is used to provide different values to the distinct objects.
r.
CONSTRUCTOR OVERLOADING :
• Constructor having the same name with different parameter list is called as constructor overloading.
USE OF 'this' KEYWORD :
• 'this' keyword can be used to refer current class instance variable.
• 'this' keyword can be used to invoke current class constructor.
• The ‘this’ is used inside the method or constructor to refer its own object
R
STATIC BLOCK, STATIC FIELDS AND METHODS :
• In Java basically, class contains variables called instance variables and methods called instance method.
Static Block :
• A class can contain code in a static block that does not exist within a method body. Static code block
executes only once when the class is loaded.
oh
• A static block is used to initialize static attributes. Static blocks are also called static initialization blocks.
• A static initialization block is a normal block of code enclosed in braces, { }, and preceded by the static
keyword. static {
//whatever code is needed for initialization goes here, …
}
• A class can have any number of static initialization blocks, and they can appear anywhere in the class
it
body.
Static Field :
• A static field of a class is referred as a class variable .
• A static field gets memory only once for the whole class.
• To declare a static field It's syntax is, static datatype fieldName;
Static Methods :
• If you apply static keyword with any method, it is known as static method.
• A static method belongs to the class.
• Static method can access static data member and can change the value of it.
• A static method is also called class method as it is associated with a class and not with individual instance
of the class.
• A static method cannot access non-static method.
Object Class :
• The object class is the parent class of all the classes in Java by default. In other words, it is the topmost class of
java.
• The Object class provides some common behaviours to all the objects such as object can be compared, object can
be cloned, object can be notified etc.
• Some methods of the object class are:
Boolean equals(Object obj) , protected Object clone() , int hashCode() , void notify(). void notifyAll() .
String Class :
• The strings in Java are treated as objects of type 'String' class. This class is present in the package java.lang.
• This package contains two string classes String class and StringBuffer class.
• The string class is used when we work with the string which cannot change whereas StringBuffer class is used
when we want to manipulate the contents of the string.
• When we create object of String Class they are designed to be immutable.
• We can use + operator to overload for string objects. Only two operators i.e. '+' & '+=" are overloaded for string
classes.
Example: String str = "Kal" + "pa" + "na";
Output: Kalpana
M
StringBuffer Class :
• It is a peer class which provides the functionality of strings. The string generally represents fixed length,
immutable character sequence whereas StringBuffer represents growable and writeable character sequences.
• StringBuffer may have some characters
• Java generally manipulate the strings using + as overloaded operator. StringBuffer class in Java is used to created
mutable (modifiable) string.
r.
• The StringBuffer class in Java is same as String class except it is mutable i.e., it can be changed.
Advantages of StringBuffer Class: 1. Alternative to String class. 2. Can be used wherever a string is used. 3. More
flexible than String.
Difference between String and StringBuffer:
• String objects are constants and immutable whereas StringBuffer objects are not constants and immutable.
• StringBuffer Class supports growable and modifiable string whereas String class supports constant strings.
R
• Strings once created we cannot modify them Whereas StingBuffer objects after creation also can be able to
delete or append any characteres to it.
• String values are resolved at run time whereas StringBuffer values are resolved at compile time.
WRAPPER CLASSES :
• A data type is to be converted into an object and then added to a Stack. For this conversion, the introduced
oh
wrapper classes.
PACKAGES :
• A Java package is a mechanism for organizing Java classes.
• A package can be defined as "a group of similar types of classes, interface, enumeration and sub-packages".
• Packages are collection of classes and interface or packages act as container for classes.
• There are two types of packages:
it
1. Built-in Package: Existing built-in Java packages like java.lang, java.util, java.sql etc.
2. User-define Package: Java package created by user to categorized classes, interface and enumeration.
Creating Packages :
• simply include a package command as the first statement in a Java source file.
• package pkg_name;
• There are three ways to access the package from outside the package.
•Using packagename:
• If we use package.* then all the classes and interfaces of this package will be accessible but not
subpackages. • The ‘import’ keyword is used to make the classes and interface of another package
accessible to the current package.
• Using packagename.classname:
• If we import package.classname then only declared class of this package will be accessible.
User Defined Packages :
• The packages credited by user are called as user defined package.
• User defined packages generally represent programs data.
it
oh
R
r.
M
OOP’s_ch_4 :User Interface with AWT and Swing
• Every user interface considers the following three main aspects: UI elements, Layouts, Behavior.
• The Abstract Window Toolkit (AWT) is Java's original platform-dependent windowing, graphics, and user-
interface widget toolkit.
• The AWT is part of theJava Foundation Classes (JFC) .
What is AWT? :
• The Java programming language class library provides a user interface toolkit called the Abstract Window
Toolkit, or the AWT.
•Java AWT is an API to develop GUI or window-based application in Java.
• Java AWT components are platform-dependent.
• The AWT is now part of the Java Foundation Classes (JFC) is the standard API for providing a Graphical
User Interface (GUI) for a Java program.
• The AWT classes are contained in the java.awt package. It is one of Java’s largest packages.
What is Swing? :
• Swing is a GUI widget toolkit for Java.
• It is part of Oracle's Java Foundation Classes (JFC)- is the API for providing a Graphical User Interface (GUI)
for Java programs.
• The swing components are defined in the package javax.swing. This package provides more powerful and
Mr

flexible components
• Swing is a Java foundation classes, library and it is has extension to do Abstract Window Toolkit (AWT).
• Various features of swing are:
Light Weight, Rich Controls, Borders, Easy mouseless Operation, Tooltips, Easy Scrolling, Highly
.R

Customizable,

Sr. No. AWT Swing


1. AWT components are platform dependent. Java swing components are platformindependent.
oh

2. AWT components are heavy weight. Swing components are light weight.
3. AWT doesn't support pluggable look and feel. Swing supports pluggable look and feel.

4. AWT provides less components than Swing. Swing provides more powerful com-
it

ponents such as tables, lists, scrollpanes, colorchooser,


tabbedpane etc.
5. AWT components require java.awt package. Swing components require javax.swing package.

6. Advanced features is not available in AWT. Swing has many advanced features like JTabel, Jtabbed
pane which is not available in AWT.
7. Different looked feel feature is not supported in AWT. We can have different look and feel in Swing.

8. Using AWT, we have to implement a lot of things ourself. Swing has them built in.

LAYOUTS AND LAYOUT MANAGERS :


• Layout means the arrangement of components within the container.
• In other way we can say that placing the components at a particular position within the container.
• Layout manager is an object which determines the way that components are arranged in a frame window.
• A layout manager automatically arranges our controls within a window by using some type of algorithm.
• A layout manager is an instance of any class that implements the LayoutManager interface.
• The layout manager is set by the setLayout() method.
• Each layout manager keeps track of a list of components that are stored by their names
• The layout manager automatically positions all the components within the container.
• A check box is a control that is used to turn an option on (true) or off (false). It consists of a small box that can
either contain a check mark or not.
• Listclass provides a list of items, which can be scrolled. From list of items, single or multiple items can be selected.
•A menu bar displays a list of top-level menu choices. Each choice is associated with a dropdown menu.
• The JButton class is used to create a push buttons.
• A toggle button is two states button that allows user to switch on and off. To create a toggle button in Swing we
use JToggleButton class
• The JTextField component allows us to enter/edit a single line of text.
• The JTextArea is used to accept several lines of text from the user and it has capabilities not found in the AWT
class.
• Swing provides a combo box (a combination of a text field and a dropdown list) through the JComboBox class,
which extends JComponent. A combobox normally displays one entry.
• A dialog is defined as a conversation between two or more persons. In a computer application a dialog is a
window which is used to "talk" to the application.
• Message dialogs are simple dialogs that provide information to the user.
• File chooser dialog box is used for navigating the file system.
• The class JColorChooser provides a pane of controls designed to allow a user to manipulate and select a color.
EVENT HANDLING :
Mr

• Changing the state of an object is known as an even.


• The java.awt.event package provides many event classes and Listener interfaces for event handling.
• Each event must return a Boolean value (true or false).
•An Event is an object that describes a state change in a source.
.R

•Event handling is a process of responding to events that can occur at any time during execution of a
program.
ADAPTERS :
• Adapter pattern is frequently used in modern Java frameworks.
• Adapter pattern works as a bridge between two incompatible interfaces.
oh

• This pattern involves a single class which is responsible to join functionalities.


ANONYMOUS INNER CLASSES :
• Anonymous classes of Java are called anonymous because they have no name.
• A class that have no name is known as anonymous inner class in Java.
it

•An anonymous class is a local class without a name.


OOP’S_CH_3 :Inheritance and Interface
• Inheritance can be defined as, the process where one class acquires the properties of another. With the use of inheritance
the information is made manageable in a hierarchical order
INHERITANCE :
• Inheritance can be defined as, “the process where one object acquires the properties of another class.
• Inheritance represents the 'IS-A relationship', also known as 'parent-child relationship'.
•In simple words, the mechanism of deriving a new class from an old class is called inheritance.
• A class that is derived from any another class is called a subclass or derivedclass or extendedclass or childclass.
•The class from which a subclass is derived is called superclass or baseclass or parentclass.
• The keyword ‘extends’ is used to inherit the properties of a class through another class.
• The keyword extends indicates that, we are making a new class that derives from an existing class.
Types of Inheritance :
• Single Inheritance:
• When a class extends another one class only then we call it a single inheritance.
• In case of single inheritance there is only a sub class and it's parent class. It is also called simple inheritance
or one level inheritance.
• Multilevel Inheritance:
M
• We can create any layers in the inheritance as we want, this is called Multilevel Inheritance.
• When a subclass is derived from a derived class then this mechanism is known as the Multilevel inheritance.
• The derived class is called the subclass or child class.
Use of 'super' Keyword :
• The 'super' keyword is used by subclass to refer its immediate superclass.
•There are two different forms of using super:
r.
1. 'super' calls the superclass constructor.
2. 'super' can access members of the superclass those have been hidden by members of a subclass.
method overriding :
• If the same method is defined in both the superclass and the subclass, then the method of the subclass class
overrides the method of the superclass. This is known as method overriding.
• If subclass (child class) has the same method as declared in the parent class, it is known as method overriding
R
• Method overriding is an example of runtime polymorphism
Runtime polymorphism :
• Runtime polymorphism is a process in which a call to an overridden method is resolved at runtime rather than
compile-time.
oh
• Method overriding is an example of runtime polymorphism.
USAGE OF 'final' KEYWORD :
• The "final" is a keyword in Java which generally means, cannot be changed once created.
• The final variables cannot be modified, The final method cannot be overridden. , The final class cannot be inherited
or extended.
Abstraction :
• Abstraction is a process of hiding the implementation details and showing only functionality to the user.
it
• The methods which have only declaration and no method body in the base class are called abstract method.
• The abstract methods are declared using the keyword "abstract".
INTERFACE :
• An interface in Java is a blueprint of a class. It has static constants and abstract methods only.
• A class can implement more than one interface. In Java, an interface is not.
• Interfaces can also have more than one method.

Marker Interface:
• An interface that does not contain methods, fields, and constants is known as marker interface .
Functional Interface:
• An interface that contains exactly one abstract method is known as functional interface.

You might also like