Lab Manual Java Programming Lab
Lab Manual Java Programming Lab
Document No:
MLRIT/CSE/LAB MANUAL/Java
programming VERSION 1.1
Date of Issue
Authorized by
29-12-2014
Compiled by
B. Madhuravani
Shiek Gouse
Date of Revision
Verified by
HOD(CSE/IT)
10-01-2015
Saritha Chowdary
Ram Mohan
INTRODUCTION TO OOP
LAB CODE
1. Students should report to the concerned lab as per the time table.
2. Students who turn up late to the labs will in no case be permitted to do the
program schedule for the day.
3. After completion of the program, certification of the concerned staff incharge in the observation book is necessary.
4. Student should bring a notebook of 100 pages and should enter the
readings /observations into the notebook while performing the
experiment.
5. The record of observations along with the detailed experimental
procedure of the experiment in the immediate last session should be
submitted and certified staff member in-charge.
6. Not more than 3-students in a group are permitted to perform the
experiment on the set.
7. The group-wise division made in the beginning should be adhered to and
no mix up of students among different groups will be permitted.
8. The components required pertaining to the experiment should be
collected from stores in-charge after duly filling in the requisition form.
9. When the experiment is completed, should disconnect the setup made by
them, and should return all the components/instruments taken for the
purpose.
10. Any damage of the equipment or burn-out components will be viewed
seriously either by putting penalty or by dismissing the total group of
students from the lab for the semester/year.
11. Students should be present in the labs for total scheduled duration.
12. Students are required to prepare thoroughly to perform the experiment
before coming to laboratory.
13. Procedure sheets/data sheets provided to the students groups should be
maintained neatly and to be returned after the experiment.
4
INDEX
S.n
o.
1
Week
no:
PageNo
34-37
10
11
10
12
11
13
12
14
13
15
14
70-76
77-80
81-87
88-93
94-97
98-102
103-106
Use Eclipse or Netbean platform and acquaint with the various menus. Create a test
project, and a test class and run it. See how you can use auto suggestions, auto fill.
Try code formatter and code refactoring like renaming variables, methods and
classes. Try debug step by step with a small program of about 10 to 15 lines which
contains at least one if else condition and a for loop.
AIM:
To create and test java projects in Eclipse and Netbean platform
Initializing Eclipse
When you develop Java applications in Eclipse, it stores all the created files in a directory
called "workspace". When Eclipse is run for the first time, it will ask you where you want
the workspace to be placed:
You can just use the default location or specify your preferred location. To avoid getting
asked this question every time you start Eclipse, check "Use this as the default and do not
ask again" option and press "OK" button. Once Eclipse finishes its startup process, you
will
see
the
following
welcome
window:
Click the "Workbench" icon on the right, which will lead you to the main Eclipse
window:
Creating a Project
Now that you've got Eclipse up and running, it's time to create your first Java project. To
do this, you'll want to go File -> New -> Java Project. After doing so, you'll see a window
like the following:
Type your project name (say, cs144project1) in the "Project name" field and click Finish.
Then the name of your newly created project will appear on the left side of the Eclipse
window (this part of the window is called "Package explorer pane"):
10
As you create more projects in Eclipse, other project names will appear in the Package
explorer pane and you will be able to switch between your projects by clicking the name
of a project.
Adding a New File to a Project
Now that you've created your first project, you now want to create a new Java file (with
.java extension) and add it into your project. To create a new Java file, right click on the
name of your project (cs144project1) in the Package explorer pane and select New ->
Class as follows:
11
This command will show you a window that looks like the following:
12
In the "Name: " section provide the name of the file (or the class) you want to create,
HelloWorld, and click "Finish" button.
13
Congratulations! Now you have created your first Java code in eclipse. As you can see
from the Package explore pane, your project now includes HelloWorld.java file. The
"Editor pane" to the right of the Package explorer pane shows the actual content of the
HelloWorld.java file, which simply declares HelloWorld as a public class. You can edit
the content of the Java code inside the Editor pane.
14
Now save the file by selecting File->Save, or pressing Ctrl-S (Option-S on Mac). When
you save a Java file, Eclipse will automatically compile the file also, so that you don't
need to compile it later when you want to run it.
Now that your code has been saved and compiled, you can run your program by selecting
Run -> Run, or by pressing Ctrl-F11 (Option-F11 on Mac) or by clicking on the "Run"
button
near the top of the window. Once your program finishes running, you will
be able to see the output of your program by selecting the "Console tab" at the bottom of
the window.
15
Quitting Eclipse
You can exit eclipse by using any of the following alternatives:
Now you have learned the very basic functionality of Eclipse. Eclipse supports many
more functionalities than what you just learned, including integrated debugging and
automatic code completion and method lookup, etc. Please read online Eclipse manual to
learn more about Eclipse.
16
Netbeans
Create an IDE Project
To create an IDE project:
1. Launch the NetBeans IDE.
o On Microsoft Windows systems, you can use the NetBeans IDE item in
the Start menu.
o On Solaris OS and Linux systems, you execute the IDE launcher script by
navigating to the IDE's bin directory and typing ./netbeans.
o On Mac OS X systems, click the NetBeans IDE application icon.
2. In the NetBeans IDE, choose File | New Project....
1. NetBeans IDE with the File | New Project menu item selected.
2. In the New Project wizard, expand the Java category and
Application as shown in the following figure:
select Java
17
The project is created and opened in the IDE. You should see the following components:
The Projects window, which contains a tree view of the components of the
project, including source files, libraries that your code depends on, and so on.
The Source Editor window with a file called HelloWorldApp.java open.
The Navigator window, which you can use to quickly navigate between elements
within the selected class.
19
20
of
To specify this JDK for the current project only, select Hello World App in
the Projects pane, choose File | Project Properties (Hello World App), click Libraries,
then select JDK 1.8 in the Java Platform pulldown menu. You should see a screen
similar to the following:
21
/**
*
* @author
*/
with these lines:
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
These four lines are a code comment and do not affect how the program runs. Later
sections of this tutorial explain the use and format of code comments.
Note: Type all code, commands, and file names exactly as shown. Both the compiler
(javac) and launcher (java) arecase-sensitive, so you must capitalize consistently.
HelloWorldApp is not the same as helloworldapp.
/**
* @param args the command line arguments
*/
22
The program prints "Hello World!" to the Output window (along with other output from
the build script).
Congratulations! Your program works!
Continuing the Tutorial with the NetBeans IDE
The next few pages of the tutorial will explain the code in this simple application. After
that, the lessons go deeper into core language features and provide many more examples.
24
Although the rest of the tutorial does not give specific instructions about using the
NetBeans IDE, you can easily use the IDE to write and run the sample code. The
following are some tips on using the IDE and explanations of some IDE behavior that
you are likely to see:
Once you have created a project in the IDE, you can add files to the project using
the New File wizard. Choose File | New File, and then select a template in the
wizard, such as the Empty Java File template.
You can compile and run an individual file (as opposed to a whole project) using
the IDE's Compile File (F9) and Run File(Shift-F6) commands. If you use
the Run Main Project command, the IDE will run the file that the IDE associates
as the main class of the main project. Therefore, if you create an additional class
in your HelloWorldApp project and then try to run that file with the Run Main
Project command, the IDE will run the HelloWorldApp file instead.
You might want to create separate IDE projects for sample applications that
include more than one source file.
As you are typing in the IDE, a code completion box might periodically appear.
You can either ignore the code completion box and keep typing, or you can select
one of the suggested expressions. If you would prefer not to have the code
completion box automatically appear, you can turn off the feature.
Choose Tools | Options | Editor, click the Code Completion tab and clear
the Auto Popup Completion Window checkbox.
If you want to rename the node for a source file in the Projects window,
choose Refactor from IDE's main menu. The IDE prompts you with
the Rename dialog box to lead you through the options of renaming the class and
the updating of code that refers to that class. Make the changes and
click Refactor to apply the changes. This sequence of clicks might seem
unnecessary if you have just a single class in your project, but it is very useful
when your changes affect other parts of your code in larger projects.
25
WEEK-I
Write a Java program that works as a simple calculator. Use a grid layout to arrange
buttons for the digits and for the +, -,*, % operations. Add a text field to display the
result. Handle any possible exceptions like divided by zero
AIM:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
ZORIN
JAVA
LINUX
2. THEORY:
GridLayout is one of the Layout managers.A layout manager automatically arranges your
controls with in a window by using some type of algorithm.Grid Layout lays out
component in a two dimensional grid. When you instantiate a GridLayout,you define the
number of rows and columns
3. ALGORITHMS:
1.create buttons using Buttons() and text field using TextField()
2.use gridlayout and place the buttons and textfield in this layout by using add()
3.Display the applet showing this.
26
4. OBSERVATION:
Input: 2 3 +
Output:
Applet
1
5
9
+
2
6
10
-
3
7
4
8
5. RESULT:
An applet that displays the calculated values
6. INFERENCES:
Execution of applet does not begin at main().The applet will be executed by java
enabled web-browser
7. APPLICATION:
->Web application
->Animations
27
8. EXTENSIONS:
The most important feature of applets on the web, however, is th fact that applets change
the web from being a static medium to one based on interactivity with users.at
present,java is limited only by the capabilities of the internet itself .as the internet grows
in data transmission,java is ready to expand with it.
9. DIAGNOSTICS:
S.NO
1.
Error
Error:Missing semicolon
2.
Error:cannot read
4.
Debugging
Go to the line number and
place semicolon at the end
of the statement
Dont divide the number
with zero
Make sure that the file is
present in the directory in
which u are executing it
Write the first character of
the System in capital letters
10 .QUESTIONS:
1.___________automatically arranges the controls the with in the window.
2.The controls cannot be arrange manually because of _________.
3.Layout managers are used when ________ and __________ information is not
available when u need to arrange the control.
4.Each __________ object has a layout manager associated to it.
5.A layout manager is an instance of any class that implements the _________interface.
6.The layout manager is set using ________ method.
7.if no call to setLayout() is made then the ___________ manger is used.
8.you can determine the shape and position of each component manually using ________
9.The _________ is notified when a new component is added to the container.
10.Each component managed by the Layout manager contains the ________ and
__________Methods.
28
Problem
statemen
t
No
P1
P2
P3
P4
P5
P6
P7
P8
P9
10
P10
Batch1
No
Batch2
No
A1
B1
A2
B2
A3
B3
A4
B4
A5
B5
A6
B6
A7
B7
A8
B8
A9
B9
A10
B10
29
WEEK-2
Develop an applet that displays a simple message
1. AIM:
Java program to display a simple message.
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
ZORIN
JAVA
LINUX
3. THEORY:
Applets are designed to bring the web alive.they function to add animation sound and
eventually complete multi media into HTML documents.java is also part of the future of
interfacing with virtual-reality environments implemented via VRML.At present ,java is
limited only by the capabilities of the internet itself.applets are java programs that are
specialized for use over the Web.
3. ALGORITHMS:
1.create an applet from extending applet class.
2.using drastic method in paint() display the simple message.
3.include the applet program in the HTML code
4.Execute the applet using web-browser.
4. OBSERVATION:
Input:
Applet ,
Sample text
5. RESULT:
An applet that displays a simple messages
6. INFERENCES:
Execution of the applet does not begin at main().The applet will be executed by
java enabled web-browser.
7. APPLICATION:
->Web application
->Animations
8. EXTENSIONS:
31
The most important feature of applets on the web, however, is th fact that applets
change the web from being a static medium to one based on interactivity with users.at
present,java is limited only by the capabilities of the internet itself .as the internet grows
in data transmission,java is ready to expand with it.
9.DIAGNOSTICS:
S.NO
1.
Error
Error:Missing semicolon
2.
Error:cannot read
4.
Debugging
Go to the line number and
place semicolon at the end
of the statement
Dont divide the number
with zero
Make sure that the file is
present in the directory in
which u are executing it
Write the first character of
the System in capital letters
10. QUESTIONS:
1.All applets must import _________
2.AWT stands for_________
3.Applets are executed by _____________
4.Execution of applets does not begin at____________
5.An applet is included in the HTML file using __________tag.
6.___________outputs the string to the specified X,Y location.
7.Applets provides all necessary support for ___________
8.Applets are ___________
9.user initiates interaction with the_____________
10.An applets waits until ___________ occurs.
32
Batch-1
No
Batch-2
No
P1
A1
B1
P2
A2
B2
P3
A3
B3
P4
A4
B4
P5
A5
B5
P6
A6
B6
P7
A7
B7
P8
A8
B8
P9
A9
B9
10
P10
A10
B10
33
WEEK -3
Develop an applet that receives an integer in one text field, and computes its
factorial Value and returns it in another text field, when the button named
Compute is clicked.
1 .AIM:
Develop an applet that receives an integer in one text field, and computes its factorial
Value and returns it in another text field, when the button named Compute is clicked
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
ZORIN
JAVA
LINUX
2.THEORY:
Applets are designed to bring the web alive.they function to add animation sound and
eventually complete multi media into HTML documents.java is also part of the future of
interfacing with virtual-reality environments implemented via VRML.At present ,java is
limited only by the capabilities of the internet itself.applets are java programs that are
specialized for use over the Web.
The Appplet life cycle
The init()Method: The init()method is where your applet does much of its setup,such as
defined its layout,parsing parameters,or setting the background colors.
The starts() Method: The start()method is used mainly when implementing threads in
java.
The stop() Mehtod: The stop() method is used to do what its name suggests: stop what is
going on.
The destroy() method: when it is called,the applet is told to free up system resources.
3. ALGORITHMS:
1.create an applet from extending applet class.
2 get the parameters from the browser using getParameter() for monthly rate.
3.Calculate the amount of loan.
34
4.Include the applet in html and set the parameter using param and value pair.
5.Run the applet in the browser.
4. OBSERVATION:
Input: 2
Output:
Applet
5 is 20
5. RESULT:
An applet that displays the fctorial of a number
6. INFERENCES:
Execution of applet does not begin at main().The applet will be executed by java
enabled web-browser
7. APPLICATION:
->Web application
35
->Animations
8. EXTENSIONS:
The most important feature of applets on the web, however, is th fact that applets change
the web from being a static medium to one based on interactivity with users.at
present,java is limited only by the capabilities of the internet itself .as the internet grows
in data transmission,java is ready to expand with it.
9. DIAGNOSTICS:
S.NO
1.
Error
Error:Missing semicolon
2.
Error:cannot read
4.
Debugging
Go to the line number and
place semicolon at the end
of the statement
Dont divide the number
with zero
Make sure that the file is
present in the directory in
which u are executing it
Write the first character of
the System in capital letters
10. QUESTIONS:
1.Applet can be executed by a _________ and _________
2.The __________ tag is used to start an applet from both HTML document and from an
applet viewer.
3.Applet viewer will execute each APPLET tag in __________ window.
4.Web browsers will allow _________ applet tag in a single page.
5.________ attribute specifies the base URL of the applet code.
6._________ is a required attribute that gives tha name of the file containing applets
compiled code.
7.___________ and ________ are required attributes that gives the size .
8.getParameters is used to return_________
9.getParameter returns the specified parameter in _______ object.
10.________tag allows to specify applet specifies argument in HTML page.
36
P1
P2
P3
P4
P5
P6
P7
P8
P9
10
P10
Batch-1
No
Batch-2
No
A1
B1
A2
B2
A3
B3
A4
B4
A5
B5
A6
B6
A7
B7
A8
B8
A9
B9
A10
B10
37
WEEK-4
Write a program that creates a user interface to perform integer divisions. The user
enters two numbers in the textfields, Num1 and Num2. The division of Num1 and
Num2 is displayed in the Result field when the Divide button is clicked. If Num1 or
Num2 were not an integer, the program would throw a NumberFormatException. If
Num2 were Zero, the program would throw an ArithmeticException. Display the
exception in a message dialog box.
1.AIM:
Program to create a user interface to perform integer divisions. The user enters two
numbers in the textfields, Num1 and Num2. The division of Num1 and Num2 is
displayed in the Result field when the Divide button is clicked. If Num1 or Num2 were
not an integer, the program would throw a NumberFormatException. If Num2 were Zero,
the program would throw an ArithmeticException. Display the exception in a message
dialog box.
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
Windows XP
JAVA
Version XP
2.THEORY:
The AWT supports a rich assortment of graphics methods.All graphics are drawn relative
to a window.this can the main windowof an applet, a child window of an applet,or a stand
alone application window. The origin of each window is at the top-left corner and is 0,0
cordinates are specified in pixels.All output to a window takes place through a graphics
context.
3.ALGORITHMS:
1. create an applet from extending Applet class.
2. Draw a line using drawLine()method.
3.Draw rectangle using drawRec() method.
4.Draw an ovel using drawOvel()method.
5.Include all these methods in the paint()method.
38
4.OBSERVATION:
Input: applet
Output:
Applet
7.APPLICATION:
->GUI application
-> Web application
8.EXTENSIONS:
We can use Graphics class to draw various shapes and also to color
39
9.DIAGNOSTICS:
S.NO
1.
Error
Error:Missing semicolon
2.
Error:cannot read
4.
Debugging
Go to the line number and
place semicolon at the end
of the statement
Dont divide the number
with zero
Make sure that the file is
present in the directory in
which u are executing it
Write the first character of
the System in capital letters
10.QUESTIONS:
1.setVisible() is used for __________
2.the title of the frame window can be changed using_________
3.The lines are drawn by means of ___________ method.
4._________displays an outlined rectangle.
5._________method displays a filled rectangle.
6.to draw rounded rectangle _________ method is used.
7.The delimiter of the rounding are along the x-axis is specified by _________
8. The delimiter of the rounding are along the x-axis is specified by _________
9.the dimensions of the rectangle are specified by _________ and _________
10.To draw an eclipse a ___________ method is used.
40
Batch-1
No
Batch-2
No
P1
A1
B1
P2
A2
B2
P3
A3
B3
P4
A4
B4
A5
B5
A6
B6
A7
B7
A8
B8
A9
B9
A10
B10
NegativeArraySizeException
P5
P6
P7
P8
P9
10
P10
41
WEEK-5
Write a Java program that implements a multi-thread application that has three threads.
First thread generates random integer every 1 second and if the value is even, second
thread computes the square of the number and prints. If the value is odd, the third thread
will print the value of cube of the number
1.AIM:
Creating a Java program that implements a multi-thread application that has three
threads. First thread generates random integer every 1 second and if the value is even,
second thread computes the square of the number and prints. If the value is odd, the third
thread will print the value of cube of the number
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
Windows XP
JAVA
Version XP
2.THEORY:
The java run-time system depends on the threads for many things, and all the class
libraries are designed with multithreading in mind. In fact,java uses threads to enable the
entire environment to be asynchronous.This helps reduce inefficiency by preventing the
waste of CPU cycles.
The benefits of javas multithreading is that the main loop/polling mechanism is
eliminated.one thread can pause without stopping other parts of your program.when a
thread blocks in ajava program,only the single thread that is blocked pauses.All other
threads continue to run.
3. ALGORITHMS:
1Create a thread class by implementing the Runnable interface.
2.Start the thread in the constructor.
42
4. OBSERVATION:
Input:
Output:
Square: 4
Cube : 21.
5. RESULT:
The values of the thread is executing will be printed
6. INFERENCES:
Multithreading is used to open several tasks simultaneously.Multithreading can be
implementing using Runnable interface or extending from Thread class
7. APPLICATION:
->Multitasking
->Multiprogramming
8. EXTENSIONS:
Priorities can also be assigned to the threads based on which the execution of
which thread first is decided
9.DIAGNOSTICS:
S.NO
1.
Error
Error:Missing semicolon
2.
Error:cannot read
Debugging
Go to the line number and
place semicolon at the end
of the statement
Dont divide the number
with zero
Make sure that the file is
present in the directory in
43
4.
10. QUESTIONS:
1.A multi thread programs contains two or more parts thet can run _________
2.A process is a program that is ____________
3.Multitasking threads require ___________ over head than multitasking process.
4.process are _________ tasks.
5.threads are _________ tasks.
6.Multithreading makes the maximum use of __________
7.___________ share the same address space.
8.A thread can be _________ when waiting for a resource.
9.A thread can be terminated which halts its _________
10.Contexts to switch is _________.
Batch-1
No
Batch-2
No
P1
A1
B1
P2
A2
B2
P3
A3
B3
44
P4
A4
B4
P5
A5
B5
P6
A6
B6
P7
A7
B7
P8
A8
B8
P9
A9
B9
10
P10
A10
B10
45
WEEK-6
Write a Java program that connects to a database using JDBC and does add, delete,
modify and retrieve operations
1.AIM:
Creating a Java program that connects to a database using JDBC and does add, delete,
modify and retrieve operations
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
Windows XP
JAVA
Version XP
2.THEORY:
JDBC is a Java database connectivity technology (Java Standard Edition
platform) from Oracle Corporation. This technology is an API for
the Java programming language that defines how a client may access a
database. It provides methods for querying and updating data in a database.
3. ALGORITHMS:
1Create a class by to connect to the database.
2.insert statement is implemented.
3.implement the select statement .
4.create the update statement
5.implement the delete statement
46
4. OBSERVATION:
Input:
Output:
Opened database successfully
Records created successfully
ID = 1
NAME = Paul
AGE = 32
ADDRESS = California
SALARY = 20000.0
ID = 2
NAME = Allen
AGE = 25
ADDRESS = Texas
SALARY = 15000.0
5. RESULT:
The values of the inserted can be retrieved.
6. INFERENCES:
With the help of JDBC connectivity we can perform operation on Java
applications
7. APPLICATION:
-> Java user interface Applications
8. EXTENSIONS:
Commit &Rollback operations also can be performed .
9.DIAGNOSTICS:
S.NO
Error
Debugging
47
1.
Error:Missing semicolon
2.
3
4.
10. QUESTIONS:
1. How many JDBC driver types does Sun define?_______
2. ________ is an open source DBMS product that runs on UNIX, Linux and Windows.
3. ___________JDBC driver Type(s) is(are) the JDBC-ODBC bridge?
4. JDBC stands for____________
5. The ............................. package contains classes that help in connecting to a database,
sending SQL statements to the database, and processing the query results.
6.The ................................ method executes a simple query and returns a single Result
Set object.
7.The ......................... method executes an SQL statement that may return multiple
results.
8. The ........................ object allows you to execute parametrized queries.
9. The .................. object provides you with methods to access data from the table.
10. The parameters of the PreparedStatement object are ...................... when the user
clicks on the Query button.
P1
P2
P3
Batch-1
No
Batch-2
No
A1
B1
A2
B2
A3
B3
A4
B4
A5
B5
To create a table
Creating a Java program that connects to a database using JDBC
Write a java program to retrieve an employe salary by its Id
Creating a Java program that connects to a database using JDBC
Write a java program to update an employe salary by its Id
P4
P5
48
P6
P7
P8
P9
10
P10
A6
B6
A7
B7
A8
B8
A9
B9
A10
B10
49
Week-7
JNTUH Program
7. Write a Java program that simulates a traffic light. The program lets the user
select one of three lights: red, yellow, or green with radio buttons. On selecting a
button, an appropriate message with Stop or Ready or Go should appear
above the buttons in selected color. Initially there is no message shown.
1.AIM:
write a java program that simulates trafficlight the program let user select one of three
lights ,thread yellowor green .when a radio button is select the light is turn ed one light
can be on at atime. No lights is on when the program starts.
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
JAVA
Windows XP
Version XP
2.THEORY:
The AWT supports a rich assortment of graphics methods.All graphics are drawn relative
to a window.this can the main windowof an applet, a child window of an applet,or a stand
alone application window. The origin of each window is at the top-left corner and is 0,0
cordinates are specified in pixels.All output to a window takes place through a graphics
context.
3.ALGORITHMS:
1. create an applet from extending Applet class.
2. Draw a line using drawLine()method.
3.Draw rectangle using drawRec() method.
4.Draw an ovel using drawOvel()method.
5.Include all these methods in the paint()method.
6.Display the line.rectangle and ovel.
50
Output:
Initial
READY
GO
STOP
4.OBSERVATION:
Input: applet
Output:
Applet
51
5.RESULT:
The above window will bw displayed.
6.INFERENCES:
The graphics class defines a number of drawing functions.Each shape can be drawn edge-only or
filled. Objects are drawn and filled in the currently selected graphics color,which is black by default
7.APPLICATION:
->GUI application
-> Web application
8.EXTENSIONS:
We can use Graphics class to draw various shapes and also to color
9.DIAGNOSTICS:
S.NO
1.
Error
Error:Missing semicolon
2.
Error:cannot read
4.
Debugging
Go to the line number and place
semicolon at the end of the
statement
Dont divide the number with
zero
Make sure that the file is present
in the directory in which u are
executing it
Write the first character of the
System in capital letters
10.QUESTIONS:
1.setVisible() is used for __________
2.the title of the frame window can be changed using_________
3.The lines are drawn by means of ___________ method.
4._________displays an outlined rectangle.
5._________method displays a filled rectangle.
6.to draw rounded rectangle _________ method is used.
7.The delimiter of the rounding are along the x-axis is specified by _________
8. The delimiter of the rounding are along the x-axis is specified by _________
9.the dimensions of the rectangle are specified by _________ and _________
10.To draw an eclipse a ___________ method is used.
52
P1
P2
P3
P4
P5
P6
P7
P8
Batch-1
No
Batch-2
No
A1
B1
A2
B2
A3
B3
A4
B4
A5
B5
A6
B6
A7
B7
A8
B8
53
P9
10
P10
A9
B9
A10
B10
54
WEEK-8
JNTUH Program-8
8. Write a java program to create an abstract class named Shape that contains two integers and an
empty method named printArea(). Provide three classes named Rectangle, Triangle and Circle
such that each one of the classes extends the class Shape. Each one of the classes contains only
the method printArea() that prints the area of the given shape.
1.AIM:
Write a java program to create an abstract class that illustrates different geometrical figures.
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
JAVA
Windows XP
Version XP
2. THEORY:
To create an abstract class that shows the hiding of elements in a class. At the same time inheritance
property is used to extend the class shape into different geometrical figures. This represents the
reusability of code for a programmer.
3. ALGORITHMS:
1.
2.
3.
4.
5.
6.
55
OUTPUT:
56
4. OBSERVATION:
Input: 1
Output: Prints the Rectangle Area
Input: 2
Output: Prints the Triangle Area
Input:
Output: Prints the Circle Area
57
5. RESULT:
The method in the subclasses will be displayed.
6. INFERENCES:
By abstracting we can hide the required data and implement in many classes by extending the
abstract class.
7. APPLICATION:
-> abstraction implementation
-> Inheritance implementation
8. EXTENSIONS:
Inheritance and abstractions are used
58
9. DIAGNOSTICS:
S.NO
1.
Error
Error: Missing semicolon
2.
4.
Debugging
Go to the line number and place
semicolon at the end of the
statement
Dont divide the number with
zero
Make sure that the file is present
in the directory in which u are
executing it
Write the first character of the
System in capital letters
10. QUESTIONS:
1. Polymorphism is a feature that allows _________
2. Polymorphism is expressed by the phrases one interface _______ methods.
3. Method override is the basis_________.
4. Java implements ________ using dynamic method dispatch.
5. A super class reference variable can refer to a __________ object.
6. The type of object being referred to determines which version of an ________method.
7. Override methods allows java to support _________
8. Method override occurs only when the names and the type signature of the two methods
are___________
9. When a method in the subclass has the same name and type as the method in the super class then the
method in the subclass is said to _________ the method in the super class.
10. Difference between overloading and overriding is __________
59
Problem
statement
No
P1
P2
P3
P4
P5
P6
P7
P8
P9
10
P10
Batch-1
No
Batch-2
No
A1
B1
A2
B2
A3
B3
A4
B4
A5
B5
A6
B6
A7
B7
A8
B8
A9
B9
A10
B10
60
WEEK-9
JNTUH Program -9
9. Suppose that a table named Table.txt is stored in a text file. The first line in the file is the
header, and the remaining lines correspond to rows in the table. The elements are separated by
commas. Write a java program to display the table using Labels in Grid Layout
1. AIM:
Write a java program to display the table using Grid Layout component
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
JAVA
Windows XP
Version XP
2. THEORY:
To create an table and display it using JTable components
3. ALGORITHMS:
1.create a class myjtable
2.declare a new Grid Layout
3.set default data and create columns
4.create new scroll pane and table
5.set the size and set visible methods
61
Output:
4. OBSERVATION:
Input: text file name
Output: table
5. RESULT:
The table will be displayed from given text file
6. INFERENCES:
By using JComponents we can display in required form
7. APPLICATION:
-> jscrollpane implementation
-> jcomponents implementation
8. EXTENSIONS:
Swings concepts are used
9. DIAGNOSTICS:
S.NO
Error
1.
Error:Missing semicolon
2.
Error:cannot read
4.
Debugging
Go to the line number and place
semicolon at the end of the
statement
Dont divide the number with
zero
Make sure that the file is present
in the directory in which u are
executing it
Write the first character of the
System in capital letters
10. QUESTIONS:
1. polymorphism is a feature that allows _________
2. polymorphism is expressed by the phrases one interface _______ methods.
3.Method override is the basis_________.
4.Java implements ________ using dynamic method dispatch.
5.A super class reference variable can refer to a __________ object.
6.The type of object being referred to determines which version of an _________ method.
7. Override methods allows java to support _________
62
8. Method override occurs only when the names and the type signature of the two methods
are___________
9. When a method in the subclass has the same name and type as the method in the super class then the
method in the subclass is said to _________ the method in the super class.
10. Difference between overloading and overriding is __________
PROBLEM DEFINITIONS DIFFERENT FROM JNTU TOPICS
S Problem
Name of the Experiment
No statemen
t
No
Suppose that a table named StudentTable.txt is stored in a text file.
1
P1
The first line in the file is the header, and the remaining lines
correspond to rows in the table. The elements are separated by
commas. Write a java program to display the table using Labels in
JTable.
Suppose that a table named EmployeeTable.txt is stored in a text
2
P2
file. The first line in the file is the header, and the remaining lines
correspond to rows in the table. The elements are separated by
commas. Write a java program to display the table using Labels in
Grid Layout
Suppose that a table named Employee Table.txt is stored in a text
3
P3
file. The first line in the file is the header, and the remaining lines
correspond to rows in the table. The elements are separated by
commas. Write a java program to display the table using Labels in
JTable.
Suppose that a table named VehicleTable.txt is stored in a text file.
4
P4
The first line in the file is the header, and the remaining lines
correspond to rows in the table. The elements are separated by
commas. Write a java program to display the table using Labels in
Grid Layout
Suppose that a table named VehicleTable.txt is stored in a text file.
5
P5
The first line in the file is the header, and the remaining lines
correspond to rows in the table. The elements are separated by
commas. Write a java program to display the table using Labels in
JTable.
Suppose that a table named AnimalTable.txt is stored in a text file.
6
P6
The first line in the file is the header, and the remaining lines
correspond to rows in the table. The elements are separated by
commas. Write a java program to display the table using Labels in
Grid Layout
Suppose that a table named AnimalTable.txt is stored in a text file.
7
P7
The first line in the file is the header, and the remaining lines
correspond to rows in the table. The elements are separated by
commas. Write a java program to display the table using Labels in
JTable.
Suppose that a table named MarksTable.txt is stored in a text file.
8
P8
The first line in the file is the header, and the remaining lines
correspond to rows in the table. The elements are separated by
Batch1
No
Batch2
No
A1
B1
A2
B2
A3
B3
A4
B4
A5
B5
A6
B6
A7
B7
A8
B8
63
P9
10
P10
A9
B9
A10
B10
64
WEEK-10
JNTUH Program-10
10. Write a Java program that handles all mouse events and shows the event name at the center of
the window when a mouse event is fired (Use Adapter classes).
1. AIM:
Write a java program for handling mouse events
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
JAVA
Windows XP
Version XP
2. THEORY:
To handle mouse events you must implement the MouseListener and the MouseMotionListener
interfaces.These two interfaces contain methods that receive and process the various types of mouse
events.
3. ALGORITHMS:
1create an applet extending from an applet class
2. In the init()method add both MouseListener and MouseMotionListener.
3. Extends the MouseAdapter and MouseMotionAdapter classes
3.Override the following
a) mouseClicked
b) mouseEntered
c) mouseExited
d)mousePressed
e) mouseReleased
f) mouseDregged
g)mouse Moved
4. Using showStatus method get the message .
5. Display the information on the screen.
65
OUTPUT:
66
4. OBSERVATION:
Input: press the mouse button on the applet
Output:
Applet |
Down
5. RESULT:
The above screen should be displayed.
6. INFERENCES:
MouseListener and MouseMotionListener are the interfaces to implement all the
methods for the mouse events.
7. APPLICATION:
->Web application
->Event handling
->GUI application
8. EXTENSIONS:
The most important feature of applets on the web, however, is the fact that applets change
the web from being a static medium to one based on interactivity with users. At present,
java is limited only by the capabilities of the internet itself .as the internet grows in data
transmission; java is ready to expand with it.
9. DIAGNOSTICS:
S.NO
1.
Error
Error:Missing semicolon
2.
Error:cannot read
4.
5.
Debugging
Go to the line number and
place semicolon at the end of
the statement
Dont divide the number
with zero
Make sure that the file is
present in the directory in
which u are executing it
Write the first character of
the System in capital letters
Override the method
67
mouseMethod()
10. QUESTIONS:
1. MOUSE_CLICKED events occurs when________
2. MOUSE_DRAGGED events occurs when ___________
3. __________ events occur when mouse enters a component.
4._________events occur when the mouse exists a component
5. MOUSE_MOVED event occurs when________
6. MOUSE_PRESSED even occurs when __________
7. The ________ events occur when mouse was released.
8. The ___________ event occurs when mouse wheel is moved.
9. An event source is _________
10. A _________ is an object that describes the state change in a source
68
WEEK-10
PROBLEM DEFINITIONS DIFFERENT FROM JNTU TOPICS
S
Proble
Name of the Experiment
Batch- BatchN
m
1
2
o stateme
No
No
nt
No
Write a Java program that handles all mouse events and set the
1
P1
A1
B1
color foreground to pink when a mouse event is fired (Use
Adapter classes).
Write a Java program that handles all mouse events and shows
2
P2
A2
B2
the image at the center of the window when a mouse event is
fired (Use Adapter classes).
Write a Java program to implement mouse event and shows the
3
P3
A3
B3
symbol star when ever user drags the mouse button (Use
Adapter classes).
Write a Java program to implement mouse event and shows the
4
P4
A4
B4
symbol dot when ever user drags the mouse button (Use
Adapter classes).
Write a Java program that handles all mouse events and shows
5
P5
A5
B5
the event name at the center of the window when a mouse event
is fired (without Adapter classes).
Write a Java program that handles all mouse events and set the
6
P6
A6
B6
color foreground to pink when a mouse event is fired (without
Adapter classes).
Write a Java program that handles all mouse events and shows
7
P7
A7
B7
the image at the center of the window when a mouse event is
fired (without Adapter classes).
Write a Java program to implement mouse event and shows the
8
P8
A8
B8
symbol star when ever user drags the mouse button (without
Adapter classes).
Write a Java program to implement mouse event and shows the
9
P9
A9
B9
symbol dot when ever user drags the mouse button (without
Adapter classes).
Write a Java program that handles all mouse events and shows
10
P10
A10
B10
the event name at the center of the window when a mouse event
is fired (without Adapter classes).
69
WEEK-11
Write a Java program that loads names and phone numbers from a text file where the data
is organized as one line per record and each field in a record are separated by a tab (\t). It
takes a name or phone number as input and prints the corresponding other value from the
hash table (hint: use hash tables).
AIM: Write a java program which can read text file into hash table and print the hash
values based on the hash key input.
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
ZORIN
JAVA
LINUX
2. THEORY:
Text file will contain names and phone numbers which are separated by a tab. This
information has to be recorded in to hash table.
3. ALGORITHMS:
1.create a text file which contains names and phone numbers separated by a tab
2.using buffer reader the file has to be read and the content has to be moved to hash table
using put method.
3. whenever a name is given the corresponding phone number from hash table has to be
displayed
70
4. OBSERVATION:
Input: RAM
Output: 123
5. RESULT:
Displays values from hash table by taking hash key as input
6. INFERENCES:
Hash table is useful in storing key value pairs. It can be populated dynamically
7. APPLICATION:
->Web application
->Data Processing and Analytics
8. EXTENSIONS:
Hash table can also be used to store data retrieved from Databases.
9. DIAGNOSTICS:
S.NO
1.
Error
Error:Missing semicolon
2.
Debugging
Go to the line number and
place semicolon at the end
of the statement
Dont divide the number
with zero
71
Error:cannot read
4.
10 .QUESTIONS:
1.___________is a package in which Hashtable class is available
2.split is a method used for _________________
3.capacity of hashtable can be determined by _______________
4._________ method is used to insert record in to hash table
5.________ method is used to know the number of entries in hash table
6.alternative to hashtable is ____________
7._____________ is used to remove all entries of hash table
8. Hash table can be enumerated using ______
9.Scanner class is present in _____________ package
10.Buffered Reader is available in _______ package
WEEK-11
PROBLEM DEFINITIONS DIFFERENT FROM JNTU TOPICS
S
No
Problem
statemen
t
No
P1
P2
P3
Batch1
No
Batch-2
No
Write a Java program that loads rollno and name from a text
file where the data is organized as one line per record and
each field in a record are separated by a tab (\t). It takes a
name or phone number as input and prints the
corresponding other value from the hash table (hint: use
hash tables).
Write a Java program that loads student name and branch
from a text file where the data is organized as one line per
record and each field in a record are separated by a tab (\t).
It takes a name or phone number as input and prints the
corresponding other value from the hash table (hint: use
hash tables).
Write a Java program that loads college code and college
name from a text file where the data is organized as one line
per record and each field in a record are separated by a tab
(\t). It takes a name or phone number as input and prints the
corresponding other value from the hash table (hint: use
hash tables).
A1
B1
A2
B2
A3
B3
72
P4
P5
P6
P7
P8
P9
10
P10
A4
B4
A5
B5
A6
B6
A7
B7
A8
B8
A9
B9
A10
B10
73
WEEK-12
Write a Java program that loads names and phone numbers from a database where the
data is organized as one line per record and each field in a record are separated by a tab
(\t). It takes a name or phone number as input and prints the corresponding other value
from the hash table (hint: use hash tables).
AIM: Write a java program which can read database into hash table and print the hash
values based on the hash key input.
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
ZORIN
JAVA
LINUX
2. THEORY:
A database table will contain names and phone numbers. This information has to be
recorded in to hash table.
3. ALGORITHMS:
1.create a table with two columns name and phone numbers. Fill some data.
2.connect to database using jdbc
3.retrieve data and store in to hash table
74
4. OBSERVATION:
Input: rammohan
Output: 987654321
5. RESULT:
Displays values from hash table by taking hash key as input
6. INFERENCES:
Hash table is useful in storing key value pairs. It can be populated dynamically
7. APPLICATION:
->Web application
->Data Processing and Analytics
8. EXTENSIONS:
Hash table can also be used to store data retrieved from Databases.
9. DIAGNOSTICS:
S.NO
1.
Error
Error:Missing semicolon
2.
Error:cannot read
Debugging
Go to the line number and
place semicolon at the end
of the statement
Dont divide the number
with zero
Make sure that the file is
75
4.
10 .QUESTIONS:
1.___________is a package in which sql related classes and methods are stored
2.forName is a __________ method
3.Class is a class found in ____________ package
4._________________ is the JDBC URL for oracle
5.________ method is used to execute select statements
6.most preferred jdbc driver is _________________
7._____________ is used to iterate the result set
8. ___________________ is the driver class for oracle
9.Scanner class is present in _____________ package
10._____________ is the port number used by oracle for non http clients
WEEK-12
PROBLEM DEFINITIONS DIFFERENT FROM JNTU TOPICS
S
No
Problem
statemen
t
No
P1
P2
P3
P4
Batch1
No
Batch-2
No
A1
B1
A2
B2
A3
B3
A4
B4
76
P5
P6
P7
P8
P9
10
P10
A5
B5
A6
B6
A7
B7
A8
B8
A9
B9
A10
B10
WEEK-13
77
Write a Java program that takes tab separated data (one record per line) from a text file
and inserts them into a database.
AIM: Write a java program which can read text file and insert the same into database
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
ZORIN
JAVA
LINUX
2. THEORY:
A text file with two fields will be read and is inserted into a database table.
3. ALGORITHMS:
1. Read text file line by line
2. Connect to database
3. Insert each line (separated with tab) as fields in to database
78
4. OBSERVATION:
Input: rammohan
Output: 987654321
4. RESULT:
All the records form text file are inserted into Database table
6. INFERENCES:
Databases are more effective than files and operating Databases is easy
7. APPLICATION:
->Web application
->Data Processing and Analytics
8. EXTENSIONS:
Database connection can be pooled in real time applications.
9. DIAGNOSTICS:
S.NO
1.
Error
Error:Missing semicolon
2.
Error:cannot read
Debugging
Go to the line number and
place semicolon at the end
of the statement
Dont divide the number
with zero
Make sure that the file is
79
4.
10 .QUESTIONS:
1.___________is a super class of all exception classes
2.forName returns _______________
3.newInstance method is in ___________ class
4._________________represents the connection listener in JDBC
5.________ method is used to execute non select statements
6.Driver software is provided by ____________
7.Result set object is used to ____________________
8. ___________________ is the object returned by getConnection method
9.to improve performance of JDBC operations _________ is used
10._____________ is the port number used by oracle for http clients
Problem
statemen
t
No
P1
Batch1
No
Batch-2
No
A1
B1
P2
A2
B2
P3
A3
B3
P4
A4
B4
P5
A5
B5
80
P6
A6
B6
P7
A7
B7
P7
A8
B8
P7
A9
B9
10
P7
A10
B10
81
WEEK-14
Write a Java program that prints meta data of a given table.
AIM: Write a java program which can read text file and insert the same into database
HARDWARE & SOFTWARE:
Hardware Requirements
Processor
Hard disk Drive
RAM
Keyboard
Monitor
CD ROM
Optical Mouse
Pentium IV
20GB
128MB
111keys Multimedia keyboard
15inches
Software Requirements
Operating System
ZORIN
JAVA
LINUX
2. THEORY:
Meta data is the data about data. Every table will have metadata. To print metadata of any
table ResultSet Metadata object is needed.
3. ALGORITHMS:
1. Connect to Db
2. Create ResultSetMetaData Object
3. Print details of meta data for a table.
82
OUTPUT:
4. OBSERVATION:
Output: prints no. of columns, column types etc about a table.
5. RESULT:
Meta data about a table is displayed
6. INFERENCES:
To know about the table and its properties meta data is useful
7. APPLICATION:
->Web application
->Data Processing and Analytics
8. EXTENSIONS:
Database connection can be pooled in real time applications.
9. DIAGNOSTICS:
S.NO
1.
Error
Error:Missing semicolon
2.
Debugging
Go to the line number and
place semicolon at the end
of the statement
Dont divide the number
with zero
83
Error:cannot read
4.
10 .QUESTIONS:
1.___________is a common exception in JDBC
2.ResutlSetMetaData is created using _______________
3.Data about data is called __________
4._________________is used to set the fetch size
5.autocommit should be turned ______
6.When more number of rows are inserted in same table _____________ is used
7.Result set object is used to ____________________
8. ___________________ is the object used for calling stored procedures
9.Types is a class contains ________
10._____________ is the method used to know the datatype of the columns
WEEK-14
PROBLEM DEFINITIONS DIFFERENT FROM JNTU TOPICS
S
No
Problem
statemen
t
No
P1
2
3
4
5
6
P2
P3
P4
P5
P6
P7
P7
P7
10
P7
Batch1
No
Batch-2
No
A1
B1
A2
A3
A4
A5
A6
B2
B3
B4
B5
B6
A7
B7
A8
B8
A9
B9
A10
B10
84