Académique Documents
Professionnel Documents
Culture Documents
Experiment No : 1
2. Prior Concepts:
Class, Object, Member functions, Data types, Operators, Control Statements in Java.
3. Information Input:
Where –
class is a keyword.
class_name is a name of the class.
data_type is built-in, derived or user defined type.
member_name is a name of a variable.
return_type is data_type of a returned value.
method1 is name of a method.
parameter list is list of parameters.
Example:
class Rectangle
{
int length;
int width;
void getData(int m, int n)
{
length = m;
width = n;
}
}
Task:
Study the sample program given below, and note the class definition and declaration of object, and
how to access data members of an object.
Sample program:
Program to define a class ‘Student’ having data members roll, name. Initialize and display
this data for an object of the class Student.
import java.lang.*; // import language package which is default package.
class Student
{
int roll ; // data members declaration.
String name; //String is a built in class used to store string.
void getData(int r, String s) // method to initialize data members.
{
roll = r;
name = s;
}
void putData( ) // method to display information.
{
System.out.println(“Roll number = “ + roll);
System.out.println(“Name = “ + name);
}
public static void main(String args[]) // main method
{
Student s = new Student( ); // creating object.
s.getData(1,”Raj”); // invoking methods
s.putData( );
}
}
Exercise :
Implement following programs using appropriate data-type
1. Initialize the temperature value in Celsius and convert it to Fahrenheit and vice
versa
2. Initialize suitable data and calculate area of circle, triangle, rectangle and square
.
3. Initialize one dimensional array of any size and separate out even ,odd, prime
numbers from this array and calculate average of each separated array
4. Initialize any two dimensional matrix and pick up largest number from this
matrix
Experiment No : 2
1. Title :
2. Prior Concepts:
3 Information Input:
3.1 Inheritance:
The mechanism of deriving a new class from an existing class is called Inheritance. The
existing class is known as the base or super class or parent class and the new class is
called as derived class or child class.
3.2 Single inheritance:
The mechanism or deriving a new class from only one super class is called as single
Inheritance. e.g.
A
Super Class
B Sub Class
The keyword extends signifies that the properties of the super class superclassname are
extends to the sub class subclassname.
The above statements will create an object of String class explicitly and initialize it to string “abcd”.
String class has number of methods which are used to get information about the string or
manipulate the string. The details of these methods are available in any Java
languagedocumentation or reference books.
3.6 Interface:
An Interface is basically a kind of class. Like classes, interface contains variables and methods.
The difference is that the interface defines only abstract method.? and final v3riables. By
default variables declared inside antrrferface are final and sfatic.'They must be initialized with
a constant value. It is the responsibility of the class that implements an interface to deTine the
code for these methods.
Syntax :
interface interface name
{
variable declaration; method declaration;
}
Exercise:
1. Calculate the balance of different accounts like Savings account , Fixed Deposit
account, Recurring account of a customer . Here Balance is superclass and other
classes are derived classes from it . Make use of inheritance
In this assignment make appropriate use of package and interface
Define an interface which contain methods like add ,delete , display. Implement the classes
Queue and stack from this interface
Experiment No : 3
1. Title:
Program for file processing
2. Prior Concepts:
File, input and output streams, primitive operations on file.
3 Information Input:
The InputStream nnd OutputStream classes are the maior components of this hierarchy.
The InputStream and OutputStream classes are abslract classes that lay the foundation for
the Java Input and Output class hierarchy. As such, they provide methods that are inherited
by all lnputStream and OutputStream classes. The inputStream and QutputStream
classes have complementary subclasses .
4. Algorithm
1) Accept from user or specify the name of file to be opened
2) Open the stream in input/output mode as specified
3) Use file to store /retrieve/process from the file
4) Close the files
Exercise :
a. Implement student database using file . Accept student name, rollno, class, Percentage
marks from user and store it in file and search particular student record and display it.
Make appropriate use of features you have studied in previous experiments like
inheritance, packages ,interfaces
Experiment No : 4
1.Title:
Design GUI using Applet.
2. Prior Concepts:
Inheritance, Method overloading and overriding, Interface.
3 Information Input:
The Applet class extends the AWT Panel class, which extends the AWT Container class,
which extends the AWT Component class. From Component, an applet inherits the ability to
draw and handle events. From Containerf-an applet inherits the ability to include other
components and to have a layout manager control the size and position of those components. From
Applet, an applet inherits several capabilities, including the ability to respond to major
1. Initialization stage: In this stage the applet object is created and loaded. The
initialization stage occurs only once in the applet's life cycle. To tap Into the initialization
stage, the init() method of Applet has to be overridden.
2. Start stage: This stage occurs when the system starts running the applet. The start
stage can occur right after the initialization stage or when an applet is restarted.
Unlike the initialization stage, the start stage can occur several times over the life of the applet.
To provide start code, override the Applet class's start() method.
3. Paint stage: The paint stage occurs whenever the applet's display mud be drawn on the
screen. This happens right after the applet's start stage, as well as wherever the applet's
display must be restored or changed. Almost every applet has a paint() method,
which is used for display
4. Stop stage: The stop stage is the counter part to the start stage. Java executes this
stage of the applet's life cycle when the applet is no longer visible on the screen. To
handle the stop stage differently, the stop( ) method of Applet class has to be
overridden.
5. Destroy stage: This is the counterpart to the initialization stage and occurs when
the system is about to remove the applet from memory. Like the initialization stage,
the destroy stage occurs only once. If the applet has resources that need to be
cleaned up before the applet exits, then it is done in by overriding the Applet class's
destroy() method.
1. Through web browser: To run an Applet, the html tag containing applet tag has to be
stored in a file with extension .html, which can be opened through any Java-compatible
web browser. The html tag is given as below.
<html>
<applet code = "classfile.class" height = 200 width=300>
</applet>
</html>
In the above syntax code is assigned the name of the .class file of the Applet to be viewed and
height and width is the size of the Applet in pixels.
Through Appletvicwer : Applets can run without a Java-compatible web browser using the
Appletviewer tool that comes as part of the JDK. Appletviewer is a Windows application
that is run from a DOS command line. When Appletviewer appears, the applet appears in the
viewer's main window. The command to view Applet through the Appletviewer is as below.
Where c:\jdk1.2\bin is the path where appleviewer.exe file is stored and the file prog1.html
contains (eg for the applet. The height and width is the size of the applet in pixels
Algorithm:
1. import the applet package.
2. create a public subclass of the Applet class
3. In Applet subclass, override at least one of the following methods: init( ) , start( ), and
paint() and declare them as public. The init and start methods, along with stop and destroy, are
called when major events (milestones) occur in the applet's life cycle. The paint method is called
when the applet needs to draw itself to the screen
Exercise:
Principal Amount
Years
Interest Rate
Final Amount
Compute
Experiment No : 5
2. Prior Concepts:
Applet and event handling
2. Information Input :
The Java programming language class library provides a user interface toolkit called the
Abstract Windowing Toolkit, or the AWT. The AWT is both powerful and flexible.
The AWT provides a well-designed object-oriented interface to these low-level services and
resources.
. The AWT was designed to provide a common set of tools for graphical user interface
design that work on a variety of platforms.
Following fig the inheritance relationship between the user interface component classes
provided by the AWT. Class Component defines the interface to which all components
must adhere.
The AWT provides nine basic non-container component classes from which a user interface
may be constructed. (Of course, new component classes may be derived from any of these
or from class Component itself.) These nine classes are class Button, Canvas, Checkbox,
Choice, Label, List, Scrollbar, TextArea, and TextField.
Types of containers
The AWT provides four container classes. They are class Window and its two subtypes --
class Frame and class Dialog -- as well as the Panel class. In addition to the containers
provided by the AWT, the Applet class is a container -- it is a subtype of the Panel class and
can therefore hold components. Brief descriptions of each container class provided by the
AWT are provided below.
Window class.
A top-level display surface (a window) with a border and title. An instance of the
Dialog
Dialog class cannot exist without an associated instance of the Frame class.
A generic container for holding components. An instance of the Panel class
Panel provides a container to which to add components.
Creating a container
Before adding the components that make up a user interface, the programmer must create a
container. When building an application, the programmer must first create an instance of
class Window or class Frame. When building an applet, a frame (the browser window)
already exists. Since the Applet class is a subtype of the Panel class, the programmer can
add the components to the instance of the Applet class itself.
The code in Listing 1 creates an empty frame. The title of the frame ("Example 1") is set in
the call to the constructor. A frame is initially invisible and must be made visible by
invoking its show() method.
import java.awt.*;
f.show();
}
}
The code in Listing 2 extends the code from Listing 1 so that the new class inherits from
class Panel. In the main() method, an instance of this new class is created and added to the
Frame object via a call to the add() method. The result is then displayed. The results of both
examples should look identical (that is, they should look quite uninteresting).
import java.awt.*;
f.add("Center", ex);
f.pack();
f.show();
}
}
By deriving the new class from class Applet instead of class Panel, this example can now
run as either a standalone application or as an applet embedded in a Web page. The code
for this example is provided in Listing 3.
import java.awt.*;
f.add("Center", ex);
f.pack();
f.show();
}
}
import java.awt.*;
ex.init();
f.add("Center", ex);
f.pack();
f.show();
}
}
3. Exercise :
Vanilla Butterscotch
Total Amount
Experiment No. 6
1. Title : Miniproject
2. Prior Concepts :
Database management system, relational database concepts, SQL commands ,
HTML, All core java concepts
3.Information Input:
jdbc :odbc:dataname
3.7 HTML:
What is HTML?
Attributes Example
Tables
Tables are defined with the <table> tag. A table is divided into rows (with the <tr> tag), and
each row is divided into data cells (with the <td> tag). The letters td stands for "table data,"
which is the content of a data cell. A data cell can contain text, images, lists, paragraphs,
forms, horizontal rules, tables, etc.
3.8 JSP
Exercise :
Develop a miniproject based upon the concepts like a) Database Management System b)
Web based application c) Any standalone Java application e.g, Game etc.
Design Online Marketing site which gives the facility to sell and buy various items in various
categories like 1. Art 2.Books 3. Business & Industrial 4.Cameras & Photo 5. Cell Phones & PDAs
6. Clothing, Shoes & Accessories 7.Computers & Networking 8.Consumer Electronics 9. DVDs &
Movies 10. Home & Garden 11. Musical Instruments 12. Real Estate 13. Sporting Goods 14
Stamps 15.Tickets etc