Advanced Java File PDF
Advanced Java File PDF
What is Java?
Java is a programming language and a platform. Java is a high level, robust, object-oriented
and secure programming language. Java was developed by Sun Microsystems (which is now
the subsidiary of Oracle) in the year 1995. James Gosling is known as the father of Java.
Before Java, its name was Oak. Since Oak was already a registered company, so James
Gosling and his team changed the name from Oak to Java.
Java SE serves as the foundation for all Java platforms, providing the core functionality of the
Java programming language. It encompasses a comprehensive set of APIs (Application
Programming Interfaces), libraries, and tools that developers leverage to create a wide range
of applications, from simple desktop utilities to complex enterprise systems.
At its core, Java SE defines the fundamental constructs of the Java language, including data
types, control flow statements, and object-oriented programming features such as classes,
interfaces, and inheritance. These language features enable developers to write code that is
readable, maintainable, and scalable.
In addition to language features, Java SE includes a rich collection of standard libraries that
provide functionality for common tasks such as input/output operations, networking, file
handling, concurrency, and collections manipulation. These libraries abstract away low-level
details and provide high-level APIs that simplify development and improve productivity.
Java SE also includes a robust runtime environment, known as the Java Virtual Machine
(JVM), which enables Java applications to run on any platform that supports Java. The JVM
provides features such as memory management, garbage collection, and bytecode
interpretation, ensuring that Java programs execute efficiently and reliably across different
operating systems and hardware architectures.
One of the key strengths of Java SE is its platform independence. Java programs are compiled
into platform-independent bytecode, which can be executed on any device that has a
compatible JVM installed. This "write once, run anywhere" capability has made Java SE a
popular choice for developing cross-platform applications.
Page|1
Java SE finds widespread use in various domains, including desktop application
development, web development, server-side programming, and scientific computing.
Developers use Java SE to build graphical user interfaces (GUIs), web servers, middleware
components, database applications, and more.
Servlets and JSPs are used for developing web applications, providing a framework for
handling HTTP requests, generating dynamic web content, and managing user sessions. EJBs
(Enterprise JavaBeans) are components that encapsulate business logic and provide services
such as transaction management, security, and concurrency control.
JPA (Java Persistence API) is a framework for interacting with relational databases, allowing
developers to map Java objects to database tables and perform database operations using
object-oriented programming techniques. JMS (Java Message Service) provides a standard
API for building messaging applications, enabling communication between distributed
components using message queues and topics.
Java EE also includes features for security, such as authentication, authorization, and
encryption, to ensure the confidentiality, integrity, and availability of enterprise applications.
It provides mechanisms for managing user identities, securing communication channels, and
enforcing access control policies.
Another important aspect of Java EE is its support for scalability and high availability. It
offers features such as clustering, load balancing, and failover, allowing applications to scale
horizontally across multiple servers and handle large volumes of traffic with minimal
downtime.
Overall, Java EE provides a comprehensive platform for building robust, scalable, and secure
enterprise applications. Its rich set of APIs, specifications, and runtime environments enable
developers to tackle the challenges of enterprise computing and deliver high-quality software
solutions that meet the needs of modern businesses.
Page|2
provides a lightweight runtime environment and a set of APIs optimized for small-footprint
devices with limited processing power, memory, and storage.
Java ME applications are typically deployed on devices with constrained resources, where
traditional Java SE or Java EE environments may be impractical due to their higher resource
requirements. Java ME applications are often written in Java but may also include native
code components for improved performance or access to device-specific features.
One of the key features of Java ME is its support for device diversity. It provides a set of
APIs that abstract away the differences between different types of devices, allowing
developers to write code that can run on a wide range of hardware platforms without
modification. This enables the development of cross-platform applications that can reach a
larger audience of users.
Java ME includes APIs for user interface development, networking, sensor data processing,
and device interaction, enabling developers to create a variety of applications, including
mobile games, utilities, and IoT applications. It also includes features for security, such as
sandboxing and code signing, to protect against malicious code execution and unauthorized
access to device resources.
Java ME applications are typically packaged as MIDlets (Mobile Information Device Profile
applications) and deployed to devices using over-the-air provisioning or side-loading. Once
installed, MIDlets run within the Java ME runtime environment, which provides features
such as memory management, garbage collection, and bytecode interpretation.
4. JavaFX:
JavaFX is a platform for building rich client applications with modern user interfaces and
advanced multimedia capabilities. It provides a set of high-level APIs for creating interactive
graphics, animations, and media content, making it ideal for developing applications with a
visually appealing and engaging user experience.
JavaFX applications can run on desktop computers, mobile devices, and web browsers,
thanks to its cross-platform support and integration with Java SE and Java EE. JavaFX
leverages hardware-accelerated graphics and media engines to deliver high-performance
rendering of graphical and multimedia content, enabling developers to create applications
with smooth animations, responsive user interfaces, and immersive visual effects.
One of the key features of JavaFX is its support for modern UI design paradigms, such as
CSS styling, FXML for declarative UI layout, and scene graph-based rendering. This allows
developers to create visually rich and expressive user interfaces that are consistent with
modern design trends and user expectations.
JavaFX includes a comprehensive set of APIs for creating UI components, handling user
input, managing application state, and integrating with backend services and data sources. It
provides support for standard UI controls, such as buttons, text fields, and lists, as well as
advanced features like charts, tables, and 3D graphics. JavaFX applications can be deployed
as standalone executables, web applications, or applets, making them accessible to users
across different platforms and environments. JavaFX applications can also be packaged and
distributed using standard Java deployment mechanisms, such as JAR files and Java Web
Start.
Page|3
EXPERIMENT-2
Compiler: A compiler interprets human-readable code into machine-specific code that can
be executed on different operating systems like Linux, Windows, or Mac OS. Most
IDEs usually come with built-in compilers for the language it supports.
Debugger: A tool that can assist developers to test and debug their applications and
graphically point out the locations of bugs or errors if any.
Build-in Terminal: Terminal is a text-based interface that can be used for interacting with
the machine’s operating system. Developers can directly run the scripts or commands within
an IDE with a built-in terminal/console.
Version Control: Version control helps bring clarity to the development of the
software. Some IDEs also support version control tools like Git, through which a user can
track and manage the changes to the software code.
Code snippets: IDEs support code snippets that are usually used to accomplish a single task
and can also reduce redundant work to some great extent.
Extensions and Plugins: Extensions and Plugins are used to extend the functionality of the
IDEs with respect to specific programming languages.
Code navigation: IDEs come with tools like code folding, class and method navigation, and
refactoring tools that make it simple to go through and analyse code.
Page|4
Types Of Java IDEs
Standard IDEs:
Standard Integrated Development Environments (IDEs) like Eclipse, IntelliJ IDEA, and
NetBeans are robust platforms that offer a comprehensive suite of tools for Java
development. Eclipse, for instance, boasts a powerful code editor with features like syntax
highlighting, code completion, and refactoring tools, enhancing developers' productivity and
code quality. It integrates seamlessly with various build systems and version control tools,
facilitating collaborative software development. Similarly, IntelliJ IDEA provides intelligent
code assistance, advanced debugging capabilities, and seamless integration with popular
frameworks and libraries, streamlining the development process. NetBeans offers a user-
friendly interface with a wide range of plugins and extensions, catering to diverse
development needs. Standard IDEs are favoured by professional developers and enterprises
for their extensive feature sets, flexibility, and support for complex projects.
Lightweight IDEs:
Lightweight IDEs, such as JDeveloper, BlueJ, and JCreator, offer a simpler and more focused
approach to Java development. These IDEs are designed to be lightweight in terms of
resource consumption while still providing essential features for coding, compiling, and
running Java applications. BlueJ, for example, is specifically tailored for introductory
programming courses, featuring a clean and intuitive interface that helps students grasp
fundamental concepts effectively. JCreator offers a minimalistic yet powerful environment
for Java development, catering to developers who prefer a streamlined workflow. While
lacking the extensive feature sets of standard IDEs, lightweight IDEs excel in simplicity,
speed, and ease of use, making them suitable for small to medium-sized projects or
developers seeking a more minimalist development environment.
Web-based IDEs:
Text Editors:
Text editors like Sublime Text, Atom, and Visual Studio Code offer lightweight yet powerful
environments for editing code. While lacking the extensive feature sets of full-fledged IDEs,
Page|5
text editors excel in simplicity, speed, and customization options. Sublime Text, for example,
provides a clean and minimalist interface with powerful editing capabilities, including multi-
caret editing, syntax highlighting, and plugin support. Atom, developed by GitHub, offers a
modern and customizable interface with built-in Git integration and a vast library of
community-created packages for extending functionality. Visual Studio Code, a highly
popular text editor from Microsoft, combines the simplicity of a text editor with the power
of an IDE, offering features like IntelliSense code completion, debugging, and built-in
terminal support. Text editors are favoured by developers who prefer lightweight tools,
minimal distractions, and flexibility in configuring their development environment. They are
widely used across various programming languages and platforms for tasks ranging from
quick code edits to full-scale software development projects.
Educational IDEs:
Page|6
EXPERIMENT-3
Page|7
directly from the IDE. It provides features like commit, merge, and branch management,
streamlining the version control process.
6. Plugin Ecosystem: Eclipse boasts a vast ecosystem of plugins and extensions that extend
its functionality beyond the core features. These plugins cover a wide range of areas,
including additional language support, framework integration, code analysis, and more,
allowing developers to customize Eclipse to suit their specific needs.
Page|8
Eclipse Workbench
Eclipse Workspace
Eclipse Runtime
Eclipse Workspace is a directory where we can store project files, source and other project
artifacts. We need to choose an Eclipse workspace to begin Eclipse workbench.
Eclipse Workbench
Eclipse Workbench is the desktop development environment for developing and building
applications. Workbench window contains Eclipse perspectives.
Eclipse Perspective
An Eclipse perspective contains several views, menus, toolbars and editors suitable for a
specific purpose. For example, Java perspective is designed to support Java standalone
applications. Java EE perspective is designed to develop enterprise Java applications. Some
examples of Eclipse perspectives:
Java perspective
Java EE perspective
Debug
Hibernate
Git
JBoss
SpotBugs
Page|9
EXPERIMENT-4
Step 1: In the first step, Open your browser and navigate to this URL.
Step 4: Then click on the “Download” button. After clicking on the download button the
.exe file for the eclipse will be downloaded.
P a g e | 10
Step 5: Now go to File Explorer and click on “Downloads” after that click on
the “eclipse-inst-jre-win64.exe” file for installing Eclipse IDE.
P a g e | 11
Step 7: Then, click on the “Install” button.
Now, you are ready to make new Java projects using eclipse IDE and the screen will
look like this :
P a g e | 12
P a g e | 13
EXPERIMENT- 5
Program:
import java.lang.*;
class FirstThread extends Thread
{
public void run()
{
for(int i=0; i<4; i++)
{
try
{
if(i == 3)
{
sleep(4000);
}
}
catch(Exception x)
{}
System.out.println(i);
}
System.out.println(" First Thread Finished ");
}
}
class SecondThread extends Thread
{
public void run()
{
for(int i=0; i<4; i++)
{
System.out.println(i);
}
System.out.println(" Second Thread Finished ");
P a g e | 14
}
}
class ThirdThread extends Thread
{
public void run()
{
for(int i=0; i<4; i++)
{
System.out.println(i);
}
System.out.println(" Third Thread Finished ");
}
}
class MultiThread
{
public static void main(String arg[])
{
FirstThread a1 = new FirstThread(); SecondThread
b1 = new SecondThread(); ThirdThread c1 = new
ThirdThread(); a1.start();
b1.start();
c1.start();
}
}
OUTPUT:
P a g e | 15
EXPERIMENT – 6
Program:
OUTPUT:
P a g e | 16
EXPERIMENT – 7
Program:
//Employee.java
package mypack;
public class Employee implements java.io.Serializable{
private int id;
private String name;
public Employee(){}
public void setId(int id){this.id=id;}
public int getId(){return id;}
public void setName(String name){this.name=name;}
public String getName(){return name;}
}
//tester.java
package mypack;
public class tester{
public static void main(String args[]){
Employee e=new Employee();//object is created
e.setName("Arjun");//setting value to the object
System.out.println(e.getName());
}}
OUTPUT:
P a g e | 17
EXPERIMENT – 8
AIM: Write a Java socket program where the client sends a text & the server
receives it & prints it.
Program:
//MyServer.java
import java.io.*;
import java.net.*;
public class MyServer {
public static void main(String[] args){
try{
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();//establishes connection
DataInputStream dis=new DataInputStream(s.getInputStream());
String str=(String)dis.readUTF();
System.out.println("message= "+str);
ss.close();
}catch(Exception e){System.out.println(e);}
}
}
//MyClient.java
import java.io.*;
import java.net.*;
public class MyClient {
public static void main(String[] args) {
try{
Socket s=new Socket("localhost",6666);
DataOutputStream dout=new DataOutputStream(s.getOutputStream()); P a g e | 18
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
}catch(Exception e){System.out.println(e);}
}}
OUTPUT:
P a g e | 19
EXPERIMENT – 9
PROGRAM:
index.html
P a g e | 20
Servlet1.java
P a g e | 21
Servlet2.java
P a g e | 22
OUTPUT:
P a g e | 23
EXPERIMENT – 10
PROGRAM:
newindex.html
validate.java
P a g e | 24
OUTPUT:
P a g e | 25
EXPERIMENT – 11
AIM: Write a Java program to insert data into a table using JSP.
PROGRAM:
insert_form.jsp
InsertServlet.java
P a g e | 26
success.jsp
P a g e | 27
error.jsp
OUTPUT :
P a g e | 28
P a g e | 29
EXPERIMENT – 12
PROGRAM:
form.jsp
LoginServlet.java
P a g e | 30
OUTPUT:
P a g e | 31
P a g e | 32