advjava
advjava
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
Use Cases:
(i) Desktop applications
(ii) Command-line tools
(iii) Basic server-side 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
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
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/
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:
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.
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
Step 2: In the New Java Package dialog, enter the name of your package.
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.
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
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.
EXPERIMENT-7
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.
Output:-
When you run TestBean.java, you will get:
Gurvansh Singh
22
21
EXPERIMENT-8
Gurvansh
23
Gurvansh
24
Example Interaction
Server Console:
Client Console:
Gurvansh
25
EXPERIMENT-9
Aim:- Write a java program to set the cookies information using Servlet.
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-
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.
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.
Gurvansh
gurvanshs
Gurvansh
gurvanshs
34