You are on page 1of 65

Department of Artificial Intelligence & Data Science

Subject: Object Oriented Programming with Java


Experiment No. 1

Name: Yatish Patil Roll No:20 Date: 09/09/2021

Aim: Write a program on Basic Programming constructs like branching and looping.
1. A] Write a program to check if a number is even or odd and also to find the sum of the
individual digits of the same number.
1.B] Write a program to generate Fibonacci Series upto 10 numbers.

Objective: To apply basic programming constructs like Branching and Looping for solving
arithmetic problems.

Software Used: JDK version -16.0.2

Theory:
1. A)Branching- It also called decision-making statements they evaluate the Boolean
expression and control the program flow depending upon the result of the condition
provided.
B)Looping- It is a sequence of instruction s that is continually repeated until a certain
condition is reached.
2. The branching statements allow us to make a decision to which a block of statements
will be executes or not is depend on the Boolean expression true or false, whereas the
Looping statements are used to do some statements repeatedly util given condion is
true.

3. Types of Branching statements (write two line explanation for each type)
a. Simple if-To specify a block of code to be executed, if a specified condition is true.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 1
b. If...Else-The Java if-else statement also tests the condition. It executes the if block if
condition is true otherwise else block is executed.

c. Nested If...Else-If an “if statement” is declared inside another if, or if-else


statement, it is called nested if statement in Java. The inner if statement can also
have another if statement .
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 1

d. The Else If ladder-The if-else-if ladder statement executes one condition from
multiple statements.

e. The Switch Statement-The switch statement to select one of many code blocks to
be executed.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 1

2. Types of Looping Statements:


a. While-The while loop loops through a block of code as long as a specified
condition is true.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 1

b. Do … while-The do/while loop is a variant of the while loop. This loop will
execute the code block once, before checking if the condition is true, then it will
repeat the loop as long as the condition is true.

c. For loop-We can initialize the variable, check condition and increment/decrement
value.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 1

d. Nested For loop-If we have a for loop inside the another loop, it is known as
nested for loop. The inner loop executes completely whenever outer loop
executes.
i. Syntax
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 1
Algorithm:
Algorithm of Program 1:

STEP 1: START
STEP 2: Take input as number
STEP 3: Read number as N
STEP 4: Check if : N%2 == 0 then
output N is an Even number.
Else output N is a ODD number.
STEP 5: Store the modulus of N in any variable
STEP 6: Sum the remainder
STEP 7: Divide N with 10
STEP 8: Repeat STEP 2 while N>0
STEP 9: Output total sum of the remainder
STEP 10: EXIT

Algorithm for Program 2 :

STEP 1: START
STEP 2: Take input Number from user as N
STEP 3: Put 0 and 1 value in two variables
STEP 4: Subtract 2 form N
STEP 5: Print 0 and 1
STEP 6: Add 1st and 2nd number, then shift 2nd to 1st and sum to 2nd
STEP 7: repeat STEP 6 for N times
STEP 8: Output the sum
STEP 9: EXIT
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 1

Implementation:
1. Program 1
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 1

2. Output:

3. Program 2
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 1

4. Output:
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 1

Conclusion: The Branching and Looping statements are very essential in many programming
languages. Also there are many programs that they utilize those statements like 1)To find n number
of sum 2)To find largest & smallest number, 3)Pattern printing etc.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 2

Name: Yatish Patil Roll No:20 Date: 16/09/2021

Aim: Program on accepting input through keyboard.


Write a program to implement a calculator using Switch case by taking input from the user by
using Scanner class or BufferedReader class

Objective: To use the facility of java to read data from the keyboard for any program.

Software: JDK version-16.0.2

Theory:
1. Scanner class -The Java Scanner class is used to collect user input. Scanner is part of the
java.util package, so it can be imported without downloading any external libraries.
Scanner reads text from standard input and returns it to a program.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 2

2. BufferedReader class – Java BufferedReader class is used to read the text from a
character-based input stream. It can be used to read data line by line by readLine()
method.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 2

Implementation:
1. Program

2. Output with each case in the switch statement.


Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 2

Conclusion: When we are comparing multiples possible coonditons of an expression and


expression itself is non-trivial.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 3

Name: Yatish Patil Roll No: 20 Date: : 23/09/2021

Aim: To implement a program on Classes and Objects


Write a program to create two classes - a class ‘Student’ with variables s_name, r_no,
marks_obtained, total_marks and percent, which have default method-compute(), return type
method- calculate() and parameterised method - cal(). Each method should calculate the
percentage obtained by the students. Create 5 objects of class ‘Student’ in another class which
contains the main method and use one object for the default method, two objects for return type
method and two objects for parameterised methods.

Objective:To apply the concept of class and object to solve a real life problem like calculating
percentage of students.

Software Used: JDK version-16.0.2

Theory:
1. Classes -A class is a user defined blueprint or prototype from which objects are
created. It represents the set of properties or methods that are common to all objects of
one type.
Objects-An object is an instance of a class. A class is a template or blueprint from which
objects are created. So, an object is the instance(result) of a class.
2. Method- A method is a block of code or collection of statements or a set of code grouped
together to perform a certain task or operation.
Types of Methods:
There are two types of methods in Java:

1. Predefined Method

2. User-defined Method
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 3

3. Syntax for defining a class

4. Syntax for defining a object

5. Syntax of all types of method


Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 3

Implementation:
Program :
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 3

Output:

Conclusion: Yes, we can execute a java program without a main method by using a static block.
Static block in Java is a group of statements that gets executed only once when the class is loaded
into the memory by Java ClassLoader, It is also known as a static initialization block. Static
initialization block is going directly into the stack memory.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 4

Name:Yatish Patil Roll No:20 Date: 30/09/2021

Aim: To implement method and constructor overloading.


a) Method Overloading- calculate area of Square, Rectangle, Circle, Triangle,
Trapezoid. Overload the method cal_area to compute the areas respectively.
b) Constructor Overloading- Create a class Student and its constructor, if the student
name and address is not passed as parameter then print student name as unknown
and address as unknown. If the values are passed as parameters then print those
values respectively. Input is to be taken from the user.

Objective: To implement the concept of Method overloading and Constructor Overloading for
calculating area and getting information about the students.

Software Used: JDK version-16.0.2

Theory:
1. Method Overloading-If a class has multiple methods having same name but different in
parameters, it is known as Method Overloading.
2. Constructor Overloading-Constructor overloading in Java is a technique of having more
than one constructor with different parameter lists. They are arranged in a way that each
constructor performs a different task.
3. Method Overloading syntax:

4. Constructor Overloading syntax


Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 4

Implementation:
1. Program
a)Method Overloading:
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 4
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 4

2. Output:
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 4
b)Constructor Overloading:

Program:

Output:
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 4
Conclusion:
Method overloading is a feature of Java in which a class has more than one method of the
same name and their parameters are different .

a) If the programmer has created a method in Java to perform some action, but later as part of the
requirement the programmer wants the same method to act on different parameters, then the coder
can simply use the feature of method overloading in Java. This will allow the programmer to
create the methods of performing similar functions with the same name so that they do not have to
remember the names later.

Constructor overloading in java is a technique of having more than one constructor with different
parameter lists.

a) As construction overloading enables the creation of the object of a specific class in several ways,
it is most commonly used in Java programs based on the requirement of the programmer. With the
use of constructor overloading, objects can be initialized with different data types .
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 5

Name:Yatish Patil Roll No:20 Date: 7/10/2021

Aim: To implement a program on packages.


Create a package ‘pack’ with a method to add three values(int/float/double). Import the
same package in another file and use it to perform addition of the user entered values by
using BufferedReader class. Create a subpackage ‘mypack’ in package ‘pack’ and print
“Hey you are in sub-Package ‘Mypack’ which is contained in package ‘pack’. ”

Objective: To implement the concept of packages and subpackages to perform addition and
printing the statement.

Software Used: JDK version-16.0.2

Theory:
1. Packages-A java package is a group of similar types of classes, interfaces and sub-
packages.
2. Types of Packages-
1.built-in package
2. user-defined package.
3. Syntax for creating User-defined packages:

4. Steps to create Package:


Choose a package name according to the naming convention.

Write the package name at the top of every source file (classes, interface, enumeration, and
annotations).

Remember that there must be only one package statement in each source file.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 5

Implementation:
1.Program
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 5

2.Output:

Conclusion: Java package is used to categorize the classes and interfaces so that they can be
easily maintained. Java package provides access protection. Java package removes naming
collision.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 6

Name:Yatish Patil Roll No:20 Date: 7/10/2021

Aim: To implement 2D array and String functions


a) Implement a program to multiply two matrices of m x n (m and n are user
input values)
b) Implement a program to compute String functions.

Software Used: JDK version -16.0.2

Theory:
1. An array is a data structure, which can store a fixed-size collection of elements of the
same data type. An array is used to store a collection of data, but it is often more useful to
think of an array as a collection of variables of the same type
2. Syntax for creation and declaration of Array
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 6

3. Strings in Java are Objects that are backed internally by a char array. Since arrays are
immutable(cannot grow), Strings are immutable as well. Whenever a change to a String
is made, an entirely new String is created. Also string is basically an object that
represents sequence of char values. An array of characters works same as Java string.
4. Syntax for creation and declaration of String
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 6
Implementation:
1. Program
a)
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 6
2.Output
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 6

b)Program
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 6

Output:

Conclusion:
2D array- The simplest of the multi-dimensional array is a two-dimensional array. A simple
definition of 2D arrays is: A 2D array is an array of one-dimensional arrays .In Java, a two-
dimensional array is stored in the form of rows and columns and is represented in the form of a
matrix.

String Function uses: String f are used in computer programming languages to manipulate
a string or query information about a string (some do both).
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 7

Name:Yatish Patil Roll No:20 Date: 14/10/2021

Aim: To implement program on StringBuffer and Vector


a) Implement a program by applying append(), insert(), replace(), delete(),
reverse() and capacity() methods of StringBuffer by taking appropriate
Strings wherever required.
b) Implement a program by applying any 6 java Vector methods.

Software Used: JDK version -16.0.2

Theory:
1. Java StringBuffer class is used to create mutable (modifiable) String objects. The
StringBuffer class in Java is the same as String class except it is mutable i.e. it can be
changed.
2. StringBuffer Methods : apppend(), insert(), replace(), delete(), reverse(), capacity(),
length(), charAt(), etc.
3. Vector is like the dynamic array which can grow or shrink its size. Unlike array, we
can store n-number of elements in it as there is no size limit. It is a part of Java Collection
framework since Java 1.2. It is found in the java.util package and implements the List
interface, so we can use all the methods of List interface here.
4. Vector Methods: add(), contains(), isEmpty(), remove(), removeElement(), size(),
get(), delete(), capacity(), clear(), etc.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 7

Implementation:
1. Program 1

2. Output 1
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 7

3. Program 2

4. Output 2
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 7
Conclusion: The significant performance difference between String & StringBuffer classes is that
StringBuffer is faster than String when performing simple concatenations. In String manipulation
code, character strings are routinely concatenated. Like an array, vector contains components that
can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed
to accommodate adding and removing items after the Vector has been created. Thus, both of them
have an upper edge over String and array, hence they’re useful in development
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 8

Name:Yatish Patil Roll No:20 Date: 14/10/2021

Aim: To implement types of inheritance.


a. Create a class Rectangle which extends only one class Shape to calculate the
area of Rectangle. Define data fields - length and breadth in class Shape() and
method compute_area() in class Rectangle.
b. Create a class Electronic → Television→ SmartTV which shows Multilevel
Inheritance to print Specifications of the same.

Software Used: JDK version -16.0.2

Theory:
1. Inheritance is the procedure in which one class inherits the attributes and methods of
another class. The class whose properties and methods are inherited is known as the
Parent class.
2. Syntax for single-level inheritance and multilevel-inheritance
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 8
Implementation:
1. Program
a)

Output
a)
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 8
1.Program
b)

Output
b)
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 8
Conclusion: When a class extends a class, which extends anther class then this is called multilevel
inheritance. For example class C extends class B and class B extends class A then this type of
inheritance is known as multilevel inheritance. Thus, we achieved multilevel inheritance.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 9

Name:Yatish Patil Roll No:20 Date: 28/10/2021

Aim: To implement multiple inheritance.


Create class Student which is extended by class Test and class Test is extended by class
Result. Class Result also implements interface Sports. Class Student has data member
-variable roll no, methods getNumber(r_no) and displayNumber(). Class Test has
getMarks(m1, m2) & displayMarks(). Interface Sports has variable sport_Weightage
and displayWt(). Class Result displays all the required Information.

Software Used: JDK version -16.0.2

Theory:
1. Interfaces -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.
2. Use of Interfaces-There are mainly three reasons to use interface. They are given below.

1.It is used to achieve abstraction.

2.By interface, we can support the functionality of multiple inheritance.

3.It can be used to achieve loose coupling.

3. Syntax for creating Interface-


Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 9

Implementation:
1. Program

2.Output
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 9

Conclusion: It is the mechanism in java by which one class is allowed to inherit the
features(fields and methods) of another class. Like a class, an interface can have methods and
variables, but the methods declared in an interface are by default abstract (only method
signature, no body).
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 10

Name:Yatish Patil Roll No:20 Date: 28/10/21

Aim: To implement a program with multiple catch blocks to demonstrate exception


handling

Software Used: JDK version -16.0.2

Theory:
1. Errors and Exception – In java, both Errors and Exceptions are the subclasses of
java.lang.Throwable class. Error refers to an illegal operation performed by the user which
results in the abnormal working of the program. Programming errors often remain undetected
until the program is compiled or executed. Some of the errors inhibit the program from
getting compiled or executed. Thus errors should be removed before compiling and
executing. It is of three types: Compile-time ,Run-time, Logical Whereas exceptions in java
refer to an unwanted or unexpected event, which occurs during the execution of a program i.e
at run time, that disrupts the normal flow of the program’s instructions
2. 2.Try-catch block and Multiple catch block syntax
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 10

Implementation:
1. Program

2. Output
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 10
Conclusion: Multiple catch block
A try block can be followed by one or more catch blocks. Each catch block must contain a different
exception handler. So, if you have to perform different tasks at the occurrence of different
exceptions, use java multi-catch block.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 11

Name:Yatish Patil Roll No:20 Date: 11/11/21

Aim: To implement a program on User defined Exception.


Implement a program to display User Defined Exception while validating a person’s
eligibility for Voting.

Software Used: JDK version -16.0.2

Theory:
1. User Defined Exceptions-User Defined Exception or custom exception is creating your
own exception class and throws that exception using ‘throw’ keyword. This can be done
by extending the class Exception. There is no need to override any of the above methods
available in the Exception class, in your derived class .

Implementation:
1. Program
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 11
2. Output

Conclusion: In the given program “MyExpception” is the User-Defined exception. The Catch
block is assigned to catch this exception. In simple word in the program it gives a condition is its
true then, it throws the user-defined exception i.e. MyException.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 12

Name:Yatish Patil Roll No:20 Date: 18/11/21

Aim: To implement a program on Multithreading.


Implement a program by applying methods of a thread using extends and and a thread using
implements keyword.

Software Used: JDK version -16.0.2

Theory:

1. Multithreading in Java is a process of executing multiple threads simultaneously.A thread


is a lightweight sub-process, the smallest unit of processing. Multiprocessing and
multithreading, both are used to achieve multitasking.
2. Ways of creating Thread:
There are two ways to create a thread:
i. By extending Thread class
ii. By implementing Runnable interface.

3. Life Cycle of Thread:


In Java, a thread always exists in any one of the following states.These states are:
i. New
ii. Active
iii. Blocked / Waiting
iv. Timed Waiting
v. Terminated
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 12
4. Syntax of thread creation

5. Methods used in thread


i. public void run(): is used to perform action for a thread.
ii. public void start(): starts the execution of the thread.JVM calls the run()
method on the thread.
iii. public void sleep(long miliseconds): Causes the currently executing
thread to sleep (temporarily cease execution) for the specified number of
milliseconds.
iv. public void join(): waits for a thread to die.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 12
Implementation:
1. Program
a)

Output
a)
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 12
b) Program

Output
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 12
Conclusion: In this Programs we have used public void run() Method which is used to
perform action for a thread.

Starting a thread:

The start() method of Thread class is used to start a newly created thread.

It performs the following tasks: of India | List of Prime Minister of India (1947-2020)

i. A new thread starts(with new callstack).


ii. The thread moves from New state to the Runnable state.
iii. When the thread gets a chance to execute, its target run() method will run.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 13

Name:Yatish Patil Roll No:20 Date: 25/11/2021

Aim: To implement a program on Graphics Class.


Implement a program to draw a Smiley Face on Applet using Graphics Class by making use
of various methods.

Software Used: JDK version 1.7.0_80

Theory:
1. Applet is a special type of program that is embedded in the webpage to generate the
dynamic content. It runs inside the browser and works at client side.
2. public void paint(Graphics g): is used to paint the Applet. It provides Graphics class
object that can be used for drawing oval, rectangle, arc etc
3. Syntax of Commonly used and implemented methods
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 13
Implementation:
1. Program

2. Output
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 13

Conclusion: Graphics class provides many methods to draw or fill different shapes, some of
those are drawString(), drawRect(), drawArc(), drawLine(), fillRect(), fillArc(), etc.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 14

Name:Yatish Patil Roll No:20 Date: 25/11/21

Aim: To implement a program on applet class.


Implement a Program to display “Hey! It's my First Applet Program”, which has
Background and Foreground colors used.

Software Used: JDK version 1.7.0_80

Theory:
1. Applet Life Cycle-
The applet life cycle can be defined as the process of how the object is created, started,
stopped, and destroyed during the entire execution of its application.

Methods of Applet Life Cycle


i. public void init(): is used to initialized the Applet. It is invoked only once.
ii. public void start(): is invoked after the init() method or browser is
maximized. It is used to start the Applet.
iii. public void stop(): is used to stop the Applet. It is invoked when Applet is
stop or browser is minimized.
iv. public void destroy(): is used to destroy the Applet. It is invoked only
once.
2. Two ways of Executing Applet-
There are two standard ways in which you can run an applet :
1. Executing the applet within a Java-compatible web browser.
2. Using an applet viewer, such as the standard tool, applet-viewer. An applet viewer
executes your applet in a window. This is generally the fastest and easiest way to
test your applet .
3. Appletviewer tool-You use the appletviewer command to launch the AppletViewer and
run applets outside of a web browser. Although available and supported in JDK 7,
theApplet API is marked as deprecated in preparation for removal in a future release.
Instead of applets, consider alternatives such as Java Web Start or self-contained
applications.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 14
Implementation:
1. Program

HTML CODE-
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 14

2. Output

Conclusion: In this program we successfully implemented Applet. Applet can be implemented


using “Applet” class present in th java.applet paclage. It can be be executed using appletviewer
which is done by using an html file.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 15

Name:Yatish Patil Roll No:20 Date: 2/12/21

Aim: To implement a program to create GUI Application


Implement a Program to create a login page using components of java Swing.(use at
least 6 distinct components and 1 listener.)

Software Used: JDK version -16.0.2

Theory:
1. Introduction Java Swing-Java Swing is a part of Java Foundation Classes (JFC) that
is used to create window-based applications. It is built on the top of AWT (Abstract
Windowing Toolkit) API and entirely written in java.
2. Various components in java Swing- Unlike AWT, Java Swing provides platform-
independent and lightweight components. The javax.swing package provides classes for
java swing API such as Jbutton , JTextField, JTextArea, JRadioButton, JCheckbox,
JMenu, JColorChooser etc.
i. Jbutton- JButton class is used to create a push-button on the UI. The
button can contain some display text or image. It generates an event
when clicked and double-clicked. A JButton can be implemented in the
application by calling one of its constructors. Ii.
ii. Jlabel- JLabel class is used to render a read-only text label or images on
the UI. It does not generate any event.
iii. JTextField JTextField renders an editable single-line text box. A user can
input non-formatted text in the box. To initialize the text field, call its
constructor and pass an optional integer parameter to it. This parameter
sets the width of the box measured by the number of columns. It does not
limit the number of characters that can be input in the box.
iv. JTextArea JTextArea class renders a multi-line text box. Similar to the
JTextField, a user can input non-formatted text in the field. The
constructor for JTextArea also expects two integer parameters which
define the height and width of the text-area in columns. It does not restrict
the number of characters that the user can input in the text-area.
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 15

Implementation:
1. Program
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 15

2. Output
Department of Artificial Intelligence & Data Science
Subject: Object Oriented Programming with Java
Experiment No. 15

Conclusion: The page created takes information. The object of JLabel class is used to display
read only text like “ Name”. The JTextFeild class is used to take input from the user. Checkboxes
are created using JCheckBox class which helps the user to select one or many alternatives from
either male or female . Button is created using Jbutton to submit the informaton. The display of
textfield is due to the implementation of ActionListener.

You might also like