0% found this document useful (0 votes)
2 views

advjava

The document outlines various experiments focused on Java programming, covering core platforms like Java SE, EE, ME, and FX, as well as Integrated Development Environments (IDEs) such as Eclipse and IntelliJ IDEA. It includes practical steps for installing Eclipse, creating Java projects, and demonstrates concepts like multi-threading, applets, JavaBeans, socket programming, and servlet cookies. Each section provides an overview, key features, use cases, and sample code to illustrate the concepts discussed.

Uploaded by

photocopyieg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

advjava

The document outlines various experiments focused on Java programming, covering core platforms like Java SE, EE, ME, and FX, as well as Integrated Development Environments (IDEs) such as Eclipse and IntelliJ IDEA. It includes practical steps for installing Eclipse, creating Java projects, and demonstrates concepts like multi-threading, applets, JavaBeans, socket programming, and servlet cookies. Each section provides an overview, key features, use cases, and sample code to illustrate the concepts discussed.

Uploaded by

photocopyieg
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

1

EXPERIMENT-1
Aim:- To study the core platforms of Java, including Java SE, Java EE, Java ME, and Java FX,
and their respective use cases.

Introduction:
Java is a versatile programming language that provides several platforms tailored for different types of
applications. The core platforms of Java include:
(1) Java Platform, Standard Edition (Java SE)
(2) Java Platform, Enterprise Edition (Java EE)
(3) Java Platform, Micro Edition (Java ME)
(4) Java FX

Java Platform, Standard Edition (Java SE)


Overview: Java SE is the core platform for developing and running Java applications. It provides the basic
libraries and tools necessary for building desktop applications, applets, and server-side applications.
Key Features:
(i) Core Libraries: Includes essential libraries for data structures, networking, I/O operations, and more.
(ii) Java Development Kit (JDK): A complete toolkit for developing Java applications, including the Java
Runtime Environment (JRE), compiler, and other tools.
(iii) Java Virtual Machine (JVM): Allows Java applications to run on any device that has the JVM installed.
2

Use Cases:
(i) Desktop applications
(ii) Command-line tools
(iii) Basic server-side applications

Java Platform, Enterprise Edition (Java EE)


Overview: Java EE is an extension of Java SE that provides a set of specifications for enterprise features such as
distributed computing and web services. It is designed for building large-scale, multi-tiered, scalable, and secure
applications.

Key Features:
(i) Enterprise JavaBeans (EJB): For building scalable and transactional enterprise applications.
(ii) Java Servlets and JavaServer Pages (JSP): For creating dynamic web content.
(iii) Java Persistence API (JPA): For managing relational data in enterprise applications.
Use Cases:
(i) Large-scale enterprise applications
(ii) Web applications
(iii) Microservices architecture

Java Platform, Micro Edition (Java ME)


Overview: Java ME is a platform designed for developing applications for resource-constrained devices such as
mobile phones, embedded systems, and IoT devices. It provides a subset of Java SE features tailored for small
devices.
3

Key Features:
(i) Configuration and Profiles: Provides a set of APIs for different types of devices (e.g., CLDC for mobile
devices, MIDP for mobile information devices).
(ii) Lightweight Libraries: Optimized for performance and memory usage on small devices.
Use Cases:
(i) Mobile applications
(ii) Embedded systems
(iii) IoT applications

Java FX
Overview: Java FX is a platform for building rich internet applications (RIAs) with a modern user interface. It
provides a set of graphics and media packages that enable developers to design, create, and deploy visually rich
applications.
4

Key Features:
(i) FXML: An XML-based language for defining user interfaces.
(ii) Scene Graph: A hierarchical tree of nodes that represent all visual elements in a Java FX application.
(iii) CSS Styling: Allows developers to style Java FX applications using CSS.
Use Cases:
(i) Desktop applications with rich user interfaces
(ii) Web applications with interactive features
(iii) Mobile applications

Conclusion:
All Java platforms consist of a Java virtual machine (VM) and an application programming interface (API). The
Java virtual machine is a program, for a particular hardware and software platform, that runs Java technology
applications. An API is a collection of software, the components that you can use to create other software
components or applications. This allows applications written for that platform to run any system compatible
with all the advantages of Java programming language: platform-independence, power, stability, ease of
development and security.
5

EXPERIMENT-2
Aim:- To study the various Integrated Development Environments (IDEs) used for Java
development, their features, and their use cases.

Introduction to IDEs
An Integrated Development Environment (IDE) is a software application that provides comprehensive facilities
to computer programmers for software development. An IDE typically consists of:
(i) A source code editor
(ii) Build automation tools
(iii) A debugger
(iv) A compiler or interpreter
For Java development, several popular IDEs are widely used, including:
(1) Eclipse
(2) IntelliJ IDEA
(3) NetBeans
(4) BlueJ
(5) JDeveloper

Eclipse
Overview: Eclipse is a popular open-source IDE for Java development. It is highly extensible and supports
various programming languages through plugins.
Key Features:
(i) Code completion and syntax highlighting
(ii) Integrated debugging tools
(iii) Plugin support for additional functionalities
(iv) Version control integration (Git, SVN)
Use Cases:
a) Java application development
b) Web development with Java EE
c) Android development (with additional plugins)

IntelliJ IDEA
Overview: IntelliJ IDEA is a powerful IDE developed by JetBrains. It is known for its intelligent code
assistance and ergonomic design. It comes in two editions: Community (free) and Ultimate (paid).
Key Features:
(i) Smart code completion and suggestions
6

(ii) Built-in support for version control systems


(iii) Integrated terminal and database tools
Use Cases:
a) Java application development
b) Web development with Spring and other frameworks
c) Android development

NetBeans
Overview: NetBeans is an open-source IDE that provides a robust environment for Java development. It is
known for its simplicity and ease of use, making it suitable for beginners.
Key Features:
(i) Easy project management
(ii) Built-in support for Java EE and JavaFX
(iii) Code templates and snippets
(iv) Integrated profiler and debugger
Use Cases:
a) Java SE and Java EE application development
b) Web application development
c) JavaFX application development

BlueJ
Overview: BlueJ is an educational IDE designed for teaching Java to beginners. It has a simple interface and is
ideal for small projects.
Key Features:
(i) Interactive object creation
(ii) Simple and intuitive interface
(iii) Built-in support for testing and debugging
(iv) Visualization of class structures
Use Cases:
a) Learning Java programming
b) Small projects and prototypes
c) Educational purposes
7

JDeveloper
Overview: JDeveloper is an IDE from Oracle that provides a comprehensive development environment for
Java, especially for enterprise applications.
Key Features:
(i) Integrated support for Oracle ADF
(ii) Visual development tools
(iii) Built-in database integration
Use Cases:
a) Enterprise application development
b) Web services and cloud applications
c) Database-driven applications

Conclusion:
Each IDE offers unique strengths and weaknesses. Eclipse stands out for its extensive plugin support, IntelliJ
IDEA is ideal for professional developers with its advanced features, BlueJ is perfect for beginners due to its
simplicity, NetBeans provides a versatile environment with modular design, and JDeveloper integrates well
with Oracle products and offers robust development tools.
8

EXPERIMENT-3
Aim:- To install the Eclipse Integrated Development Environment (IDE) for Java development.

Downloading Eclipse
Step 1: Open your browser and type https://www.eclipse.org/

Step 2: Click on “Download” button.


Step 3: Click on “Download 64 bit” button.

Step 4: Click on “Download” button.


9

Installing Eclipse
Step 1: Click on “downloads” in Windows file explorer.
Step 2: Click on “eclipse-inst-win64.exe” file.

Step 3: Click on Run button. You will be prompted to choose which “flavor” of Eclipse you want:

Step 4: Click on “Eclipse IDE for Java Developers”.


10

Launching Eclipse
Click on “LAUNCH” button.
11

EXPERIMENT-4

Aim:- Demonstrate how to create, compile, and run a simple Java program using the Eclipse
Integrated Development Environment (IDE).

Requirements:
Eclipse IDE installed on your computer.
Java Development Kit (JDK) installed and configured.

Create a Java Project


Step 1: To create a new Java project in Eclipse, go to File > New > JavaProject.

Step 2: The New Java Project wizard dialog appears to let you specify configurations for the project. Select the
Java Project option in it.

Step 3: After that, you will see the below screen. Enter the project name. After that, click the Finish button.
12

Gurvansh

Create a Java Package


Step 1: Right-click on the project option, and select New > Package from the context menu like this:
13

Step 2: In the New Java Package dialog, enter the name of your package.

Create a Java Class


Step 1: Right-click on the package and select New > Class from the context menu.
Step 2: The New Java Class dialog appears, type the name of the class and choose the option to generate the
main () method.
14

Write the Java Code


In the editor window that opens, you will see a template for your class. Modify it and write a program that you
want to run.

Save the File


Click on File > Save or press Ctrl + S to save your changes.

Run the Java Program


Step 1: Right-click on the HelloWorld.java file in the Package Explorer.
Step 2: Select Run As > Java Application.
Alternatively, you can click the green "Run" button (a play icon) in the toolbar.

View the Output


The output of your program will appear in the Console view at the bottom of the Eclipse window.

Gurvansh
15

EXPERIMENT-5

Aim:- To demonstrate the concept of multi-threading in Java by creating a simple program that
runs multiple threads concurrently.

What is Multi-threading?
Multi-threading is a programming concept that allows multiple threads to run concurrently within a single
program. A thread is the smallest unit of processing that can be scheduled by an operating system. Multi-
threading enables a program to perform multiple tasks simultaneously, improving the efficiency and
performance of applications, especially in environments where tasks can be executed independently.

Importance of Multi-Threading
Improved Performance: By utilizing multiple threads, a program can perform tasks in parallel, leading to faster
execution times, especially on multi-core processors.
Resource Sharing: Threads within the same process share resources such as memory, which makes context
switching between threads more efficient than switching between processes.
Responsiveness: In user interface applications, multi-threading can keep the application responsive by
performing background tasks (like loading data) without freezing the user interface.
Simplified Program Structure: Multi-threading can simplify the design of programs that require concurrent
operations, such as server applications that handle multiple client requests simultaneously.

Java and Multi-Threading


Java provides built-in support for multi-threading through the Thread class and the Runnable interface.
Developers can create threads by either extending the Thread class or implementing the Runnable interface.
Java's threading model is designed to be simple and easy to use, allowing developers to create and manage
threads with minimal effort.

Program Overview
In this experiment, we will demonstrate multi-threading in Java by creating a simple program that utilizes two
threads. Each thread will print a count from 0 to 4, simulating a task that takes some time to complete. The
program will showcase how threads can run concurrently, allowing for interleaved output from both threads.
Creating Threads: create a custom thread class by extending the Thread class.
Starting Threads: to start threads using the start () method.
Thread Execution: threads execute independently and concurrently.
16

Program Code: -

Program Output: -
17

EXPERIMENT-6

Aim:- To demonstrate the concept of applet by creating a simple program.

What is an Applet?
An applet is a small Java program that runs inside a web browser or an applet viewer. It was primarily used for
embedding Java programs in web pages. However, due to security issues and the deprecation of the Applet API
in Java 9 and its complete removal in Java 11, applets are no longer supported in modern browsers and IDEs
like Eclipse.

Why Use Swing Instead?


Since applets are not supported in Eclipse and modern browsers, we can use Java Swing to create a similar
graphical user interface (GUI) application. Swing is a part of Java's standard library and provides a rich set of
GUI components that can be used to create desktop applications.
Create a simple Swing application that mimics the behavior of an applet by displaying a message in a window.
The application will demonstrate basic GUI components such as a frame and a label.

Swing-Based Applet Alternative


Instead of using an applet, we use Swing components like:
- JFrame (acts as the main window),
- JPanel (container for UI components),
- JButton, JLabel, etc.
By following this approach, create a standalone GUI application that mimics an applet's behavior but works in
modern Java versions and Eclipse.

Explanation of the Code:


Imports: The program imports necessary classes from the javax.swing and java.awt packages.
Class Declaration: The MyExample class extends JFrame, which is the main window for our application.
Constructor: In the constructor, we set the title, layout, and create a label to display "Hello, World!".
Main Method: The main method creates an instance of the MyExample class, which displays the window.
Adding Components: JLabel displays a message, and JButton interacts with the user.
Handling Events: The JButton uses an ActionListener to show a dialog box when clicked.
Main Method Execution: The GUI is created inside SwingUtilities.invokeLater() to ensure thread safety.
18

Program Code with output window.


19

EXPERIMENT-7

Aim:- To demonstrate the use of JAVA bean by creating a simple program.

What is a JavaBean?
A JavaBean is a reusable software component in Java that follows specific conventions. It allows for
encapsulation and component reusability in Java applications. JavaBeans are often used in GUI applications,
enterprise applications, and frameworks like Spring.

Key Features of a JavaBean


1. Encapsulation – All fields are private with public getter and setter methods.
2. Public No-Arg Constructor – A JavaBean must have a public default constructor.
3. Serializable – Implements the Serializable interface for object persistence.
4. Getter and Setter Methods – Follows standard naming conventions (getPropertyName() and
setPropertyName(value)).

Java Program: Demonstrating JavaBean in Eclipse


Step 1: Create the JavaBean (StudentBean.java): - stores student details like name and age.
20

Step 2: Create a Class to Use the Bean (TestBean.java)

Output:-
When you run TestBean.java, you will get:

Gurvansh Singh
22
21

EXPERIMENT-8

Aim:- Write a java socket program.

What is Socket Programming?


Socket programming allows communication between two programs running on different devices or the same
system over a network. Java provides the java.net package to facilitate client-server communication using
sockets.
Sockets are important for computer networking. These are regarded as the endpoints of the communication line.
Two sockets must be created at both the server and client ends to connect two machines. The ServerSocket class
of the Java computer language controls the server end of the socket, whereas the Server class controls the client
end. The client must understand the characteristics of the IP address and port number to connect to the server.
After submitting a request, the client must wait for the server to authorize it. The server approves the request
using the accept() function.
22

Java Socket Program (Client-Server Communication in Eclipse)


Implement a simple chat application where:
-The server listens for messages.
-The client sends messages.

Step 1: Create the Server (ServerProgram.java):

Gurvansh
23

Step 2: Create the Client (ClientProgram.java):

Gurvansh
24

Example Interaction

Server Console:

Client Console:

Gurvansh
25

EXPERIMENT-9

Aim:- Write a java program to set the cookies information using Servlet.

What Are Cookies?


A cookie is a small piece of data stored on the client’s browser by a web server. It helps maintain state between
multiple client-server interactions, such as storing user preferences, login sessions, or tracking information.

How Do Servlets Use Cookies?


In Java Servlets, cookies can be created, modified, and deleted using the javax.servlet.http.Cookie class. The
HttpServletResponse object is used to add cookies to the response, while the HttpServletRequest object is used
to retrieve cookies sent by the client.

Useful methods of Cookie class


javax.servlet.http.Cookie class provides the functionality of using Cookies. Below are given some commonly
used methods of the Cookie class:
public void setMaxAge(int expiry): Sets the maximum age of the Cookie in seconds.
public String getName(): Returns the name of the Cookie and the name cannot be changed after creation.
public String getValue(): Returns the value of the Cookie
public void setName(String name): Changes the name of the Cookie.
public void setValue(String value): Changes the value of the Cookie.
26

Program -
Step 1: Create a Dynamic Web Project.
Step 2: Create the Servlets
1. Create Page1 Servlet
Purpose: To display a form for user input (name and email).
Code-

The doGet method generates an HTML form that allows to enter their name and email address. When the user
submits the form, it sends a POST request to Page2.
Output -
27

2. Page2 Servlet
This servlet processes the data submitted from Page1, creates cookies for the name and email, and then redirects
the user to Page3. Two cookies are created: one for the name (Cname) and one for the email (Cemail). Both
cookies are set to expire in one hour (3600 seconds). After setting the cookies, the servlet redirects the user to
Page3 using response.sendRedirect("Page3").
Code-

3. Page3 Servlet
This servlet retrieves the cookies set by Page2 and displays their names and values to the user. The doGet
method retrieves all cookies from the request using request.getCookies().
It iterates through the cookies and prints their names and values in an HTML format.
28

Code-

Step 3: Run the Project


- Select Run As -> Run on Server.
- Choose your server (e.g., Apache Tomcat) and click Finish.
29

Output -
30

Gurvansh Singh
gurvanshs

Gurvansh
gurvanshs
31

EXPERIMENT-10

Aim:- Write a java program to show the use of validation using Servlet.

Introduction
Web applications often require user input, and it is crucial to validate this input to ensure data integrity and
security. Validation can be performed on both the client side (using JavaScript) and the server side (using Java
Servlets). In this experiment, we will focus on server-side validation using Jakarta Servlets.

Overview of the Code


The experiment consists of two main components:
1. An HTML form for user input.
2. A Jakarta Servlet that processes the form submission and performs validation.

Step 1: HTML Form


The HTML form is designed to collect the user's name and email address. It uses the POST method to submit
the data to the servlet.

Step 2: Jakarta Servlet


The servlet processes the form data submitted by the user. It performs validation checks on the input fields and
returns appropriate messages based on the validation results.
32
33

Explanation of the Servlet Code


Servlet Annotation:The @WebServlet("/ValidationServlet") annotation maps the servlet to the specified URL
pattern. When the form is submitted, the request is directed to this servlet.
doPost Method:This method handles POST requests. It retrieves the form data using request.getParameter() and
performs validation.

Validation Logic
Name Validation: Checks if the name is empty or consists only of whitespace. If it is, an error message is
appended to the validationMessage.
Email Validation: Checks if the email is empty and validates the format using a regular expression. If the email
does not match the expected pattern, an error message is added.
Response Handling: If there are validation errors, the servlet sends an HTML response containing the error
messages and a link to go back to the form. If there are no validation errors, the servlet sends a welcome
message along with the user's name and email.

Testcase 1: - Successful Submission

Gurvansh

gurvanshs

Gurvansh

gurvanshs
34

Testcase 2: - Name Validation

Testcase 3: - Email Validation

--------- END OF PRACTICAL FILE ---------

You might also like