You are on page 1of 8

INTRODUTION TO ADVANCED JAVA

THE Java programming language has continued to grow both in popularity and scope since its initial release. Java in its current form is the culmination of several years work, dating back to 1991 when it was conceived as a modular and extensible programming language. Java is based on the C and C++ programming languages, but differs from these languages is some important ways. The main difference between C/C++ and Java is that in Java all development is done with objects and classes. This main difference provides distinct advantages for programs written in Java, such as multiple threads of control and dynamic loading. Another advantage to Java is its extensibility. Since the original release of Java, several extensions have been added to the core code, providing greater flexibility and power to applications. These extensions add objects and classes that improve the Java programmers ability to use such features as: Java Swing a component set to create grapical user interfaces with a cross-platform look and feel Java Sound for high-quality 32-channel audio rendering and MIDIcontrolled sound synthesis Java 3D for advanced geometry and 3D spatial sound Java Media Framework for components to play and control time-based media such as audio and video Java Telephony (JTAPI) for computer-telephony applications Java Speech for including speech technology into Java applets and Applications

SOME IMPORTANT TOPICS OF ADVANCE JAVA 1) JSP


Advantages of JSP 1. HTML friendly simple and easy language and tags. 2. Supports Java Code. 3. Supports standard Web site development tools.

Disadvantages of JSP 1. As JSP pages are translated to servlets and compiled, it is difficult to trace errors occurred in JSP pages. 2. JSP pages require double the disk space to hold the JSP page. 3. JSP pages require more time when accessed for the first time as they are to be compiled on the server. A JSP life cycle can be defined as the entire process from its creation till the destruction which is similar to a servlet life cycle with an additional step which is required to compile a JSP into servlet. The following are the paths followed by a JSP

Compilation Initialization Execution Cleanup The four major phases of JSP life cycle are very similar to Servlet Life Cycle and they are as follows:

Fig:1-Life Cycle Of JSP

The Scriptlet:
A scriptlet can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language. Following is the syntax of Scriptlet:
<% code fragment %>

We can write XML equivalent of the above syntax as follows: <jsp:scriptlet> code fragment </jsp:scriptlet> Any text, HTML tags, or JSP elements you write must be outside the scriptlet. Following is the simple and first example for JSP: <html> <head><title>Hello World</title></head> <body> Hello World!<br/> <%

out.println("Your IP address is " + request.getRemoteAddr()); %> </body> </html> This would generate following result:

Fig:2- Output of scriplet

JSP Declarations:
A declaration declares one or more variables or methods that you can use in Java code later in the JSP file. You must declare the variable or method before you use it in the JSP file. Following is the syntax of JSP Declarations: <%! declaration; [ declaration; ]+ ... %> You can write XML equivalent of the above syntax as follows: <jsp:declaration> code fragment </jsp:declaration> Following is the simple example for JSP Declarations: <%! int i = 0; %> <%! int a, b, c; %> <%! Circle a = new Circle(2.0); %>

JSP Expression:
A JSP expression element contains a scripting language expression that is evaluated, converted to a String, and inserted where the expression appears in the JSP file. Because the value of an expression is converted to a String, you can use an expression within a line of text, whether or not it is tagged with HTML, in a JSP file. The expression element can contain any expression that is valid according to the Java Language Specification but you cannot use a semicolon to end an expression. Following is the syntax of JSP Expression: <%= expression %> You can write XML equivalent of the above syntax as follows: <jsp:expression> expression </jsp:expression> Following is the simple example for JSP Expression: <html> <head><title>A Comment Test</title></head> <body> <p> Today's date: <%= (new java.util.Date()).toLocaleString()%> </p> </body> </html> This would generate following result:

Today's date: 11-Sep-2010 21:24:25

JSP Comments:
JSP comment marks text or statements that the JSP container should ignore. A JSP comment is useful when you want to hide or "comment out" part of your JSP page. Following is the syntax of JSP comments: <%-- This is JSP comment --%> Following is the simple example for JSP Comments: <html> <head><title>A Comment Test</title></head> <body> <h2>A Test of Comments</h2> <%-- This comment will not be visible in the page source --%> </body> </html> This would generate following result: A Test of Comments

2) SERVLET
Servlets are an integral part of any J2EE Web application. The key benefits of Using Servlets in our web applications are: a. They are faster than CGI scripts because each CGI script produces an entirely new process that takes a lot of time to execute, whereas a servlet creates only a new thread. b. Servlet API is standard and available easily on the internet (like JSPs)

c. Servlets have the advantages like ease of development & platform independence (likeJava) d. They can access all the J2SE and J2EE APIs e. Can take the full advantage & capabilities of the Java programming langauge As you can see, there are numerous advantages of using the Servlet & JSP technologies. This is exactly why numerous organizations use them as a staple part of their J2EE application development work.

3) SESSION TRACKING
1) simple 2) don't need to send data back to us, browser can participate in this task. 3) size and number of cookies stored are limited. 4) it stored as plain-text in a specific directory, everyone can view and modify them. Personal information is exposed. 5) it won't work if the security level set too high in browser.

DATABASE
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>Developerhelpway.com</TITLE> <META http-equiv=Content-Type content="text/html"> </HEAD> <BODY> <H1>JSP Examples :</H1> <ol> <li><a href="jsp/dataConnection.jsp">DataBase Connection (JDBC) </a></li>

</ol> </BODY></HTML> dataConnection.jsp: <%@ page import ="java.sql.*" %> <% String driverName="com.mysql.jdbc.Driver"; String url="jdbc:mysql://localhost:3306/"; String databaseName="jdbcexamples"; String userName="root"; String password=""; String tableName = "student"; Connection con = null; try{ Class.forName(driverName); con=(Connection) DriverManager.getConnection(url+databaseName, userName, password ); out.println("Connection : "+con); } catch(Exception e){ out.println("Database not connected"); e.printStackTrace(); } %>