You are on page 1of 17

INDUSTRIAL TRAINING REPORT

SUBMITTED BY :ABHISHEK GUPTA I.T. IVTH

0803513002

WHAT IS JAVA ?
Java is a programming language originally

developed by Sun Microsystems and released in 1995. Much syntax from C and C++ but has a simpler object model. Architecture neutrality. An Internet language.

FEATURES OF JAVA
Java Is Small and Simple. Java Is Object Oriented. Java is Dynamic. Java is Architecture-Neutral. Java is future proof or rather future

portable. The Java environment is more homogeneous and less complex than .NET.

JAVA FEATURES
Java IDEs are superior in their support for

coding tasks. Features like code refactoring, intention actions, superior code browsing (i.e. Find Usages). Integration with Java from other languages like Perl, PHP or Python is cross platform. Automatic garbage collection.

HISTORY OF JAVA
Java started as a project called "Oak" by James Gosling in June 1991 for use in a set top box

project. The first public implementation was Java 1.0 in 1995. It promised Write Once, Run Anywhere" (WORA). Web browsers soon incorporated the ability to run secure Java "applets" within web pages. Various versions of java have been released from 1.0 to 7.0.

HISTORY OF JAVA
Sun makes most of its Java implementations

available without charge, with revenue being generated by specialized products such as the Java Enterprise System. Sun distinguishes between its (SDK) and (JRE) which is a subset of the SDK, the primary distinction being that in the JRE the compiler is not present. On November 13, 2006, Sun released parts of Java as free/open source software, under the GNU General Public License(GPL). The release of the complete source code under GPL was done in the first half of 2007 .

Types of Java

There are many types of Java programs which run differently: Applet - can be put online (in web browsers). Application - can only be run on the computer, cannot be put online. Servlet - runs on a server and helps to display web pages. Swing application - like an application, but can have a more graphical look.

APIs
Sun has defined three platforms targeting different application environments and

segmented many of its APIs so that they belong to one of the platforms. The platforms are: Java Platform, Micro Edition (Java ME) targeting environments with limited resources, Java Platform, Standard Edition (Java SE) targeting workstation environments, and Java Platform, Enterprise Edition (Java EE) targeting large distributed enterprise or Internet environments.

SERVLETS
A Servlet is an object that receives a request and generates

a response based on that request. The package javax.servlet.http defines HTTP-specific subclasses of the generic servlet elements, including session management objects that track multiple requests and responses between the Web server and a client. To deploy and run, the Apache Tomcat Server may be used. It is an open source servlet container developed by the Apache Software Foundation (ASF). The difference between Servlets and JSP is that Servlets typically embed HTML inside Java code, while JSPs embed Java code in HTML.

Life Cycle of Servlet


The container calls the no-arg constructor. The Web container calls the init() method The init() method is called only once. After initialization, the servlet can service client requests. Each request is serviced in its own separate thread. The Web container calls the service() method of the servlet for every request. The service() method determines the kind of request being made and dispatches it to an appropriate method to handle the request Finally, the Web container calls the destroy() method that takes the servlet out of service. The destroy() method, like init(), is called only once in the lifecycle of a servlet.

Advantages over CGI


When an HTTP request is made, a new process is created for each call of the CGI script. But a servlet is not a separate process. Request to be handled by a servlet is handled by a separate Java thread within the Web server process. Simultaneous CGI request causes the CGI script to be copied and loaded into memory as many times as there are requests. Servlets threads

increase for requests on one class.

Example

HttpServlet is a subclass of GenericServlet, an implementation of the Servlet interface.

import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class HelloWorld extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " + "Transitional//EN\">\n" + "<html>\n" + "<head><title>Hello World</title></head>\n" + "<body>\n" + "<h1>Hello, world!</h1>\n" + "</body></html>"); } }

Introduction to Session Management


Prior Session Management through IP

address. New methodologies :(a)Hidden field :- <INPUT TYPE="hidden" NAME="user"VALUE="Jennifer> (b)URL rewrirting:<A HREF="/orderform.htm?user=Jen">Order </A>

(c) Cookie :- A cookie is information that's stored as a name/value pair and transmitted

from the server to the browser. Cookie user = new Cookie("user","Jennifer"); user.setMaxAge(3600); response.addCookie(user); Drawback:The information stored on the client's browser in a text file . But the main problem is that they can be disabled through a setting in the Web browser.

(d)Session Object : The HttpSession API provides a A session

object for storing information about individual users on the application server. The object is stored on the application server and a unique identifier called a session ID is assigned to it. HttpSession session=request.getSession(true);

The methods you'll use most often and the ones we'll focus

on are: setAttribute(String name, Object value): Binds an object to this session using the name specified. Returns nothing (void). getAttribute(String name): Returns the object bound with the specified name in this session, or null if no object is bound under this name. removeAttribute(String name): Removes the object bound with the specified name from this session. Returns nothing (void). invalidate(): Invalidates this session and unbinds any objects bound to it. Returns nothing (void).

Conclusion
The session examples that we went over in

this article cover the main capabilities of the session API. Learning all of Java's session management features will make your job as a Web developer easier and help you create a better experience for your Web site visitors. Use of servlets is now rare instead of those JSP has taken over the market.

You might also like