Varun
Varun
Chapter-1
Introduction
1. Introduction to java
With the invention of microprocessors, the world is scientifically developed with sophisticated
equipment, system, and devices. Microprocessors are used in computers, television, and fax
machines. Even the handheld devices such as pages, PDAs(Personal Digital Assistant), and cell
phones make use of microprocessors. All these electronic devices are helpful because of their
communication capabilities. With the increasing capabilities and decreasing cost of information
processing and networking technologies, the network is growing rapidly for
transmitting information through electronic systems.
Internet is the network of networks between different types of computers located at different
places to transmit information. Information can reach to any place in the world quickly at a
cheaper rate through the Internet. Thus, the Internet has made the world a global village for
information exchange. The emerging infrastructure of electronic devices and interconnected
computer networks create an environment that presents new challenges to software industries. for
this emerging computing environment, Java process to be a well - suited programming language.
it is found suitable for networked environments involving a great variety of computer
and devices.
There were five primary goals in the creation of the Java language.
• It should be "simple, object-oriented and familiar"
• It should be "robust and secure".
• It should be "architecture-neutral and portable".
• It should execute with "high performance".
• It should be "interpreted, threaded, and dynamic”.
Java does have some drawbacks. Since it has automated garbage collection, it can tend to use
more memory than other similar languages. There are often implementation differences on
different platforms, which have led to Java being described as a "write once, test everywhere"
system. Lastly, since it uses an abstract "virtual machine", a generic Java program doesn't have
access to the Native API's on a system directly. None of these issues are fatal, but it can mean
that Java isn't an appropriate choice for a particular piece of software
Chapter-2
The Java Platform
One thing that distinguished Java from some other languages is its ability to run the same
compiled code across multiple operating systems. In other languages, the source code (code that
is written by the programmer), is compiled by a compiler into an executable file. This file is in
machine language, and is intended for a single operating system/processor combination, so the
programmer would have to recompile the program separately for each new operating system/
processor combination. Java is different in that it does not compile the code directly into machine
language code. Compilation creates byte code out of the source code. Byte code generally looks
something like this:
a7 f4 73 5a 1b 92 7d
When the code is run by the user, it is processed by something called the Java Virtual Machine
(JVM). The JVM is essentially an interpreter for the byte code. It goes through the byte code and
runs it. There are different versions of the JVM that are compatible with each OS and can run the
same code. There is virtually no difference for the end-user, but this makes it a lot easier for
programmers doing software development.
Chapter-3
Check installation and Configuring Variables
• Java might already be installed on your machine. You can test this by opening a console (if you
are using Windows: Win+R, enter cmd and press Enter) and by typing in the following
command java -version.
• If Java is correctly installed, you should see some information about your Java installation. If
the command line returns the information that the program could not be found, you have to
install Java
Note on Editions:-
The JDK comes in three editions.
2. Java Standard Edition (JSE) - This version is the basic platform for Java. The course will
focus on this edition.
Configuring Variables:-
• Before writing code, it is recommended that you set the Path variable on your system so you
can compile your code more easily.
For Macintosh:-
• Apple sets everything up for you. Sit back and relax.
• The only drawback is that because Apple handles development and maintenance of Java on the
Mac, there is usually a delay from the time that a new version is released by Sun and the time
that the new version is released on the Mac. Also, getting the latest version sometimes requires
an operating system upgrade.
Garbage collector:-
• The JVM automatically re-collects the memory which is not referred to by other objects. The
java garbage collector checks all object references and find the objects which can be
automatically released.
• While garage collector releases the programers from the need to explicitly manage memory the
programers still need to ensure that he does not keep unnecessary object references otherwise
the garbage collector cannot release the associated memory. Keeping unneeded object
references are typically called memory leaks.
Class path:-
• The class path defines where the Java compiler and Java runtime look for class files to load.
This instructions can be used in the Java program.
• For example if you want to use an external Java library you have to add this library to your
class path to use it in your program.
Chapter-4
JAVA BASIC TERMS
Basics: Package, Class and Object
It is important to understand the base terminology of Java in terms of packages, classes and
objects. This section gives an overview of these terms.
Packages:
Java groups classes into functional packages.Packages are typically used to group classes into
logical units. For example all graphical views of an application might be placed in the same
package called com.vogella.webapplication.views.
It is common practice to use the reverse domain name of the company as top level package. For
example the company might own the domain, vogella.com and in this example the Java packages
of
this company starts with com.vogella.
Other main reason for the usage of packages is to avoid name collisions of classes. A name
collision occurs if two programmers give the same fully qualified name to a class. The fully
qualified name of a class in Java consists out of the package name followed by a dot (.) and the
class name.
Without packages, a programmer may create a Java class called Test. Another programmer may
create a class with the same name. With the usage of packages you can tell the system which
class to call. For example if the first programmer puts the Test class into package report and the
second programmer puts his class into package xmlreader you can distinguish between these
classes by using the fully qualified name, e.g. xmlreader. Test or report. Test.
Class:
Def.: Template that describes the data and behaviour associated with an instance of that class. In
Java source code a class is defined by the class keyword and must start with a capital letter. The
body of a class is surrounded by {}. The data associated with a class is stored in variables ; the
behaviour associated to a or object is implemented with class methods.
A class is contained in a Java source file with the same name as the class plus the java extension.
Object:
Def.: An object is an instance of a class.The object is the real element which has data and can
perform actions. Each object is created based on class definition.
Chapter-5
VARIABLES AND METHODS
• Variable
Variables allow the Java program to store values during the runtime of the program.
A variable can either be a primitive variable or a reference variable. A primitive variable contains
value while the reference variable contains a reference (pointer) to the object. Hence if you
compare two reference variables, you compare if both point to the same object. To compare
objects use the objectl.equals(object2) method call.
• Instance variable
Instance variable is associated with an instance of the class (also called object). Access works
over these objects.
Instance variables can have any access control and can be marked final or transient. Instance
variables marked as final can not be changed after assigned to a value.
• Local variable
Local (stack) variable declarations cannot have access modifiers.
final is the only modifier available to local variables. This modifier defines that the variable
cannot be changed after first assignment.
Local variables do not get default values, so they must be initialised before use.
• Methods
A method is a block of code with parameters and a return value. It can be called on the object.
Method can be declared with var-args. In this case the method declares a parameter which
accepts from zero to many arguments (syntax: type .. name;) A method can only have one var-
args parameter and this must be the last parameter in the method.
Overwrite of a superclass method: A method must be of the exact same return parameter and the
same arguments. Also the return parameter must be the same. Overload methods: An overloaded
method is a method with the same name, but different arguments. The return type can not be used
to overload a method.
• Constructor
A class contains constructors that are invoked to create objects based on the class definition.
Constructor declarations look like method declarations except that they use the name of the class
and have no return type. A class can have several constructors with different parameters. Each
class must define at least one constructor.
Following is a simple example the constructor.
Chapter-6
INHERITANCE
A class can be derived from another class. In this case this class is called a subclass. Another
common phrase is that a class extends another class.
The class from which the subclass is derived is called a superclass.
Inheritance allows a class to inherit the behaviour and data definitions of another class. The
following codes demonstrates how a class can extend another class. In Java a class can extend a
maximum of one class.
Chapter-7
METHOD AND CONSTRUCTOR OVERLOADING
• Method overloading:-
Method Overloading is a feature that allows a class to have more than one method having the
same name, if their argument lists are different. It is similar to constructor overloading in Java
that allows a class to have
more than one constructor having different argument lists.
To understand method overloading following programme can be use:
• Constructor overloading:-
Like methods, constructors can also be overloaded.
Constructor overloading is a concept of having more than one constructor with different
parameters list, in such a way so that each constructor performs a different task.
Chapter-8
MODIFIERS
There are three access modifiers keywords available in Java. public, protected and private. There
are four access levels: public, protected, default and private. They define how the corresponding
element is visible to other components.If something is declared public, e.g. classes or methods
can be freely created or called by other Java objects. If something is declared private, e.g. a
method, it can only be accessed within the class in which it is declared. protected and default are
similar. A protected class can be accessed from the package and sub-classes outside the package
while a default class can get only accessed via the same package.
The following table describes the visibility:
Public Y Y Y Y
Protected Y Y Y N
No modifier Y Y N N
Private Y N N N
Other Modifier:
• final methods: cannot be overwritten in a subclass
• abstract method: no method body
• synchronised method: threat safe, can be final and have any access control
• native methods: platform dependent code, apply only to methods
• Strictfp: class or method.
Import statements
• Usage of import statements: In Java you have to access a class always via its full-qualified
name, e.g. the package name and the class name. You can add import statements for classes or
Chapter-9
INTERFACE
Interfaces are contracts for what a class can do but they say nothing about the way in which the
class must do it. An interface is a type similar to a class. Like a class an interface defines
methods. An interface can have only abstract methods, no concrete methods are allowed.
Methods defined in interfaces are by default public and abstract - explicit declaration of these
modifiers is optional. Interfaces can have constants which are always implicitly public, static and
final. A class can implement an interface. In this case it must provide concrete implementations
of the interface methods. If you override a method defined by an interface you can also use the
@override annotation.
Chapter 10
JAVA DATABASE CONNECTIVITY
The Java Database Connectivity (JDBC) API is the industry standard for database- independent
connectivity between the Java programming language and a wide range of databases - SQL
databases and other tabular data sources, such as spreadsheets or flat files. The JDBC API
provides a call-level API for SQL-based database access. JDBC technology allows you to use the
Java programming language to exploit "Write Once, Run Anywhere" capabilities for applications
that require access to enterprise data. With a JDBC technology-enabled driver, you can connect
all corporate data even in a heterogeneous environment.
1. JDBC drivers
There are commercial and free drivers available for most relational database servers. These
drivers fall into one of the following types:
Type 1, That calls native code of the locally available ODBC driver.
Type 2, That calls database vendor native library on a client side. This code then talks to database
over network.
Type 3, the pure-java driver that talks with the server-side middleware those then talks to
database.
Type 4, the pure-java driver that uses database native protocol
Statement - the statement is sent to the database server each and every time.
Prepared Statement - the statement is cached and then the execution path is predetermined on
the database server allowing it to be executed multiple times in efficient manner.
Callable Statement - used for executing stored procedure son the Database. Update statements
such as INSERT, UPDATE and DELETE return an update count that indicates how many rows
were affected in the database. These statements do not return any other information. Query
statements return a JDBC row result set. The row result set is used to walk over the result set.
Individual columns in a row are retrieved either by name or by column number. There may be
any number of rows in the result set. The row result set has metadata that describes the names of
the columns and their types. There is an extension to the basic JDBC API in the javax.sql. The
method Class. forName(String) is used to load the JDBC driver class.
• The java.sql package contains classes that help in connecting to a database, sending SQL
statements to the database and processing the query results.
• The Connection Object represents a connection with a database. It can be initialised using the
getConnection() method of the Driver Manager class.
• The setString() method sets the query parameters of the PreparedStatementobject.
• The Prepared Statement object allows you to execute parameterised queries. It can be
initialised using the prepareStatement() method of the Connection object.
• The execute Update () method executes the query statement present in the Prepared Statement
object and returns the number of rows affected by the query.
• The Result Set Metadata interface is used to obtain information about the columns stored in a
Result Set object.
Chapter-11
JAVA SERVER PAGES
Java Server Pages (JSP) is a technology that helps software developers create dynamically
generated web pages based on HTML, XML, or other document types. Released in 1999 by Sun
Microsystems [1], JSP is similar to PHP, but it uses the Java programming language. To deploy
and run Java Server Pages, a compatible web server with a servlet container, such as Apache
Tomcat or Jetty, is required.
Java Server Pages is a technology which permits software developers to create dynamic request
like HTML, XML in order to answer to client request in the net. This technology lets Java code
and definite pre-defined
Procedures to be implemented into static content. The syntax in Java Server Pages includes a
supplementary XML tag which is known s JSP actions.
It is made use to evoke the utility of the built-in functions. Moreover JSP permits to establish and
form the JSP tag libraries which operate as an extension to the standard XML or HTML tags.
These JSP tag libraries give a good technique to widen the potentiality of the Web server by
providing an independent platform's compiler compiles the JSPs into Java Servlets.
A JSP compiler may possibly create a servlet in Java code and it is later compiled by the Java
compiler. It might even directly produce the byte code for the servlet. Java Server Pages can be
examined as a high level abstraction of servlets which is practiced as an extension of the Servlet
2.1 API. Java Server Pages are HTML pages embedded with snippets of Java code. It is an
inverse of a Java Servlet.
JSPs run in two phases
• Translation Phase- In translation phase JSP page is compiled into a servlet called JSP Page
Implementation class.
• Execution Phase- In execution phase the compiled JSP is processed
The Java Server Pages and the Servlets were initially developed at Sun Microsystems. Opening
with version 1.2 of the Java Server Page specification the JSPs have been built under the Java
Community Process. There are quite a few JSP implicit objects that are represented by the JSP
container and it could be mentioned and indicated by the programmers.
Application - Data's are shared by the servlets and Java Server Pages in the application.
Exception - Exceptions are not trapped by the codes in the application.
Chapter-12
SERVLET
Servlets are protocol and platform independent server-side software components, written in Java.
They run inside a Java enabled server or application server, such as the Web Sphere Application
Server. Servlets are loaded and executed within the Java Virtual Machine (JVM) of the Web
server or application server, in much the same way that applets are loaded and executed within
the JVM of the Web client.
Since servlets run inside the servers, however, they do not need a graphical user interface (GUI).
In this sense, servlets are also faceless objects.
Servlets more closely resemble Common Gateway Interface (CGI) scripts or programs than
applets in terms of functionality. AS in CGI programs, servlets can respond to user events from
an HTML request, and then dynamically construct n HTML response that is sent back to the
client.
1) The Java Servlet API
The Java Servlet API is a set of Java classes which define a standard interface between a Web
client and a Web servlet. Client requests are made to the Web server, which then invokes the
servlet to service the request through this interface.
The API is composed of two packages:
javax.servlet
javax.servlet.http
The Servlet interface class is the central abstraction of the JavaServlet API. This class
defines the methods which servlets must implement, including a service O method for the
handling of requests. The Generic Servlet class implements this interface, and defines a
generic, protocol-independent servlet To write an HTTP servlet for use on the Web, we will
use an even More specialised class of Generic Servlet called HttpServlet.HttpServlet
provides additional methods for the processing of HTTP requests such as GET (do Get
method) and POST (do Post method). Although our servlets may implement a service
method, in most cases we will implement the HTTP specific request handling methods of do
get and do Post.
2) Servlet Life Cycle
The life cycle of a servlet can be categorised into four parts:
Loading and Instantiation- The servlet container loads the servlet during startup or when the
first request is made. The loading of the servlet depends on the attribute < load-onstartup> of
Web.Xml file. If the attribute <load-on-startup> has a positive value then the servlet is load with
loading of the container otherwise it load when the first request comes for service. After load in
of the servlet, the container creates the instances of the servlet
Initialisation- After creating the instances, the servlet container calls the init() method and passes
the servlet initialisation parameters to the init() method. The init() must be called by the servlet
container before the servlet can service any request. The initialisation parameters persist until the
servlet is destroyed. The int method is called only once throughout the lite cycle of the servlet.
The servlet will be available for service if it is loaded successfully otherwise the servlet container
unloads the servlet.
Servicing the Request: After successfully completing the initialisation process, the servlet will
be available for service. Servlet creates separate threads for each request. The servlet container
calls the service() method for servicing any request. The service() method determines the kind of
request and calls the appropriate method (doGet() or doPost()) for handling the request and sends
response to the client using the methods of the response object.
Destroying the Servlet- If the servlet is no longer needed for servicing any request, the servlet
container calls the destroy 0 method. Like the init) method this method is also called only once
throughout the life cycle of the servlet. Calling the destroy method indicates to the servlet
container not to sent the any request for service and the servlet releases all the resources
associated with it. Java Virtual Machine claims for the memory associated with the resources for
garbage collection.
Technologies Used
1. Java: The core programming language used for backend logic.
2. JSP (JavaServer Pages): For rendering dynamic web content.
3. JDBC (Java Database Connectivity): For database interactions.
4. Servlets: For handling requests and responses.
5. Bootstrap: For a responsive and visually appealing user interface.
Application Structure
The application consists of several components, each responsible for a specific functionality:
1. Home Page:
◦ Provides a welcome message to the users.
◦ Users can navigate to different sections such as adding a new student or
displaying student details.
2. Add Student Page:
◦ A form where users can input student details like name and marks.
◦ A submit button to save the data to the database.
3. Display Student Page:
◦ Displays a list of all students with their IDs, names, and marks.
◦ Includes options to edit or delete each student record.
4. Edit Student Page:
◦ Allows users to update existing student information.
◦ Similar to the add student form but pre-filled with the selected student's data for
editing.
Database Interaction
The application uses JDBC to interact with the database. The key operations include:
1. Insert: Adding new student records.
2. Update: Modifying existing student records.
3. Delete: Removing student records.
4. Select: Fetching student records to display in the list.
User Interface:-
The application leverages Bootstrap for a clean and responsive design. Key UI components
include:
1. Navigation Bar: Provides links to the home, add student, and display student pages.
2. Forms: For adding and editing student details.
3. Tables: For displaying the list of students with edit and delete options.
Screenshots
1. Home Page:
Conclusion
During the internship, the trainee had the invaluable opportunity to learn and apply a range of
technologies including JSP, JDBC, Servlets, and Java. Through dedicated effort and hands-on
practice, the trainee successfully developed a comprehensive Student Management System. This
project served as a practical application of the theoretical knowledge gained and allowed the
trainee to understand the intricacies of web development using Java technologies.
The Student Management System project involved creating a web-based application that
efficiently manages student information. The trainee was responsible for designing and
implementing various functionalities such as adding, editing, and deleting student records, as
well as displaying the list of students in a user-friendly interface. Utilising JSP for dynamic
content rendering, JDBC for database interactions, and Servlets for request handling, the trainee
demonstrated a solid understanding of full-stack development in a Java environment.
Additionally, the integration of Bootstrap ensured the application was both responsive and
visually appealing.
As a trainee, the individual gained practical experience in key areas such as:
1. Java Programming: Strengthened core Java skills and applied object-oriented principles
in a real-world project.
2. JSP and Servlets: Developed and managed dynamic web content, gaining insights into
server-side scripting and request-response handling.
3. JDBC: Implemented database operations, enhancing understanding of SQL and database
connectivity.
4. Bootstrap: Learned to create responsive web designs, improving user experience and
interface design skills.
This internship provided a solid foundation for the trainee's future career in software
development. The hands-on experience with these technologies not only built technical
proficiency but also fostered problem-solving skills, project management, and an understanding
of the software development lifecycle
References
[1.] www.udemy.com
[2.] Programming in JAVA (Student Learning Booklet of Road Ahead Technology)
[3.] https://www.mindsmapped.com/java-advantages-and-disadvantages/