P. 1
Java Project Report

Java Project Report

|Views: 960|Likes:
Published by Hemant Kumar

More info:

Published by: Hemant Kumar on Nov 08, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less







Submitted in partial fulfillment for the award of Bachelor Of Technology degree Of the Rajasthan Technical University, Kota

Approved By AICTE & Affiliated to Rajasthan Technical University,Kota SESSION 2011-2012

Submitted to: Mr. Ashok Kumar Gill(Asst.Professor) Miss Jyoti Sharma (Asst.Professor)

Submitted by: Hemant Kumar IT,4th year 08ESMIT021

DEPARTMENT OF INFORMATION TECHNOLOGY ENGG. S.M.E.C , NEEMRANA ALWAR(Raj)-301705 Rajasthan Technical University August, 2011

Department of Information Technology
St. Margaret Engineering College Neemrana, NH-8, Alwar, Rajasthan -301705

This is to certify that the project titled “CORE JAVA(J2SE)” submitted by Mr. Hemant Kumar,08ESMIT021 in partial fulfillment of the course workrequirement for B.Tech Program in the Department of Information Technology, St. Margaret Engineering College, Neemrana, Alwar (Raj.) is a bona fide work carried out by her under my guidance and supervision. This project report has been find quite satisfactory.

Head of Department
Name- Mr. Hawa Singh Kumar Designation- Asst. Professor Department of CS/IT Engg

Project Guide
Name- Mr.Permod Designation-Asst.Professor Department of CS/IT Engg.

Margaret Engineering College Neemrana Neemrana .St. Margaret Engineering College St.

ACKNOWLEDGEMENT I am grateful to St. a lot of difficulties were faced by me. (HEMANT KUMAR) .Ltd. I have learnt a lot. But it was the help of some special people that I have gained much confidence and developed the project quite well. Margaret Engineering College. While developing this project. This will be an un-forgetful experience. for permitting me to undergo for a minor project for the development of an expert system. I would like to thank all the lecturers of Appin Knowledge Solutions Pvt. (Pitampura) to co-ordinate with me and provide me the information needed to complete the analysis part of this project. While developing this project.

CONTENTS Chapter 1: History 1.1 Encapsulation 2.1 Principles Chapter 2: Features of Java 2.2 Java Platform .

The language. providing no-cost runtimes on popular platforms. it allowed network. 1. Sun released the first public implementation as Java 1. J2EE targeted enterprise applications and the greatly stripped-down version J2ME for mobile applications. utility programs. Sun generated revenue from Java through the selling of licenses for specialized products such as the Java Enterprise System. new versions had multiple configurations built for different types of platforms. With the advent of Java 2 (released initially as J2SE 1. For example. Java ME. In 2006. Sun Microsystems approached the ISO/IEC JTC1 standards body and later the Ecma International to formalize Java.2 in December 1998). for marketing purposes. from a list of random words. Sun renamed new J2 versions as Java EE. Sun released much of Java as open source software under the terms of the GNU General Public License (GPL). On 13 November 2006. In 1997. respectively. James Gosling initiated the Java language project in June 1991 for use in one of his many set-top box projects. At one time. Java remains a de facto standard. and Java SE. aside from a small portion of code to which Sun did not hold the copyright. Sun distinguishes between its Software Development Kit (SDK) and Runtime Environment (JRE) (a subset of the SDK). It promised "Write Once. Major web browsers soon incorporated the ability to run Java applets within web pages. Sun made most of its Java implementations available without charge. On 8 May 2007 Sun finished the process. and Java quickly became popular.0 in 1995. Fairly secure and featuring configurable security. but it soon withdrew from the process. making all of Java's core code available under free software / open-source distribution terms. despite their proprietary software status. controlled through the Java Community Process. the Java mascotSee also: Java (Sun) history and Java version history.1 HISTORY Duke. the primary distinction involves the JRE's lack of the compiler. and header files.1What Is the Java Technology? • Java technology is: A programming language A development environment An application environment A deployment environment . initially called Oak after an oak tree that stood outside Gosling's office. Run Anywhere" (WORA). J2SE designated the Standard Edition. also went by the name Green and ended up later renamed as Java. Gosling aimed to implement a virtual machine and a language that had a familiar C/C++ style of notation.and file-access restrictions.

2 PRIMARY GOALS OF THE JAVA TECHNOLOGY • • • • • • • • • • • Provides an easy-to-use language by: Avoiding the pitfalls of other languages Being object-oriented Enabling users to create streamlined and clear code Provides an interpreted environment for: Improved speed of development Code portability Enables users to run more than one thread of activity Loads classes dynamically. similar in semantics to SmallTalk • It is used for developing both applets and applications 1. that is. at the time they are actually needed Supports dynamically changing programs during runtime by loading classes from disparate sources Furnishes better security .• It is similar in syntax to C++.

Even so. some means of generating portable executable code is needed. most users still worried about the possibility of infecting their systems with a virus. PORTABILITY Many types of computers and operating systems are in use throughout the world and many are connected to the Internet. For programs to be dynamically downloaded to all the various types of platforms connected to the Internet. you can safely download Java applets without fear of viral infection or malicious intent. Prior to Java. The object model in Java is simple . Beyond its similarities with C/C++. pragmatic approach to objects. This allowed the Java team the freedom to design with a blank slate. Java has another attribute that makes it easy to learn: it makes an effort not to have surprising features. most users did not download executable programs frequently. which is provided by java. usable. OBJECT-ORIENTED Java was not designed to be source-code compatible with any other language. SECURE Every time that you download a “normal” program. and those who did scanned them for viruses prior to execution. The basic concepts of object-oriented programming .2 FEATURES OF JAVA • • • • • • • • • • • Simple Secure Portable Object-oriented Robust Multithreaded Architecture-neutral Interpreted High performance Distributed Dynamic SIMPLE Java was designed to be easy for the professional programmer to learn and use effectively. One outcome of this was a clean. When you use a Javacompatible Web browser. you are risking a viral infection. make learning Java easier.

The Java designers made several hard decisions in the Java language and the Java Virtual Machine in an attempt to alter this situation. it also checks your code at run time. At the same time. Knowing that what you have written will behave in a predictable way under diverse conditions is a key feature of Java. to force you to find your mistakes early in program development. because the program must execute reliably in a variety of systems. This code can be interpreted on any system that provides a Java Virtual Machine. Java restricts you in a few key areas.and easy to extend. Their goal was “write once. ARCHITECTURE-NEUTRAL A central issue for the Java designers was that of code longevity and portability. Operating system upgrades. One of the main problems facing programmers is that no guarantee exists that if you write a program today. To gain reliability. it checks your code at compile time. In fact. Java supports multithreaded programming. are kept as high-performance non objects. while simple types. forever. not the multitasking subsystem. Java frees you from having to worry about many of the most common causes of programming errors. INTERPRETED AND HIGH PERFORMANCE Java enables the creation of cross-platform programs by compiling into an intermediate representation called Java bytecode. ROBUST The multiplatformed environment of the Web places extraordinary demands on a program. which allows you to write programs that do many things simultaneously. any time. this goal was accomplished. processor upgrades. the ability to create robust programs was given a high priority in the design of Java. such as integers. MULTITHREADED Java was designed to meet the real-world requirement of creating interactive. To accomplish this. However.” To a great extent. it will run tomorrow—even on the same machine. Most previous attempts at crossplatform solutions have done so at the expense of performance DISTRIBUTED . many hard-to-track-down bugs that often turn up in hard-to-reproduce run-time situations are simply impossible to create in Java. networked programs. Because Java is a strictly typed language. and changes in core system resources can all combine to make a program malfunction. run anywhere. Java’s easy-to-use approach to multithreading allows you to think about the specific behavior of your program. Thus. The Java run-time system comes with an elegant yet sophisticated solution for multiprocess synchronization that enables you to construct smoothly running interactive systems.

The original version of Java (Oak) included features for intraaddress-space messaging. in which small fragments of bytecode may be dynamically updated on a running system. . This feature brings an unparalleled level of abstraction to client/server programming. This allowed objects on two different computers to execute procedures remotely. DYNAMIC Java programs carry with them substantial amounts of run-time type information that is used to verify and resolve accesses to objects at run time. accessing a resource using a URL is not much different from accessing a file. because it handles TCP/IP protocols. Java revived these interfaces in a package called Remote Method Invocation (RMI). This is crucial to the robustness of the applet environment. In fact. This makes it possible to dynamically link code in a safe and expedient manner.Java is designed for the distributed environment of the Internet.

. A Bean may be visible to an end user. • A Bean may register to receive events from other objects and can generate events that are sent to other objects. • The configuration settings of a Bean can be saved in persistent storage and restored at a later time. • A Bean may be designed to operate correctly in different locales. events. • The properties.2A TOUR OF SWING Swing is a set of classes that provides more powerful and flexible components than are possible with the AWT.A Bean that provides real-time price information from a stock or commodities exchange would need to work in cooperation with other distributed software to obtain its data. which makes it useful in global markets. such as checking the spelling of a document. It does not need to be included in the run-time environment. and labels. including tabbed panes. In addition to the familiar components. such as buttons. It may perform a simple function. and tables. and methods of a Bean that are exposed to an application builder tool can be controlled. 3. There is no restriction on the capability of a Bean. Even familiar components such as buttons have more capabilities in Swing. 3.1. or a complex function. • Auxiliary software can be provided to help a person configure a Bean.3 SOFTWARE DEVELOPMENT USING JAVA 3. Swing supplies several exciting additions. such as forecasting the performance of a stock portfolio. The Swing component classes that are used in this book are shown here: Class AbstractButton Description Abstract superclass for Swing buttons. scroll panes. This software is only needed when the design-time parameters for that component are being set. run-anywhere” paradigm. • A Bean obtains all the benefits of Java’s “write-once. trees.1WHAT IS A JAVA BEAN? A Java Bean is a software component that has been designed to be reusable in a variety of different environments.1ADVANTAGES OF JAVA BEANS A Software component architecture provides standard mechanisms to deal with software building blocks. check boxes.

world!" inside: // Hello. which is used as the window's title. The Swing push button class.ButtonGroup ImageIcon JApplet JButton JCheckBox JComboBox JLabel JRadioButton JScrollPane JTabbedPane JTable JTextField JTree Encapsulates a mutually exclusive set of buttons. The Swing version of a radio button.EXIT_ON_CLOSE).awt package in the compilation. The Swing version of Applet. Encapsulates a tree-based control. Encapsulates a combo box (an combination of a drop-down list and text field).awt. The Hello class extends the JFrame class.*. Encapsulates a scrollable window.swing.swing package. The Swing version of a label. setDefaultCloseOperation(WindowConstants. Encapsulates a table-based control. Encapsulates an icon. Encapsulates a tabbed window. It then calls the setDefaultCloseOperation(int) method inherited from JFrame to set the default operation when the close control on the title bar is selected to .BorderLayout. import javax.setVisible(true). setLayout(new BorderLayout()).java (Java SE 5) import java. public class Hello extends JFrame { public Hello() { super("hello"). } } The first import statement directs the Java compiler to include the BorderLayout class from the java. add(new JLabel("Hello. } public static void main(String[] args) { new Hello(). pack(). passing the parameter "hello". The Swing version of a text field. world!")). the second import includes all of the public classes and interfaces from the javax. The Swing check box class. This example Swing application creates a single window with "Hello. The Hello() constructor initializes the frame by first calling the superclass constructor. the JFrame class implements a window with a title bar and a close control.

// necessary for the frame to be visible } } Used the mouse to drag the Window to a larger size WindowConstants. the layout of the frame is set to a BorderLayout.EXIT_ON_CLOSE — this causes the JFrame to be disposed of when the frame is closed (as opposed to merely hidden). .BUILDING A GRAPHICAL INTERFACE • Adding a Frame and using the show() method package com.awt.cosc210.*.AWT . import java.awt. myFrame. public class MyApp1 { public static void main (String arg[]) { Frame myFrame = new Frame("example Frame for cosc210"). which allows the JVM to exit and the program to terminate. this tells Swing how to arrange the components that will be added to the frame. Next.show().

we will begin by building and testing a simple servlet. • Start Tomcat. The basic steps are the following: • Create and compile the servlet source code.3. • Start a Web browser and request the servlet. A Simple Servlet:To become familiar with the key servlet concepts. .3SERVLETS Servlets are small programs that execute on the server side of a Web connection.

Java suppresses several features (such as operator overloading and multiple inheritance) for classes in order to simplify the language and to prevent possible errors and anti-pattern design. */ . boolean values.4 SYNTAX The syntax of Java is largely derived from C++. with the exception of the intrinsic data types (ordinal and real numbers. Java was built almost exclusively as an object oriented language. There are two different styles of comment: a single line style marked with two forward slashes. and characters). Unlike C++. Example: //This is an example of a single line comment using two forward slashes /* This is an example of a multiple line comment using the forward slash and asterisk. and a multiple line style opened with a forward slash asterisk (/*) and closed with an asterisk forward slash (*/). which combines the syntax for structured. Java uses the same commenting methods as C++. which are not classes for performance reasons. This type of comment can be used to hold a lot of information but it is very important to remember to close the comment. generic. and object-oriented programming. All code is written inside a class and everything is an object.

*. appending the suffix .5 EXAMPLES 5. world!" and then exits */ public class HelloWorld { public static void main(String[] args) { System.java. for example. producing a file named HelloWorld. Java classes that run in managed environments such as applets and Enterprise JavaBean do not use or need a main() method. The name of the class file is the name of the class.2 A MORE COMPREHENSIVE EXAMPLE import java.swing. A class that is declared private may be stored in any . } } Source files must be named after the public class they contain.class appended. using a Java compiler.class. which means that the VM needs to be explicitly told which class to launch from.out. It is simply the name of the method the Java launcher calls to pass control to the program.gif"). world!").The compiler will generate a class file for each class defined in the source file. A java program may contain multiple classes that have main methods. HelloWorld. // Create an icon ImageIcon ii = new ImageIcon("france.println("Hello.java.1 Hello world The traditional Hello world program can be written in Java as: /* * Outputs "Hello.java file. with .*. Only then can it be executed. 5. It must first be compiled into bytecode. The java source file may only contain one public class but can contain multiple classes with less than public access and any number of public inner classes.awt. . or 'launched'. public class JLabelDemo extends JApplet{ public void init() { // Get content pane Container contentPane = getContentPane(). import javax.

ii. } } Output from this applet is shown here: .add(jl). // Add label to the content pane contentPane.// Create a label JLabel jl = new JLabel("France". JLabel.CENTER).

swing. the JApplet class provides the framework for the host application to display and control the lifecycle of the applet. javax.JApplet and java. 95).Hello.org/TR/html4/strict.The import statement allows these classes to be referenced in the source code using the simple class name (i.awt. } } The import statements direct the Java compiler to include the javax.drawString("Hello.awt. The applet tag has three attributes set: code="Hello" specifies the name of the JApplet class and width="200" height="200" sets the pixel width and height of the applet.e.e.1 APPLET Java applets are programs that are embedded in other applications.w3. import java. . typically in a Web page displayed in a Web browser. world!".dtd"> <!-.JApplet.JApplet).Graphics classes in the compilation.html --> <html> <head> <title>Hello World Applet</title> </head> <body> <applet code="Hello" width="200" height="200"> </applet> </body> </html> An applet is placed in an HTML document using the <applet> HTML element. public class Hello extends JApplet { public void paintComponent(Graphics g) { g.Graphics.swing. // Hello.6 SPECIAL CLASS 6.01//EN" "http://www.java import javax. JApplet) instead of the fully qualified class name (i.swing. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4. The Hello class extends (subclasses) the JApplet (Java Applet) class. 65.

After that. Once the applet has initialized itself. instantiates the Hello applet and creates an AppletContext for the applet. For container classes. consistent mechanism for extending the functionality of a Web server and for accessing existing business systems. 6. as part of J2SE 5. for example. 6. to HTTP requests from clients.4 GENERICS In 2004 generics were added to the Java language. so the object tag is preferred where supported. Prior to the introduction of generics.2 SERVLET Java Servlet technology provides Web developers with a simple. the applet tag is deprecated.3 JAVA SERVER PAGE JavaServer Pages (JSPs) are server-side Java EE components that generate responses. the first time it is accessed. each variable declaration had to be of a specific type.Applets may also be embedded in HTML using either the object or embed element[26]. The paint method is called by the AWT event dispatching thread whenever the display needs the applet to draw itself. typically a Web browser. [27] However. typically HTML pages. the generated servlet creates the response. although support for these elements by Web browsers is inconsistent.0. a Java application in its own right. A JSP is compiled to a Java servlet. Generics allow compile-time type checking without having to create a large number of container classes. each containing almost identical code. or a different container class has to be created for each contained class. . Either the container operates on all subtypes of a class or interface. this is a problem because there is no easy way to create a container that accepts only specific types of objects. The host application. 6. usually Object. Servlets are server-side Java EE components that generate responses (typically HTML pages) to requests (typically HTTP requests) from clients. JSPs embed Java code in an HTML page by using the special delimiters <% and %>. it is added to the AWT display hierarchy.

created by Sun Microsystems. the multi-line comment tags. */ public class Program { /** * A main method. 8.1 Examples The following is an example of java code commented with simple Javadoc-style comments: /** * A program that does useful things. It provides developers with an organized system for documenting their code. used by many Java developers. so that the tags are /** and */. Whereas normal comments in Java and C are set off with /* and */. * @param args The arguments */ public static void main(String[] args) { //do stuff } } .7 Documentation Javadoc is a comprehensive documentation system. Javadoc comments have an extra asterisk at the beginning.

It is the Java Platform used to deploy portable applications for general use. Java SE consists of a virtual machine. Standard Edition or Java SE is a widely used platform for programming in the Java language. The platforms are: • • • • Java Card Micro Edition (ME) Standard Edition (SE) Enterprise Edition (EE) Java Card –Java Card refers to a technology that allows Java –dd application(applets)to be run securely on smart cards and similar small memory footprint devices. It includes tools to create frameworks. Java Card products are based on the Java Card Platform specifications developed by Sun Microsystems. In practical terms. Java Platform. graphical interfaces. together with a set of libraries (or "packages") needed to allow the use of file systems. The first Java Card was introduced in 1996 by Schlumberger’s card division which later merged with Gemplus to form Gemalto.jar in the distribution package of J2SE. API specifications suitable for companies. Java Platform. Then there are specification such as Swing and Networking. Enterprise Edition or Java EE is a widely used platform for server programming in the Java programming . from within those programs Java Platform. a subsidiary of Oracle Corporation. and so on.8 Editions Sun has defined and supports four editions of Java targeting different application environments and segmented many of its APIs so that they belong to one of the platforms. which must be used to run Java programs. It is widely used in SIM cards(used in mobile phones) and ATM cards. Java Card is the tiniest of Java targeted for embedded devices. JSP and Servlets (and Beans) are J2EE. Enterprise Edition (Java EE) — J2EE on the other hand builds on top of J2SE so to speak. Standard Edition (Java SE) — J2SE is Sun's platform that includes the Java Virtual Machine (JVM) and packages. There is the core package which is basically the contents of rt. By specification. Java Card gives the user ability to program the device and make them application specific. J2EE needs J2SE. Java Platform. networks.

This process has been a subject of controversy. Micro Edition (J2ME). is a Java platform designed for embedded systems (mobile devices are one kind of such systems) . J2ME (Micro Edition) which runs on portable. Sun also provided an edition called PersonalJava that has been superseded by later. handheld devices. the platform replaced a similar technology. I don't really have a testing environment. The set of APIs is controlled by Sun Microsystems in cooperation with others through the Java Community Process program. Micro Edition (Java ME) — Java Platform. Java ME was designed by Sun Microsystems. classes and exceptions.Companies or individuals participating in this process can influence the design and development of the APIs. I'm honestly not that familiar with this one. or Java ME. Each package contains a set of related interfaces. Refer to the separate platforms for a description of the packages available. The Java platform (Enterprise Edition) differs from the Java Standard Edition Platform (Java SE) in that it adds libraries which provide functionality to deploy fault-tolerant. now a subsidiary of Oracle Corporation. Micro Edition. but has tended not to provide free binary implementations of its Java ME runtime environment for mobile devices. The classes in the Java APIs are organized into separate groups called packages. based largely on modular components running on an application server Java Platform. Originally developed under the Java Community Process as JSR 68. PersonalJava. standards-based Java ME configuration-profile pairings. distributed. multi-tier Java software. . Sun provides a reference implementation of the specification. Java ME was formerly known as Java 2 Platform.language. mobile. rather relying on third parties to provide their own. Target devices range from industrial controls to mobile phones (especially feature phones) and set-top boxes. the different flavors of Java ME have evolved in separate JSRs.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->