Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
555 views

Lab Manual JAVA

This document provides information about the Java lab manual for the Department of Information Technology at SMVEC. It includes the vision, mission, and objectives of the institute and department. It outlines the Java lab course details including prerequisites, objectives, outcomes, topics to be covered, textbooks, and websites for reference. It provides guidelines for students and details the objectives, requirements, and outcomes of the lab. It also includes a list of example programs for students to practice Java concepts like arrays, objects, inheritance, abstraction and more.

Uploaded by

sargunakamala
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
555 views

Lab Manual JAVA

This document provides information about the Java lab manual for the Department of Information Technology at SMVEC. It includes the vision, mission, and objectives of the institute and department. It outlines the Java lab course details including prerequisites, objectives, outcomes, topics to be covered, textbooks, and websites for reference. It provides guidelines for students and details the objectives, requirements, and outcomes of the lab. It also includes a list of example programs for students to practice Java concepts like arrays, objects, inheritance, abstraction and more.

Uploaded by

sargunakamala
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 133

Java Lab Manual

DEPARTMENT OF INFORMATION TECHNOLGY

P43 - JAVA LAB

Year: II Semester: IV

Even Semester - Dec 2018 – April 2019

Prepared by

R. Saravanan M.E, (Ph.D)


Asso. Prof, Dept of IT
N. Kalaiselvi M.Tech
Asst. Prof, Dept of IT
A.Sarkunavathi M.Tech,(Ph.D)
Asst. Prof, Dept of IT
SMVEC

SMVEC- Department of Information Technology 1


Java Lab Manual

VISION, MISSION AND PROGRAM EDUCATIONAL OBJECTIVES

To be a stimulating place to learn and practice technology and become a leading


college of
Vision of the
Engineering Nationally and Internationally recognized for its outstanding
Education,
Institute
Research and Outreach Programs
Foster the inbuilt qualities (M1): To foster the inbuilt qualities of the students
to face the
challenges of the new millennium.
Innovative Ideologies (M2): To provide an opportunity to explore and
experiment
Mission of
the innovative ideologies
Institute
Potential Dexterity (M3): To equip our students with the vital and potential
dexterity to
flourish in the corporate and industrial sectors
Excellence in Engineering (M4): To dilate as a center of relevance and
excellence in
Engineering and Technology
To produce dynamic and versatile software engineers adaptable to the every
increasing
Vision of the
demands of emerging technologies involving analytical and practical skills and
enabling
Department
them to face any challenges in the global network.
Competence (M1): To provide excellent IT engineers with strong analytical,
programming
and problem solving skills to meet the prerequisites of the existing world and
future
Mission of Exemplar (M2): To instil the institution ethics in their field to cope with the
the needs of
society
Department
Complaisant (M3): To accord a prompt and courteous professional in the IT
sector
Eminence (M4): To bring the overall personality development of students
for the
unmatched academic excellence in near future

SMVEC- Department of Information Technology 2


Java Lab Manual

Lectures Tutorials Practical


Subject Code Subject Name
(Periods) (Periods) (Periods)
IT-P43 Java Lab - - 9
Pre-requisite: Object oriented programming
Course Objectives:
1. To understand the basics of java
2. To write programs in Java covering the object oriented concepts.
3. To write programs covering advanced concepts in java like thread handling, applets, RMI
and JDBC

Course Outcomes: Students will learn how to write programs and develop projects in Java.
Develop Java programs to cover the following topics:
1. Simple Java program with one or more classes
2. Exception Handling
3. Inheritance
4. Packages
5. Interfaces
6. Event Handling
7. File Handling
8. Thread Handling
9. AWT controls/Java Swings/Struts framework
10. Applets
11. RMI
12. JDBC

Content beyond Syllabus:


Java’s support in graphics, networking, web technology etc.
Text Books:
1. The Complete Reference Java J2SE 5th Edition, Herbert Schildt, TMH Publishing Company
Ltd, NewDelhi.
2. Big Java 2nd Edition, Cay Horstmann, John Wiley and Sons.
Reference Books:
1. Java How to Program, Sixth Edition, H.M.Dietel and P.J.Dietel, Pearson Education/PHI
2. Core Java 2, Vol 1, Fundamentals, Cay.S.Horstmann and Gary Cornell, Seventh Edition, Pear-
son Education.
3. Core Java 2, Vol 2, Advanced Features, Cay.S.Horstmann and Gary Cornell, Seventh Edition,
Pearson Education.
Websites:
1. http://www.ibm.com/developerworks/java/
2. http://docs.oracle.com/javase/tutorial/rmi/.
3. IBM’s tutorials on Swings, AWT controls and JDBC.

SMVEC- Department of Information Technology 3


Java Lab Manual

Objectives

 To teach the students basics of JAVA programs and its execution.


 To teach the students the differences between C++ and Java programming.
 To make the students learn concepts like packages and interfaces.
 To make the students understand life cycle of the applets and its functionality.
 To make the students understand the usage util package.
 To teach the student, to develop java programs using JDBC and RMI.

Recommended System/Software Requirements

 Intel based desktop PC with minimum of 2.6GHZ or faster processor with at least 256 MB
RAM and 40GB free disk space.
 Operating system: WINDOWS.
 Software
o j2sdk1.7.
o MySQL.
o Eclipse or Net bean.

SMVEC- Department of Information Technology 4


Java Lab Manual

Guidelines to Students

 Equipment in the lab for the use of student community. Students need to maintain a proper
decorum in the computer lab. Students must use the equipment with care.
 Students are instructed to come to lab in formal dresses only.
 Students are supposed to occupy the systems allotted to them and are not supposed to talk
or make noise in the lab.
 Students are required to carry their observation book and lab records with completed
exercises while entering the lab.
 Lab records need to be submitted every week. 6. Students are not supposed to use pen
drives in the lab.

Lab Objective

 To introduce Java compiler and eclipse platform.


 To make the student learn an object oriented way of solving problems using java.
 To make the students to write programs using multithreading concepts and handle
exceptions.
 To make the students to write programs that connects to a database and be able to perform
various operations.
 To make the students to create the Graphical User Interface using Applets, AWT
Components & Swing Components.

Lab Outcome

 Able to use Java compiler and eclipse platform to write and execute java program.
 Understand and Apply Object oriented features and Java concepts.
 Able to apply the concept of multithreading and implement exception handling.
 Able to access data from a Database with java program.
 Develop applications using Console I/O and File I/O,GUI applications

SMVEC- Department of Information Technology 5


Java Lab Manual

LIST OF EXPERIMENTS

Practice Programs for Students

1. Write a program to print ―Hello World‖ on the screen.


2. Write a program that calculates how long it takes to drive from New York to Los Angeles
at mile per hour (Use 3000 miles as the approximate distance between two cities).Write a
program that creates and initializes a four-element int array. Calculate and display the av-
erage of its values.
3. Write a program that creates a 2-d array with int values the first element should be an ar-
ray containing 32. The second array should be an array containing 500 and 300 .The third
element should be an array containing 39.45 and 600.Declare, allocate and initialize the ar-
ray display its length and elements.
4. Write a program to swap two values using object reference. Your program should have a
swap function
5. To write a JAVA program to find the factorial of a given number.
6. Write a program that describes a class person. It should have instance variables to record
name, age and salary. Create a person object. Set and display its instance variables.
7. Write a program that creates a class circle with instance variables for the centre and the ra-
dius. Initialize and display its variables. Write a constructor in class circle to initialize its
variables.
8. Write a program to display the use of this keyword.
9. Write a program that can count the number of instances created for the class.
10. Write a program that implements method overloading.
11. Write a program that shows passing object as parameter.
12. Write a program that illustrates method overriding
13. Write a program to show that the value of non static variable is not visible to all the in-
stances, and therefore cannot be used to count the number of instances.
14. WAP to illustrate simple inheritance
15. Write a program illustrating a super class variable a referencing as sub class object.
16. Write a program illustrating all uses of super keywords.
17. Create an abstract class shape. Let rectangle and triangle inherit this shape class. Add ne-
cessary functions.
18. Write an application that creates a package p1. Add some classes in it. Write an applica-
tion that uses the package p1 created.
19. Write an application that creates an ‗interface‘ and implements it
20. Write an application that shows the usage of try, catch, throws and finally.
21. Write an application that shows how to create a user-defined exception.
22. Write an application that executes two threads. One thread displays ―An every 1000 mil-
liseconds and other displays ―B every 3000 milliseconds. Create the threads by extending
the Thread class.
23. Write an application that shows thread synchronization.
24. Write an application that displays deadlock between threads.
25. Write a program that read from a file and write to file.
26. Basic File handling program in java with reader/writer
27. Write an Applet that displays ―Hello World‖ (Background color-black, text color-blue
and your name in the status window.)
28. Write a program that displays the life cycle of an Applet.
29. Write an Applet displaying line, rectangle, rounded rectangle, filled rectangle, filled roun-
ded rectangle, circle, ellipse, arc, filled arc and polygon, all in different colors
30. Write an Applet that displays a counter in the middle of applet.
31. Write an Applet that displays a counter in the middle of applet. The counter starts from
zero and keeps on incrementing after every second.
SMVEC- Department of Information Technology 6
Java Lab Manual

32. Write an Applet that draws a dot at a random location in its display area every 200ms. Any
existing dots are not erased. Therefore dots accumulate as the applet executes.
33. Write an Applet that illustrates how to process mouse click, enter, exit, press and release
events. The background color changes when the mouse is entered, clicked, pressed, re-
leased or exited.
34. Write an Applet that displays your name whenever the mouse is clicked.
35. Use adapter classes to write an Applet those changes to cyan while the mouse is being
dragged. At all other times the applet should be white.
36. Write RMI based client-server programs.
37. Write programs of database connectivity using JDBC drivers.
38. Create a simple web page using HTML
39. Create a simple web page using Java Script(Client side Scripting)
40. Create a web application using Servlet

SMVEC- Department of Information Technology 7


Java Lab Manual

CONTENT BEYOND THE SYLLABUS

List of Advance experiments given to the students is summarized as below:


• A simple Calendar using Applet
• Creating a Paint Brush Using Applet
• HTML WEB Page Creation
• Java Script – Page Creation
• Servlet – Web application creation

SMVEC- Department of Information Technology 8


Java Lab Manual

PROJECTS TO BE ALLOTED

Students will be divided into a group of four/five and projects are allotted to those groups..

List of projects given to the students is summarized as below:



Moving ball with Java Script

Checker Board game with Java Script

Library Management System

Global Defender Game

Brick Game

Rapid Roll Game

Tic Tack Toe

NOTE: The project is to be made in Java Language preferably.

SMVEC- Department of Information Technology 9


Java Lab Manual

Each practical which student is performing in the lab should have the following details :
a) Program Name
b) Aim
c) Algorithm
d) Source Code
e) Output
f) Viva questions

SMVEC- Department of Information Technology 10


Java Lab Manual

MARKING SCHEME FOR THE PRACTICAL EXAMS

 Internal Practical Exam


 External Practical Exam

INTERNAL PRACTICAL EXAM

` It is taken by the concerned faculty of the batch.

MARKING SCHEME FOR INTENAL PRACTICAL EXAM

Regularity:
Performing program in each turn of the lab 40
Attendance of the lab
Record Submission
Viva Voce 10
Total 50

EXTERNAL PRACTICAL EXAM

It is taken by the concerned faculty of the batch and by an external examiner. In this exam
student needs to perform the experiment allotted at the time of the examination , viva voce
conducted and the paper is evaluated

Aim & Algorithm: 10

Program/Source Code 20

Execution & Output: 10

Viva Voice:: 10

Total 50

NOTE:

 Internal marks + External marks = Total marks given to the students


(50 marks) + (50 marks) = (100 marks)

 Experiments given to perform can be from any section of the lab.

SMVEC- Department of Information Technology 11


Java Lab Manual

Index
Pgm. Page
Date Program Name
No No.
Simple Java Programs

1 A. Simple Programs using Scanner 20

B. Reversing a Number 23

C. Factorial of a Number 25

2 Class and Objects

A. Class and Objects 28

B. Static Variable and Methods 30

C. Constructor 42

D. Function Overloading 45

E. Nested Classes 47

F. String Classes 50

3 Exception Handling

A. Multiple Catch Block 54


B. Array Index Out Of Bounds Excep-
57
tion
C. User Defined Exceptions 59

4 Inheritance

A. Single Inheritance 63

B. Hierarchical Inheritance 67

5 Package 72

6 Interface 76

7 Threads Programming

A. Multi-Threads 81

B. Runnable Interface 84

8 Applet Programming

A. Simple Applet 89

SMVEC- Department of Information Technology 12


Java Lab Manual

B. Event Handler 91

9 Colour Palette 96

10 Layouts

A. Border Layout 100

B. Flow Layout 102

10 AWT-Controls 104

11 Java Database Connectivity 109

12 Remote Method Invocation 114

Content Beyond the Syllabus

13 Java Script 119

SMVEC- Department of Information Technology 13


Java Lab Manual

Java Version

JAVA – Platform Independent

Integrated Development Environments


SMVEC- Department of Information Technology 14
Java Lab Manual

There are sophisticated IDEs for Java programming that are available.

 Eclipse IDE -- An increasingly popular professional development environment that sup-


ports Java development, among other things. Eclipse is itself written in Java. It is available
from http://www.eclipse.org/.
 NetBeans IDE -- A pure Java IDE that should run on any system with Java 1.7 or later.
NetBeans is a free, "open source" program. It is essentially the open source version of the
next IDE. It can be downloaded from www.netbeans.org.
 Sun ONE Studio 4 for Java, Community Edition, for Linux, Solaris, Windows 2000 to all
versions till 2010, Windows NT, and Windows 98SE. This was formerly known as "Forte
for Java", and it might be referred under that name. Again, it requires a lot of resources,
with a 256 MB memory recommendation. Main site currently at http://www.sun.com/soft-
ware/sundev/jde/index.html. It is available from there and on the J2SE download page,
http://java.sun.com/j2se/1.7/download.html. The Community Edition is the free version.
 Borland JBuilder Personal Edition, for Linux, Solaris, MacOS X, Windows 2000, Win-
dows XP, and Windows NT. Requires a lot of disk space & memory (256 MB memory re-
commended). Company Web page at http://www.borland.com. Jbuilder site at http://
www.borland.com/jbuilder/index.html. The Personal Edition, which is free, has more than
enough features for most programmers.
 BlueJ is a Java IDE written in Java that is meant particularly for educational use. It is
available from http://www.bluej.org/.
 JCreator, for Windows. It looks like a nice lighter-weight IDE that works on top of Sun's
SDK. There is a free version, as well as a shareware version. It is available at http://
www.jcreator.com.

There are other products similar to JCreator, for Windows and for other operating systems.

Using the Java SDK

SMVEC- Department of Information Technology 15


Java Lab Manual

After installing Oracles’ Software Development Kit for Java, one can use the commands "javac",
"java", and "appletviewer" for compiling and running Java programs and applets. These
commands must be on the "path" where the operating system searches for commands.

Make a directory to hold Java programs. Create program with a text editor, or copy the program to
be compiled into program directory

If program contains more than a few errors, most of them will scroll out of the window. In Linux
and UNIX, a command window usually has a scroll bar that can be used to review the errors. In
Windows 2000 to 2010/NT/XP (but not Windows 95/98), one can save the errors in a file which
can be viewed later in a text editor.

The command in Windows is

javac SourceFile.java >& errors.txt

The ">& errors.txt" redirects the output from the compiler to the file, instead of to the DOS
window. It is possible to compile all the Java files in a directory at one time. Use the command
"javac *.java".

After compiled class files are made, run application or applet. For running a stand-alone
application -- one that has a main ( ) routine -- use the "java" command from the SDK to run the
application. If the class file that contains the main ( ) routine is named Main. class, then run the
program with the command:

java Main

Updating the PATH Environment Variable


If you do not set the PATH variable, you need to specify the full path to the executable file every
time you run it, such as:
SMVEC- Department of Information Technology 16
Java Lab Manual

C:\> "C:\Program Files\Java\jdk1.7.0\bin\javac" MyClass.java


It is useful to set the PATH variable permanently so it will persist after rebooting.

To set the PATH variable permanently, add the full path of the jdk1.7.0\bin directory to


the PATH variable. Typically, this full path looks something like C:\Program Files\Java\jdk1.8.0\
bin. Set the PATH variable as follows on Microsoft Windows:

1. Click Start, then Control Panel, then System.

2. Click Advanced, then Environment Variables.

3. Add the location of the bin folder of the JDK installation to the PATH variable in System


Variables. The following is a typical value for the PATH variable:

4. C:\WINDOWS\system32;C:\WINDOWS;C:\Program Files\Java\jdk1.7.0\bin
Note:

 The PATH environment variable is a series of directories separated by semicolons (;)


and is not case-sensitive. Microsoft Windows looks for programs in the PATH direc-
tories in order, from left to right.

 You should only have one bin directory for a JDK in the path at a time. Those following
the first instance are ignored.

 If you are not sure where to add the JDK path, append it.

 The new path takes effect in each new command window you open after setting
the PATH variable.

Steps to write JAVA Program

1. Create JAVA file by text editor (eg Notepad++).

SMVEC- Department of Information Technology 17


Java Lab Manual

2. Write the program as per JAVA syntax.

3. Save the file with .java extension.

4. Compile the file with JAVA compiler (javac filename.java) and create class file.

5. Run the class file with JAVA interpreter (java classname.class) and check the output.

Simple Java Program

Program : To Print a message


SMVEC- Department of Information Technology 18
Java Lab Manual

public class Message


{
public static void main(String[] args) {
System.out.println("Java Programming");
}
}

Compile and run your Java program

To compile
javac Message.java

To Execute
java Message

Output
Java Programming

SMVEC- Department of Information Technology 19


Java Lab Manual

Simple Programs

SMVEC- Department of Information Technology 20


Java Lab Manual

Ex. No.:1(a) Simple Java Programs using Scanner

Aim

To write a JAVA program to get and display multiple inputs.

Algorithm

1. Declare the class.


2. Import the packages.
3. Get multiple inputs using Scanner.
4. Print the output.

Code

import java.io.*;
import java.util.*;

class Inputs
{
public static void main(String args[])
{
int a;
float b;
String c;
double d;
String e;
Scanner inp=new Scanner(System.in);

System.out.print("\nEnter an Integer number : ");


a=inp.nextInt();

System.out.print("Enter a Float number : ");


b=inp.nextFloat();

System.out.print("Enter a String : ");


c=inp.next();

System.out.print("Enter a Double number : ");


d=inp.nextDouble();

System.out.print("Enter a Line : ");


e=inp.nextLine();
e=inp.nextLine();

System.out.printl21n("\nThe variables are ");


System.out.println("\nInteger a = "+a);
SMVEC- Department of Information Technology 21
Java Lab Manual

System.out.println("\nFloat b = "+b);
System.out.println("\nString c = "+c);
System.out.println("\nDouble d = "+d);
System.out.println("\nLine e = "+e);
}

SMVEC- Department of Information Technology 22


Java Lab Manual

OUTPUT:

RESULT

The multiple input java program has been executed successfully.

Ex. No.:1(b) Reversing Given Number


SMVEC- Department of Information Technology 23
Java Lab Manual

AIM

To write a JAVA program to find the reverse of the given number.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Get multiple inputs using Scanner.
4. Print the output.

CODE

mport java.io.*;
import java.util.Scanner;

class NumRev
{
public static void main(String args[])
{
int n,rev=0;
System.out.println(" Number Reverse Program In Java ");
System.out.print(" Enter a number : ");
Scanner inp = new Scanner (System.in);
n = inp.nextInt();
while(n!=0)
{
rev=rev*10;
rev=rev+n%10;
n=n/10;
}
System.out.println("Reversed number is : "+rev);
}
}

SMVEC- Department of Information Technology 24


Java Lab Manual

OUTPUT

RESULT:

The reverse a number program has been executed successfully.

SMVEC- Department of Information Technology 25


Java Lab Manual

Ex.No.:1(c) Factorial of a Number

AIM

To write a JAVA program to find the factorial of a given number.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Use factorial logic in a for loop.
4. Print the output.

PROGRAM:
import java.io.*;
import java.util.Scanner;

public class Factorial


{
public static int fact(int x)
{
if(x==1)
return 1;
else
return(fact(x-1)*x);
}

public static void main(String[] args)


{
int n,result;
Scanner in=new Scanner(System.in);
System.out.print("Enter the number : ");
n=in.nextInt();
result=fact(n);
System.out.println("The factorial of " +n + " is " + result);
}
}

SMVEC- Department of Information Technology 26


Java Lab Manual

OUTPUT:

RESULT:

The JAVA program to find factorial of a given number has been executed successfully.

SMVEC- Department of Information Technology 27


Java Lab Manual

Java – Class and Objects

SMVEC- Department of Information Technology 28


Java Lab Manual

Ex.No.:1(d) Class and Objects

AIM

To write a JAVA program to understand class and objects.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Declare and define functions getdata() and display().
4. Print the output.

PROGRAM

import java.io.*;
class Student3
{
int Sno;
String Sname;
public void getdata(int x,String y)
{
Sno=x;
Sname=y;
}
public void display()
{
System.out.print("\n"+Sno);
System.out.println(" "+Sname);
}
public static void main(String args[])
{
Student3 S1=new Student3();
S1.getdata(15,"Aravindan");
Student3 S2=new Student3();
S2.getdata(30,"Prabhakar");
System.out.println("\nStudent Details");
S1.display();
S2.display();
}
}

SMVEC- Department of Information Technology 29


Java Lab Manual

OUTPUT

RESULT

The JAVA program to understand class and object has been executed successfully.

SMVEC- Department of Information Technology 30


Java Lab Manual

Ex.No.:1(e) Static Variable

AIM

To write a JAVA program to understand static variable functionality.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Declare static variable count=0.
4. Declare and define function increment() to increment count value.
5. Display the output.

PROGRAM

import java.io.*;

class Staticv
{
static int count=0;

public void increment()


{
count++;
}

public static void main(String args[])


{
Staticv obj1=new Staticv();
Staticv obj2=new Staticv();
Staticv obj3=new Staticv();

obj1.increment();
obj2.increment();

System.out.println("Obj1: count is= "+obj1.count);


System.out.println("Obj2: count is= "+obj2.count);

obj3.increment();
System.out.println("Obj3: count is= "+obj3.count);

SMVEC- Department of Information Technology 31


Java Lab Manual

OUTPUT

RESULT

The JAVA program using static variable has been executed successfully.

SMVEC- Department of Information Technology 32


Java Lab Manual

Java Question – Objective Type

SMVEC- Department of Information Technology 33


Java Lab Manual

Java Question – Oracle Dump Questions

QUESTION: 1

Given
4. String #name = "Jane Doe";
5. int $age = 24;
6. Double _height = 123.5;
7. double ~temp = 37.5;

Which two statements are true? (Choose two.)

A. Line 35 will not compile.


B. Line 36 will not compile.
C. Line 37 will not compile.
D. Line 38 will not compile.

QUESTION: 2

Which are valid declarations? (Choose all that apply.)


A. int $x;
B. int 123;
C. int _123;
D. int #dim;
E. int %percent;
F. int *divide;
G. int central_sales_region_Summer_2005_gross_sales;

QUESTION: 3

Given:
• public class LineUp {
• public static void main(String[] args) {
• double d = 12.345;
• // insert code here
• }
• }

Which code fragment, inserted at line 4, produces the output | 12.345|?


1. System.out.printf("|%7d| \n", d);
2. System.out.printf("|%7f| \n", d);
3. System.out.printf("|%3.7d| \n", d);
4. System.out.printf("|%3.7f| \n", d);
5. System.out.printf("|%7.3d| \n", d);
6. System.out.printf("|%7.3f| \n", d);

SMVEC- Department of Information Technology 34


Java Lab Manual

QUESTION: 4

Given:
• public class TestString1 {
• public static void main(String[] args) {
• String str = "420";
• str += 42;
• System.out.print(str);
• }
• }

What is the output?


1. 42
2. 420
3. 462
4. 42042
5. Compilation fails.
6. An exception is thrown at runtime.

QUESTION: 5

Given:
• public class Mud {
• //insert code here
• System.out.println("h
i"); }
• }
And the following five fragments:
public static void main(String...a)
{ public static void main(String.* a)
{ public static void main(String... a)
{ public static void main(String[]... a)
{ public static void main(String...[] a)
{

How many of the code fragments, inserted independently at line 2, compile?


1. 0
2. 1
3. 2
4. 3
5. 4
6. 5

QUESTION: 6

Given:
class Hexy {
public static void main(String[] args) {
Integer i = 42;
String s = (i<40)?"life":(i>50)?"universe":"everything";
System.out.println(s);
}}

SMVEC- Department of Information Technology 35


Java Lab Manual

What is the result?


1. null
2. life
3. universe
4. everything
5. Compilation fails.
6. An exception is thrown at runtime.

QUESTION: 7

Given:
class Feline {
public static void main(String[] args) {
Long x = 42L;
Long y = 44L;
System.out.print(" " + 7 + 2 + " ");
System.out.print(foo() + x + 5 + " ");
System.out.println(x + y + foo());
}
static String foo() { return "foo"; }
}

What is the result?


A. 9 foo47 86foo
B. 9 foo47 4244foo
C. 9 foo425 86foo
D. 9 foo425 4244foo
E. 72 foo47 86foo
F. 72 foo47 4244foo
G. 72 foo425 86foo
H. 72 foo425 4244foo
I. Compilation fails.
QUESTION: 8

Given:
class Maybe {
public static void main(String[] args) {
boolean b1 = true;
boolean b2 = false;

System.out.print(!false ^ false);
System.out.print(" " + (!b1 & (b2 = true)));
System.out.println(" " + (b2 ^ b1));
}
}

SMVEC- Department of Information Technology 36


Java Lab Manual

Which are true?


A. Line 5 produces true.
B. Line 5 produces false.
C. Line 6 produces true.
D. Line 6 produces false.
E. Line 7 produces true.
F. Line 7 produces false.

QUESTION: 9
Given:
class Sixties {
public static void main(String[] args) {
int x = 5;
int y = 7;
System.out.print(((y * 2) % x));
System.out.print(" " + (y % x));
}
}

What is the result?


A. 1 1
B. 1 2
C. 2 1
D. 2 2
E. 4 1
F. 4 2
G. Compilation fails.
H. An exception is thrown at runtime

SMVEC- Department of Information Technology 37


Java Lab Manual

QUESTION: 10
Given:
public class Bar {
static void foo( int... x ) {
// insert code here
}
}
Which two code fragments, inserted independently at line 12, will allow the class to
compile? (Choose two.)
A. foreach( x ) System.out.println(z);
B. for( int z : x ) System.out.println(z);
C. while( x.hasNext() ) System.out.println( x.next() );
D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]);

SMVEC- Department of Information Technology 38


Java Lab Manual

JAVA Question – Oracle Dump Questions

QUESTION: 1
Given:
public class Hello {
String title;
int value;
public Hello() {
title += " World";
}
public Hello(int value) {
this.value = value;
title = "Hello";
Hello();
}
} and:
Hello c = new Hello(5);
System.out.println(c.title);

What is the result?


1. Hello
2. Hello World
3. Compilation fails.
4. Hello World 5
5. The code runs with no output.
6. An exception is thrown at runtime.

QUESTION: 2
Given:
class Foo {
static void alpha() { /* more code here */ }
void beta() { /* more code here */ }
}

Which two statements are true? (Choose two.)


A. Foo.beta() is a valid invocation of beta().
B. Foo.alpha() is a valid invocation of alpha().
C. Method beta() can directly call method alpha().
D. Method alpha() can directly call method beta().

QUESTION: 3
Given:
public class ItemTest {
private final int id;
public ItemTest(int id) { this.id = id; }
public void updateId(int newId) { id = newId; }

public static void main(String[] args) {


ItemTest fa = new ItemTest(42);
fa.updateId(69);
System.out.println(fa.id);
}
SMVEC- Department of Information Technology 39
Java Lab Manual

SMVEC- Department of Information Technology 40


Java Lab Manual

What is the result?


A. Compilation fails.
B. An exception is thrown at runtime.
C. The attribute id in the ItemTest object remains unchanged.
D. The attribute id in the ItemTest object is modified to the new value.
E. A new ItemTest object is created with the preferred value in the id attribute.

QUESTION: 4
Given:
/ class Snoochy {
/ Boochy booch;
/ public Snoochy() { booch = new Boochy(this); }
/ }
/ class Boochy {
/ Snoochy snooch;
/ public Boochy(Snoochy s) { snooch = s; }
/ }
And the statements:
public static void main(String[] args) {
Snoochy snoog = new Snoochy();
snoog = null;
// more code here
}

Which statement is true about the objects referenced by snoog, snooch, and booch immediately
after line 23 executes?
A. None of these objects are eligible for garbage collection.
B. Only the object referenced by booch is eligible for garbage collection.
C. Only the object referenced by snoog is eligible for garbage collection.
D. Only the object referenced by snooch is eligible for garbage collection.
E. The objects referenced by snooch and booch are eligible for garbage collection.

SMVEC- Department of Information Technology 41


QUESTION: 5
Given:
class Voop {
public static void main(String[] args) {
doStuff(1);
doStuff(1,2);
}

// insert code here


}

Which, inserted independently at line 6, will compile? (Choose all that apply.)
A. static void doStuff(int... doArgs) { }
B. static void doStuff(int[] doArgs) { }
C. static void doStuff(int doArgs...) { }
D. static void doStuff(int... doArgs, int y) { }
E. static void doStuff(int x, int... doArgs) { }

QUESTION: 6
public class A
{
private int counter=0;
public static int getInstanceCount()
{
return counter;
}
public A()
{
counter++;
}
}
Given this code from Class B:
A a1 = new A();
A a2 = new A();
A a3 = new A();
System.out.println(A.getInstanceCount());

What is the result?


A. Compilation of class A fails.
B. Line 28 prints the value 3 to System.out.
C. Line 28 prints the value 1 to System.out.
D. A runtime error occurs when line 25 executes.
E. Compilation fails because of an error on line 28.

QUESTION: 7
Given:
public class Batman {
int squares = 81;
public static void main(String[] args) {
new Batman().go();
}
void go() {
incr(++squares);
System.out.println(squares);
}
void incr(int squares) { squares += 10; }
}

What is the result?


1. 81
2. 82
3. 91
4. 92
5. Compilation fails.
6. An exception is thrown at runtime.
QUESTION: 9
Given:
/ public class Pass {
/ public static void main(String [] args) {
/ int x = 5;
/ Pass p = new Pass();
/ p.doStuff(x);
/ System.out.print(" main x = " + x);
}
/ void doStuff(int x) {
/ System.out.print(" doStuff x = " + x+
+); }
}

What is the result?


A. Compilation fails.
B. An exception is thrown at runtime.
C. doStuff x = 6 main x = 6
D. doStuff x = 5 main x = 5
E. doStuff x = 5 main x = 6
F. doStuff x = 6 main x = 5

QUESTION: 10
Given:
/ public class ClassA {
/ public int getValue() {
int value=0;
boolean setting = true;
String title=”Hello”;
if (value || (setting && title == “Hello”)) { return 1; }
if (value == 1 & title.equals(”Hello”)) { return 2; }
}
}
And:
ClassA a = new ClassA();
a.getValue();

What is the result?


1. 1
2. 2
3. Compilation fails.
4. The code runs with no output.
5. An exception is thrown at runtime.
Java – Constructor

42
Ex.No.:1(f) Constructor

AIM

To write a JAVA program to understand the concept of constructor.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Declare the variables.
4. Declare and define the constructor.
5. Declare and define function display.
6. Display the output.

PROGRAM

import java.io.*;

class Student1
{

int Sno;
String Sname;
public Student1( int no, String name)
{
Sno = no ;
Sname = name ;
}

public static void main(String args[])


{
Student1 S1 = new Student1( 10 , "Aravind" );
S1.display();
}

public void display()


{
System.out.println(Sno);
System.out.println(Sname);
}

43
OUTPUT:

RESULT

The constructor program has been executed successfully.

44
Ex.No.:(g) Function Overloading

AIM

To write a JAVA program to understand the concept of overloading in functions.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Declare the variables.
4. Declare and define the function sum() having 2 arguments.
5. Declare and define function sum() having 3 arguments.
6. Display the output.

PROGRAM

import java.io.*;
import java.util.Scanner;
class Add
{
public void sum(int a,int b)
{
System.out.println("Sum is : "+(a+b));
}
public void sum(int a,int b,int c)
{
System.out.println("Sum is : "+(a+b+c));
}

public static void main(String args[])


{
int ch,a,b,c;
Add a1= new Add();
Scanner s=new Scanner(System.in);
System.out.println("Enter the choice of addition (2 or 3)");
ch=s.nextInt();
System.out.print("Enter the inputs : ");
switch(ch)
{
case 2:
a=s.nextInt();
b=s.nextInt();
a1.sum(a,b);
break;
case 3:
a=s.nextInt();
b=s.nextInt();
c=s.nextInt();
a1.sum(a,b,c);

45
break;
default:
System.out.println("Enter valid choice");
}
}

OUTPUT

RESULT

The function overloading program has been executed successfully.

46
Ex.No.:1(h) Nested Class

AIM

To write a JAVA program to understand the concept of nested class.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Declare the variables and define another class within it.
4. Declare and define function print() in it.
5. Declare and define constructor having 2 arguments.
6. Display the output.

47
PROGRAM

class OuterDemo
{
int num;

private class InnerDemo


{
public void print()
{
System.out.println("This is an inner class");
}
}

void displayInner()
{
InnerDemo inner = new InnerDemo();
inner.print();
}
}

class Myclass
{
public static void main(String args[])
{
OuterDemo outer=new OuterDemo();
outer.displayInner();
}

48
OUTPUT:

RESULT

The nested class program has been executed successfully.

49
Ex.No.:1(i) String Class

AIM

To write a JAVA program to understand the concept of string class.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Declare the variables and assign them strings.
4. Check whether the two variables are equal using string class function equals().
5. Display the output.

PROGRAM

public class MyStringEquals


{
public static void main(String a[])
{
String x = "Hello";
String y = "hello";
if(x.equals(y))
{
System.out.println("Both strings are equal in case-sensitive block.");
}
else
{
System.out.println("Both strings are not equal in case-sensitive block.");
}

if(x.equalsIgnoreCase(y))
{
System.out.println("Both strings are equal in Ignore case block.");
}
else
{
System.out.println("Both strings are not equal Ignore case block.");
}
}
}

50
OUTPUT

RESULT

The string class program has been executed successfully.

51
Practice Exercises:

1. Write a Java program to generate Fibonacci series.


2. Write a Java program that prompts the user for an integer and then prints out all the prime
numbers up to that Integer.
3. Write a Java program that checks whether a given string is a palindrome or not. Ex: MADAM
is a palindrome.
4. Write a Java Program to define a class with constructor and instantiate its object.
5. Write a Java Program to implement array of objects.

52
Java – Exception Handling

53
Ex.No.:2(a) Exception Handling - Multiple Catch

AIM

To write a JAVA program to understand the concept of exception handling using multiple
catch.

ALGORITHM

1. Declare the class.


2. Declare the variables.
3. Code the main concept in try-catch block for exception handling.
4. Display the output as exception.

PROGRAM

import java.io.*;
import java.util.*;

public class MultipleCatch


{
public static void main(String args[])
{
int array[]=new int[3];
int result,n,d;
Scanner s = new Scanner(System.in);
System.out.println("\n\t Division.... !");
System.out.print("Enter the no of dividends : ");
n=s.nextInt();
System.out.print("Enter the dividends : ");
for(int i=0;i<n;i++)
{
array[i]= s.nextInt();
}
System.out.print("Enter the divisor : ");
d=s.nextInt();
try
{
for(int i=0;i<n;i++)
{
result = array[i]/d;
System.out.println("The result of dividing "+array[i]+" is " +result);
}
}

54
catch (ArrayIndexOutOfBoundsException e)
{
System.out.println("Array is out of Bounds" +e);
}
catch (ArithmeticException e)
{
System.out.println ("Can't divide by Zero" +e);
}
catch(Exception e)
{
System.out.println("Exception caught");
}
}
}

55
OUTPUT

RESULT

The Multiple exception catch program has been executed successfully.

56
Ex.No.:2(b) Exception Handling - Array Index Out Of Bound

AIM

To write a JAVA program to understand the concept of exception handling for array index out
of bound exception.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Declare the variables in array.
4. Increment the array variable in a for loop.
5. Display the output as exception.

PROGRAM

import java.io.*;
import java.util.Scanner;
public class SingleArray
{
public static void main(String[]args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter number of elements");
int n=s.nextInt();
int arr[]=new int[5];
System.out.println("Enter elements");
for(int i=0;i<n;i++)
{
arr[i]=s.nextInt();
}
System.out.println("The numbers are ...");
for(int i = 0; i <n; i++)
{
System.out.println(".."+arr[i]);
}
}
}

57
OUTPUT:

RESULT

The Array index out of bound exception program has been executed successfully.

58
Ex.No.:2(c) User Defined Exception

AIM

To write a JAVA program to understand the concept of exception handling using user defined
exception.

ALGORITHM

1. Declare the class.


2. Declare the variables.
3. Code the main concept in try-catch block for exception handling.
4. Display the output as exception.

PROGRAM

import java.io.*;
import java.util.Scanner;

class InvalidAgeException extends Exception


{
InvalidAgeException (String s)
{
super(s);
}
}
class TestException
{
static void validate(int age) throws InvalidAgeException
{
if(age<18)
{
throw new InvalidAgeException("Not Eligible to vote !!!");
}
else
{
System.out.println("Eligible to Vote..");
}
}

59
public static void main(String args[])
{
int a;
Scanner s=new Scanner(System.in);
System.out.print("\nEnter Your Age : ");
a=s.nextInt();
try
{
validate(a);
}
catch(Exception m)
{
System.out.println("Exception Occured : "+m);
}
}
}

60
OUTPUT:

RESULT

The user defined exception program has been executed successfully.

61
Java – Inheritance

62
Ex.No.:3(a) Single Inheritance

AIM

To write a JAVA program to understand the concept of single inheritance.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Declare another class that inherits base class.
4. Perform the tasks.
5. Display the output .

PROGRAM

import java.io.*;
import java.util.Scanner;

class Student
{
public
int regno;
int year;
String name;
public void method()

{
Scanner ob = new Scanner(System.in);
System.out.print("Enter student name:");
name=ob.nextLine();
System.out.print("Enter register number:");
regno=ob.nextInt();
System.out.print("Enter year:");
year=ob.nextInt();
}

63
class Marks extends Student
{
int arr[]=new int[5],tot;
public void method2()
{
Scanner ob = new Scanner(System.in);
System.out.print("Enter Student marks : ");
for (int i=0;i<5;i++)
{
arr[i]=ob.nextInt();
tot = tot + arr[i];
}

public void display()


{
System.out.println("\t\t\t *****STUDENT DETAILS*****");
System.out.println("Name :"+name);
System.out.println("Register number:"+regno);
System.out.println("Year:"+year);
System.out.println("Total Marks Obtained :"+tot);

}
public static void main(String[] arg)
{
Marks s=new Marks();
s.method();
s.method2();
s.display();
}

64
OUTPUT:

RESULT

The single inheritance program has been executed successfully.

65
Ex.No.:3(b) Inheritance – Hierarchical

AIM

To write a JAVA program to understand the concept of hierarchical inheritance.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Create another class that inherits main class.
4. Create another class that inherits the sub class..
5. Perform the tasks.
6. Display the output as exception.

PROGRAM

import java.io.*;
import java.util.Scanner;

class Player
{
public
int number;
String name;
String role;
String country;
public void method()

{
Scanner ob = new Scanner(System.in);
System.out.print("Enter player name :");
name=ob.nextLine();
System.out.print("Enter Jersey number :");
number=ob.nextInt();
System.out.print("Enter the Nationality :");
country=ob.nextLine();
country=ob.nextLine();
}

66
class Batsman extends Player
{
float avg;
public void method1()
{
Scanner ob = new Scanner(System.in);
System.out.print("Enter the Role of Batsman :");
role=ob.nextLine();
System.out.print("Enter Batting Average:");
avg=ob.nextFloat();
}

public void display()


{
System.out.println("\n\t\t\t\t *Batsman Details*");
System.out.println("Name : "+name);
System.out.println("Jersey Number : "+number);
System.out.println("Nationality : "+country);
System.out.println("Specialist : "+role);
System.out.println("Batting Average : "+avg);
}
}

class Bowler extends Player


{
float avgb,eco;
public void method2()
{
Scanner ob = new Scanner(System.in);
System.out.print("Enter Bowling type : ");
role=ob.nextLine();
System.out.print("Enter Bowling average : ");
avgb=ob.nextFloat();
System.out.print("Enter Economy :");
eco=ob.nextFloat();
}
public void display()
{
System.out.println("\n\t\t\t\t *Bowlwer Details*");
System.out.println("Name : "+name);
System.out.println("Jersey Number : "+number);
System.out.println("Nationality : "+country);
System.out.println("Specialist : "+role);
System.out.println("Bowling Average : "+avgb);
System.out.println("Economy : "+eco);
}
}

67
class Heirarchical
{
public static void main(String[] arg)
{
Batsman ba=new Batsman();
Bowler bo=new Bowler();
System.out.println("Batsman Details ... ");
ba.method();
ba.method1();
System.out.println("Bowler Details .... ");
bo.method();
bo.method2();
System.out.println("\n\t\t\t *****PLAYER'S DETAILS*****");
ba.display();
bo.display();
}
}

68
OUTPUT

RESULT

The hierarchical inheritance program has been executed successfully.

69
Practice Exercise:

1. Write a Java Program to implement multilevel inheritance by applying various access


controls to its data members and methods.

70
Java – Packages

71
Ex.No.:4 Package

AIM

To write a JAVA program to understand the concept of package.

ALGORITHM

1. Declare the class.


2. Import the packages.
3. Make this class as package.
4. Declare another class.
5. Import the package class that we created in this class.
6. Display the output.

PROGRAM

package pack;
import java.io.*;
public class Compute
{
int a,b;
public void add(int a,int b)
{
System.out.println("The result of addition is :" +(a+b));
}
public void sub(int a,int b)
{
System.out.println("The result of subtraction is :" +(a-b));
}
public void mul(int a,int b)
{
System.out.println("The result of multiplication is :" +(a*b));
}
public void div(int a,int b)
{
System.out.println("The result of division is :" +(a/b));
}
}

72
import pack.Compute;
import java.io.*;
import java.util.Scanner;
class Calculate
{
public static void main(String args[])
{
int a,b,ch;
Scanner s1=new Scanner(System.in);
System.out.println("Enter two numnber : ");
System.out.print(" A : ");
a=s1.nextInt();
System.out.print(" B : ");
b=s1.nextInt();
System.out.println("Enter the operation to be performed : ");
System.out.println(" 1. Addition \n 2. Subtraction" );
System.out.println(" 3. Multiplication \n 4. Division ");
System.out.print("Enter the choice :");
ch=s1.nextInt();
Compute c=new Compute();
switch(ch)
{
case 1: c.add(a,b);
break;
case 2: c.sub(a,b);
break;
case 3: c.mul(a,b);
break;
case 4: c.div(a,b);
break;
default: System.out.println("Invalid choice...");
}
}
}

73
OUTPUT:

RESULT

The package program has been executed successfully.

74
Java – Interface

75
Ex.No.:5 Interface

AIM

To write a JAVA program to understand the concept of interfaces.

ALGORITHM

1. Declare and define an interface.


2. Declare class that implements the interface.
3. Display the output.

PROGRAM

interface ISports
{
public void SetTeam(String t1,String t2, int score1, int score2);
public void ShowResult();
}

class Cricket implements ISports


{
String team1,team2;
int team1Runs,team2Runs;
public void SetTeam(String t1,String t2, int r1, int r2)
{
team1 = t1;
team2 = t2;
team1Runs = r1;
team2Runs = r2;
}

public void ShowResult()


{
System.out.println("\t\t\t*Cricket*");
System.out.println("\t" +team1 + " - " + team1Runs + " Runs");
System.out.println("\t" +team2 + " - " + team2Runs + " Runs");
if(team1Runs>team2Runs)
{
System.out.println("\t"+team1+" Won");
}

76
else
{
System.out.println("\t"+team2+" Won");
}
}
}

class Hockey implements ISports


{
String team1,team2;
int team1Goals,team2Goals;
public void SetTeam(String t1,String t2, int r1, int r2)
{
team1 = t1;
team2 = t2;
team1Goals = r1;
team2Goals = r2;
}
public void ShowResult()
{
System.out.println("\t\t\t*Hockey*");
System.out.println("\t"+team1 + " - " + team1Goals + " Goals");
System.out.println("\t"+team2 + " - " + team2Goals + " Goals");
if(team1Goals>team2Goals)
{
System.out.println("\t"+team1 + " Won");
}
else
{
System.out.println("\t"+team2 + " Won");
}
}
}

77
class Sports
{
public static void main(String args[])
{
Cricket c = new Cricket();
Hockey h = new Hockey();

c.SetTeam("India", "England",240,220);
h.SetTeam("India", "Germany",3,2);

c.ShowResult();
h.ShowResult();

}
}

78
OUTPUT

RESULT

The interface program has been executed successfully.

79
Java – Thread

80
Ex.No.:6(a) Multi-Thread

AIM

To write a JAVA program to understand the concept of multi-threading

ALGORITHM

1. Declare class that extends thread..


2. Implement thread concepts in it.
3. Declare another class.
4. Create object for the main class here to invoke the thread.
5. Start the thread.
6. Display the output.

PROGRAM

import java.io.*;
import java.util.Scanner;

class ThreadA extends Thread


{
int a;
public ThreadA (int b)
{
a=b;
}
public void run()
{
for(int i=a;i<a+10;i++)
{
try
{
Thread.sleep(5000);
}catch(InterruptedException e)
{
System.out.println(e);

}
System.out.println(i);
}
}
}

class MyThread
{

81
public static void main(String args[])
{
int l,m;
Scanner s= new Scanner(System.in);
System.out.println("Enter two starting numbers");
l=s.nextInt();
m=s.nextInt();
ThreadA t1=new ThreadA(l);
ThreadA t2=new ThreadA(m);
t1.start();
t2.start();
}
}

82
OUTPUT:

RESULT

The multi-thread program has been executed successfully.

83
Ex.No.:6(b) Thread Using Runnable Interface

AIM

To write a JAVA program to understand the concept of runnable thread.

ALGORITHM

1. Declare class that implement runnable.


2. Define run() function in it..
3. Declare another class.
4. Create object for the main class here to invoke the thread.
5. Start the thread.
6. Display the output.

PROGRAM:

import java.io.*;
import java.util.Scanner;

class ThreadA implements Runnable


{
String msg;
ThreadA(String m)
{
msg=m;
}
public void run()
{
for(;;)
{
System.out.println(msg);
}
}
}

84
class RunThread
{
public static void main(String[] args)
{
ThreadA t1 = new ThreadA ("Hello");
ThreadA t2 = new ThreadA ("Folks");
Thread s = new Thread(t1);
Thread t = new Thread(t2);
s.start();
t.start();
}
}
}

85
OUTPUT:

RESULT

The runnable thread program has been executed successfully.

86
Practice Exercise

1. 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.

87
Applet Application
Small Program Large Program

Used to run a program on client Can be executed on standalone computer


Browser system
Applet is portable and can be Need JDK, JRE, JVM installed on client
executed by any JAVA supported machine.
browser.
Applet applications are executed in Application can access all the resources of
a Restricted Environment the computer
Applets are created by extending Applications are created by writing public
the java.applet.Applet static void main(String[] s) method.
Applet application has 5 methods Application has a single start point which
which will be automatically invoked is main method
on occurance of specific event

Java – Applet Programming

88
Ex. No: 7(a) SIMPLE APPLET

AIM

To create a simple applet code in java.

ALGORITHM

1. Create a class that extends “Applet” class and implements “ActionListener” interface.
2. Define Label boxes, Buttons and Text Fields (i.e., Components) in the “init()” method.
3. Override the “actionPerformed()” method with specified action.
4. Compile and view the output in “appletviewer”.

PROGRAM

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Applet2 extends Applet implements ActionListener


{
TextField t1 = new TextField(20);
TextField t2 = new TextField(20);

public void init()


{
Label l1=new Label("UserName");
Label l2=new Label(" Password");
add(l1);
add(t1);
add(l2);
add(t2);
Button b1=new Button("OK");
add(b1);
Button b2=new Button("Clear");
add(b2);
b2.addActionListener(this);

89
public void actionPerformed(ActionEvent ae)
{
t1.setText(" ");
t2.setText(" ");
}

/*<applet code="Applet2.class" height="500" width="500"> </applet>*/

OUTPUT:

RESULT
The Java simple applet program has been executed successfully.

90
Ex. No: 7(b) EVENT HANDLER

AIM

To write a java code to handle events in Applet.

ALGORITHM

1. Create a class that extends “Applet” class and implements “ActionListener” interface.
2. Define two buttons and an image(Components) in “init()” method.
3. Add the two buttons to a panel.
4. Set the panel to be Grid Layout.
5. Add the panel to the Layout and add Action Listeners for the buttons.
6. Perform the action(select the image) with respect to the button selected.

PROGRAM

import java.applet.*;
import java.awt.event.*;
import java.awt.*;

public class EventL extends Applet implements ActionListener


{

Panel p1;
Button b,c;
Image backGround;

public void init()


{
backGround = getImage(getCodeBase(), "Autumn.jpg");

Panel p1 = new Panel();

b = new Button("Autumn");
c = new Button("Winter");

p1.add(b);
p1.add(c);

setLayout(new GridLayout(10,1));
add(p1);

b.addActionListener(this);
c.addActionListener(this);

91
}

public void paint(Graphics g)


{
g.drawImage(backGround,0,100,this);
}

public void actionPerformed(ActionEvent e)


{
if(e.getSource()== b)
{
backGround = getImage(getDocumentBase(), "image1.jpg");
}
else
{
backGround = getImage(getDocumentBase(), "image2.jpg");
}
repaint();
}

/*<applet code="EventL.class" height="500" width="500"> </applet>*/

92
OUTPUT:

RESULT

The event handler in the Applet has been executed successfully.

93
Practice Exercises

1. Write a program using Applet for configuring Applets by passing parameters.

2. Develop an Applet that receives an integer in one text field & compute its factorial value &
returns it in another text filed when the button “Compute” is clicked.

3. Write a program that creates a user interface to perform integer divisions. The user enters two
numbers in the text fields, 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 Arithmetic Exception Display the exception in a message dialog box.

94
Ex. No: 8 COLOUR PALLET

AIM

To design a colour pallet applet in java

ALGORITHM

1. Create a class that extends “Applet” class and implements “ActionListener” and “ItemListener”
interfaces.
2. In “init()” method, define and initialize the objects.
3. Change the colour of Background and Foreground of a Text area based on the choice and button
selected.
4. Change the image being displayed based on choice
5. Use Grid Layout and set the panels
6. In “actionPerformed” method, text area is edited.
7. In “itemStateChanged” method, image is repainted.
8. The applet is executed in “appletviewer”.

PROGRAM

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

/*
<applet code=colorpalette.class width=500 height=400>
</applet>
*/

public class colorpalette extends Applet implements ActionListener,ItemListener


{
int flag=1; //Variable declaration
String s1,s2;

Button b1,b2,b3,b4; //AWT components


TextField text;
Checkbox forecolor,backcolor,image1,image2;
CheckboxGroup colour,images;
Image backGround;
Panel p1,p2,p3,p4;

public void init()


{
backGround = getImage(getCodeBase(), "Mountain.jpg");

Panel p1 = new Panel();

95
Panel p2 = new Panel();
Panel p3 = new Panel();
Panel p4 = new Panel();

b1=new Button(); //Button initialization


b1.setBackground(Color.green);
b2=new Button();
b2.setBackground(Color.red);
b3=new Button();
b3.setBackground(Color.yellow);
b4=new Button();
b4.setBackground(Color.orange);

colour=new CheckboxGroup();
backcolor=new Checkbox("Background",colour,true);
forecolor=new Checkbox("Foreground",colour,false);

text=new TextField("Type Here",25);

//Checkbox initialization for Image1 and Image2


images=new CheckboxGroup();
image1=new Checkbox("Mountain",images,true);
image2=new Checkbox("Sunrise",images,false);

p1.add(b1); //Adding button and checkbox


p1.add(b2);
p1.add(b3);
p1.add(b4);

p2.add(backcolor);
p2.add(forecolor);

p3.add(text);

p4.add(image1);
p4.add(image2);

setLayout(new GridLayout(10,1));
add(p1);
add(p2);
add(p3);
add(p4);

b1.addActionListener(this); //Adding ActionListener to all button


b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);

backcolor.addItemListener(this); //Adding ItemListener to all checkbox


forecolor.addItemListener(this);

image1.addItemListener(this);
image2.addItemListener(this);
}

96
public void paint(Graphics g)
{
g.drawImage(backGround,0,100,this);
}
public void actionPerformed(ActionEvent e)
{
Color col= Color.white;

if(e.getSource()==b1)
{
col = Color.green;
}
else if(e.getSource()==b2)
{
col = Color.red;
}
else if(e.getSource()==b3)
{
col = Color.yellow;
}
else if(e.getSource()==b4)
{
col = Color.orange;
}

if(flag==1)
{
text.setBackground(col);
}
else
{
text.setForeground(col);
}

repaint();
}

97
public void itemStateChanged(ItemEvent ie)
{
s1=colour.getSelectedCheckbox().getLabel();
if(s1.equals("Background"))
{
flag=1;
}
else
{
flag=0;
}

s2=images.getSelectedCheckbox().getLabel();
if(s2.equals("Mountain"))
{
backGround = getImage(getCodeBase(), "Mountain.jpg");
}

else
{
backGround = getImage(getCodeBase(), "sunrise.jpg");
}

repaint();
}
}

98
OUTPUT

RESULT

The Colour pallet has been designed in the Applet.

99
Ex. No: 9(a) BORDER LAYOUT

AIM
To set the layout of the Applet as Border layout.

ALGORITHM:
1. Create a class that extends “JFrame”.
2. In Constructor of the class, create buttons and place them at different areas of the same “JPanel”
that is created with a BorderLayout.
3. In Main method, create an object for the class.
4. Resize the window to see the layout design during execution.

PROGRAM:

import java.awt.*;
import javax.swing.*;

public class BorderLay extends JFrame


{
JButton B1,B2,B3,B4,B5;
BorderLay()
{
super("Border Layout");
JPanel panel = new JPanel(new BorderLayout());
B1= new JButton("1");
B2= new JButton("2");
B3= new JButton("3");
B4= new JButton("4");
B5= new JButton("5");

panel.add(B1,BorderLayout.PAGE_START);
panel.add(B2,BorderLayout.LINE_START);
panel.add(B3,BorderLayout.CENTER);
panel.add(B4,BorderLayout.LINE_END);
panel.add(B5,BorderLayout.PAGE_END);

add(panel);
setSize(200, 150);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public static void main(String args[])


{
new BorderLay();
}
}

100
OUTPUT:

RESULT

The buttons have been set Border layout in the Applet.

101
Ex. No: 9(b) FLOW LAYOUT

AIM
To set the layout of the Applet as Flow layout

ALGORITHM

1. Create a class that extends JFrame.


2. In Constructor of the class, create buttons and add them to the same panel.
3. Set the panel to be in Flow Layout.
4. In Main method, create an object for the class.
5. Resize the window to see the layout design during execution.
PROGRAM:
import java.awt.*;
import javax.swing.*;

public class FlowLay extends JFrame


{
JButton B1,B2,B3,B4,B5,B6,B7,B8,B9;
FlowLay()
{
super("Flow Layout");
JPanel panel = new JPanel(new FlowLayout());
B1= new JButton("1");
B2= new JButton("2");
B3= new JButton("3");
B4= new JButton("4");
B5= new JButton("5");
B6= new JButton("6");
B7= new JButton("7");
B8= new JButton("8");
B9= new JButton("9");

panel.add(B1);
panel.add(B2);
panel.add(B3);
panel.add(B4);
panel.add(B5);
panel.add(B6);
panel.add(B7);
panel.add(B8);
panel.add(B9);
add(panel);
setSize(200, 150);
this.setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
FlowLay f = new FlowLay();
}
}

102
OUTPUT

RESULT
The Buttons have been set Flow layout in the Applet.

103
Ex. No: 10 AWT - CONTROLS

AIM

To create and execute an AWT’s Controls.

ALGORITHM

1. Create a class “AwtControl” that extends Frame and implements “ActionListener” interface.
2. Define components of the applet.
3. In Constructor of the class, initialize the components and add them to the applet.
4. Include the “actionPerformed” method and “windowclosing” method to the class.
5. In Main method, create an object for the class.
6. View the output in an “appletviewer”

PROGRAM

import java.io.*;
import java.awt.*;
import java.awt.event.*;

public class AwtControl extends Frame implements ActionListener


{
Label l1, l2, l3, l4, l5, l6, l7;
TextField t1, t2, t3, t4;
Choice ch1;
Checkbox cb1, cb2;
CheckboxGroup cbg;
List It;
Button b1, b2;
Panel p1;
TextArea ta;

public AwtControl()
{
setLayout(new GridLayout(10, 2));

ta = new TextArea( 20, 20);

l1 = new Label("Student ID ");


l2 = new Label("Name ");
l3 = new Label("College");
l4 = new Label("Department");
l5 = new Label("Gender ");
l6 = new Label("Extra activities");

t1 = new TextField(20);
t2 = new TextField(20);

104
t3 = new TextField(20);
ch1 = new Choice();
ch1.addItem("CSE");
ch1.addItem("IT");
ch1.addItem("MCA");
ch1.addItem("ECE");

cbg = new CheckboxGroup();


cb1 = new Checkbox("Male", cbg, true);
cb2 = new Checkbox("Female", cbg, true);

p1 = new Panel();
p1.add(cb1);
p1.add(cb2);
It = new List();
It.addItem("Sports");
It.addItem("Graphics");
It.addItem("Mobile Technology");
b1 = new Button("Show");
b1.addActionListener(this);
b2 = new Button("Exit");
b2.addActionListener(this);

add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(l4);
add(ch1);
add(l5);
add(p1);
add(l6);
add(It);
add(b1);
add(b2);
add(ta);

}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b2)
{
System.exit(0);
}
ta.setText(""); //Clear
ta.append(t1.getText() + "\n");
ta.append(t2.getText()+ "\n");
ta.append(t3.getText()+ "\n");
ta.append(ch1.getSelectedItem()+ "\n");
ta.append(cbg.getSelectedCheckbox().getLabel()+ "\n");
ta.append(It.getSelectedItem()+ "\n");
}

105
public void windowClosing(WindowEvent e)
{
dispose();
System.exit(0);
}

public static void main(String args[])


{
AwtControl control = new AwtControl();
control.setSize(600,600);
control.setVisible(true);
}
}

106
OUTPUT:

RESULT

The AWT’s Controls have been executed successfully.

107
Java Database Connectivity

108
Ex. No: 11 JDBC

AIM

A java program to connect the backend database using JDBC Technique

ALGORITHM

1. Create a table for Student in MySQL and insert records.


2. Create a class.
3. In Main method, Register the driver class using “forName()” method of Class “class”.
4. Establish the connection with the database using “getConnection()” method of “DriverMan-
ager” class.
5. Create Statement using “createStatement()” method of “Connection” interface.
6. The Query to be executed is got using “executequery()” method of the “Statement” class in-
voked using “ResultSet” object.
7. Display the table from database.
8. Close the connection.

PROGRAM
import java.sql.*;

class OracleCon
{
public static void main(String args[])
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection
con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","smvec");

Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from student");
while(rs.next())
{
System.out.println(rs.getInt(1)+" "+rs.getString(2)+" "+rs.getString(3) +" "+ rs.getInt(4));
}
con.close();
}
catch(Exception e)
{
System.out.println(e);
}
}

109
}

OUTPUT:

110
RESULT

The JDBC Program for Database Connectivity to java has been executed successfully.

111
Practice Exercise

1. Write a java program that connects to a database using JDBC and does add, deletes, modify
and retrieve operations?

112
Remote Method Invocation

113
Ex. No: 12 Remote Method Invocation

AIM

To write an RMI code to invoke remote code from a server.

ALGORITHM

1. Create an Interface “RmiInterface” that extends “Remote” class.


2. In the interface, the signature of methods to be invoked are defined.
3. Implement the interface using the class “RmiImplementation” which extends a “Uni-
castRemoteObject” class.
4. Define the methods in the interface.
5. Create a class “RmiServer” for Server.
6. Create an object for “RmiImplementation” class.
7. Bind the code using “rebind()” method of “Naming” class.
8. Create another class “RmiClient” which acts as a Client.
9. Create an object for the “RmiInterface” and using “lookup()” method of “Naming” class
connect the server.
10. Call the methods to be invoked from the implementation present in the server.
11. Compile and execute the code.

PROGRAM

// Interface code:
import java.rmi.*;
public interface RmiInterface extends Remote
{
double add(double d1, double d2) throws RemoteException;
double sub(double d1, double d2) throws RemoteException;
double mul(double d1, double d2) throws RemoteException;
double div(double d1, double d2) throws RemoteException;
}

114
// Implementation code:
import java.rmi.*;
import java.rmi.server.*;

public class RmiImplementation extends UnicastRemoteObject implements RmiInterface


{

public RmiImplementation() throws RemoteException


{
}
public double add(double d1, double d2) throws RemoteException
{
return d1 + d2;
}
public double sub(double d1, double d2) throws RemoteException
{
return d1 - d2;
}
public double mul(double d1, double d2) throws RemoteException
{
return d1 * d2;
}
public double div(double d1, double d2) throws RemoteException
{
return d1 / d2;
}
}

//Server code:
import java.net.*;
import java.rmi.*;
public class RmiServer
{
public static void main(String args[])
{
try
{
RmiImplementation rmiImp = new RmiImplementation();
Naming.rebind("AddServer", rmiImp);
}
catch(Exception e)
{
System.out.println("Exception: " + e);
}
}
}

115
//Client code :
import java.rmi.*;
public class RmiClient
{
public static void main(String args[])
{
try
{
RmiInterface rmiIntf = (RmiInterface)Naming.lookup("rmi://" + args[0] + "/AddServer");
System.out.println("The first number is: " + args[1]);
double d1 = Double.valueOf(args[1]).doubleValue();

System.out.println("The second number is: " + args[2]);


double d2 = Double.valueOf(args[2]).doubleValue();

System.out.println("The Sum is: " + rmiInf.add(d1, d2));


System.out.println("The Difference is: " + rmiInf.sub(d1, d2));
System.out.println("The Product is: " + rmiInf.mul(d1, d2));
System.out.println("The Division is: " + rmiInf.div(d1, d2));
}
catch(Exception e)
{
System.out.println("Exception: " + e);
}
}
}

116
OUTPUT:

RESULT

The RMI code has been executed successfully.

117
Content Beyond the Syllabus

118
JavaScript
Aim:
To create a simple web page using Java Script

Procedure:
Function with arguments, that returns a value

1. Create HTML file by using notepad ++ editor.

2. Define Tags HTML,body tags.

3. Save the file with .html extension

4 .Open the file in the browser. Browser will show the output as shown in the sample program
output.
Source Code :

<html>

<head>

<script type="text/javascript">

function product(a,b)

return a*b

</script>

</head>

<body>

<script type="text/javascript">

document.write(product(4,3))

</script>

<p>The script in the body section calls a function with two parameters (4 and 3).</p>

<p>The function will return the product of these two parameters.</p> </body>

</html>

119
Output :

Result:
Thus a simple Client side web page is created using java script.

120
Servlet
Aim:
To create a dynamic web page using servlet
Procedure:
1. Open Netbeans IDE, Select File -> New Project
2. Select Java Web -> Web Application, then click on Next,
3. Give a name to your project and click on Next,
4. The complete directory structure required for the Servlet Application will be created
automatically by the IDE.
5. To create a Servlet, open Source Package, right click on default packages -> New -
> Servlet.
6. Give a Name to your Servlet class file,
7. Write some code inside your Servlet class.
8. Create an HTML file, right click on Web Pages -> New -> HTML
9. Give it a name. We recommend you to name it index, because browser will always pick up
the index.html file automatically from a directory. Index file is read as the first page of the
web application.
10. Write some code inside your HTML file. We have created a hyperlink to our Servlet in our
HTML file.
11. Edit web.xml file. In the web.xml file you can see, we have specified the url-pattern and
the servlet-name, this means when hello url is accessed our Servlet file will be executed.
12. Run your application, right click on your Project and select Run

Source Code:
ExampleHttpServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
// Creating Http Servlet by Extending HttpServlet class
public class ExampleHttpServlet extends HttpServlet
{
private String mymsg;

public void doGet(HttpServletRequest request,


HttpServletResponse response) throws ServletException,
IOException
{
// Setting up the content type of web page
response.setContentType("text/html");
// Writing the message on the web page
PrintWriter out = response.getWriter();
out.println("<h1>" + mymsg + "</h1>");
out.println("<p>" + "Hello Friends!" + "</p>");
}
}

index.html
index<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Http Servlet Demo</title>

121
</head>
<body>
<a href="welcome">Click to call Servlet</a>
</body>
</html>
web.xml
<web-app>
<display-name>BeginnersBookServlet</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>MyHttpServlet</servlet-name>
<servlet-class>ExampleHttpServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyHttpServlet</servlet-name>
<url-pattern>/welcome</url-pattern>
</servlet-mapping>
</web-app>

122
Output:

Result:
Thus the dynamic web page is created using servlet

123
Viva Voce Questions
1. What is the most important feature of Java?
Java is a platform independent language.
2. What do you mean by platform independence?
Platform independence means that we can write and compile the java code in one
platform (eg Windows) and can execute the class in any other supported platform eg
(Linux,Solaris,etc).
3. What is a JVM?
JVM is Java Virtual Machine which is a run time environment for the compiled java class
files.
4. Are JVM's platform independent?
JVM's are not platform independent. JVM's are platform specific run time implementation
provided by the vendor.
5. What is the difference between a JDK and a JVM?

JDK is Java Development Kit which is for development purpose and it includes execution
environment also. But JVM is purely a run time environment and hence you will not be able to
compile your source files using a JVM.

6. What is a pointer and does Java support pointers?

Pointer is a reference handle to a memory location. Improper handling of pointers leads to


memory leaks and reliability issues hence Java doesn't support the usage of pointers.

7. What is the base class of all classes? java.lang.Object

8. Does Java support multiple inheritance? Java doesn't support multiple inheritance.

9. Is Java a pure object oriented language?


Java uses primitive data types and hence is not a pure object oriented language.

10. Are arrays primitive data types? In Java, Arrays are objects.

11. What is difference between Path and Classpath?

Path and Classpath are operating system level environment variales. Path is used define
where the system can find the executables(.exe) files and classpath is used to specify the
location .class files.
12. What are local variables?
Local varaiables are those which are declared within a block of code like methods. Local
variables should be initialised before accessing them

124
13. Can a class declared as private be accessed outside it's package? Not possible.

14. Can a class be declared as protected?


A class can't be declared as protected. only methods can be declared as protected.

15. What is the access scope of a protected method?


A protected method can be accessed by the classes within the same package or by the subclasses
of the class in any package.

16. What is the purpose of declaring a variable as final?

A final variable's value can't be changed. final variables should be initialized before using them.

17. What is the impact of declaring a method as final?

A method declared as final can't be overridden. A sub-class can't have the same method
signature with a different implementation.

18. I don't want my class to be inherited by any other class. What should i do?
You should declared your class as final. But you can't define your class as final, if it is an
abstract class. A class declared as final can't be extended by any other class.

19. Can you give few examples of final classes defined in Java API?
java.lang.String, java.lang.Math are final classes.

20. How is final different from finally and finalize()?


o final is a modifier which can be applied to a class or a method or a variable. final class
can't be inherited, final method can't be overridden and final variable can't be changed.

o finally is an exception handling code section which gets executed whether an


exception is raised or not by the try block code segment.
o finalize() is a method of Object class which will be executed by the JVM just before
garbage collecting object to give a final chance for resource releasing activity.

21. Can a class be declared as static?


We can not declare top level class as static, but only inner class can be declared static.

public class Test

{
static class InnerClass
{
public static void InnerMethod()

{
System.out.println("Static Inner Class!"); }
}

125
public static void main(String args[])
{
Test.InnerClass.InnerMethod();

}
}
//output: Static Inner Class!

22. When will you define a method as static?


When a method needs to be accessed even before the creation of the object of the class
then we should declare the method as static.

23. What are the restriction imposed on a static method or a static block of code?

A static method should not refer to instance variables without creating an instance and
cannot use "this" operator to refer the instance.

24. I want to print "Hello" even before main() is executed. How will you acheive that?

Print the statement inside a static block of code. Static blocks get executed when the class
gets loaded into the memory and even before the creation of an object. Hence it will be executed
before the main() method. And it will be executed only once.

25. How-will-you-communicate-between-two-Applets
The simplest method is to use the static variables of a shared class since there's only one
instance of the class and hence only one copy of its static variables. A slightly more reliable
method relies on the fact that all the applets on a given page share the same AppletContext. We
obtain this applet context as follows:

AppletContext ac = getAppletContext();

AppletContext provides applets with methods such as getApplet(name),


getApplets(),getAudioClip, getImage, showDocument and showStatus( ).

26. Which classes can an applet extend?


An applet can extend the java.applet.Applet class or the java.swing.JApplet class. The
java.applet.Applet class extends the java.awt.Panel class and enables you to use the GUI tools in
the AWT package. The java.swing.JApplet class is a subclass of java.applet.Applet that also
enables you to use the Swing GUI tools.

27. How do you cause the applet GUI in the browser to be refreshed when data in it may have
changed?
You invoke the repaint() method. This method causes the paint method, which is required
in any applet, to be invoked again, updating the display.

28. For what do you use the start() method?

126
You use the start() method when the applet must perform a task after it is initialized,
before receiving user input. The start() method either performs the applet's work or (more likely)
starts up one or more threads to perform the work.

29. True or false: An applet can make network connections to any host on the Internet. False: An
applet can only connect to the host that it came from.

30. How do you get the value of a parameter specified in the APPLET tag from within the applet's
code?
You use the getParameter("Parameter name") method, which returns the String value
of the parameter.
31. True of false: An applet can run multiple threads.
True. The paint and update methods are always called from the AWT drawing and event
handling thread. You can have your applet create additional threads, which is recommended for
performing time-consuming tasks.

127
COURSE OUTCOMES AND PROGRAM OUTCOMES
List of PSO’s
PSO 1: Establishment of Mathematical and computer systems concepts: To use mathematical
and system concepts to solve multidisciplinary problems using appropriate mathematical
analysis, system and programming concepts on various computing environments.
PSO 2: Establishment of communication and information concepts: To inculcate good breadth of
knowledge to apply and enhance informatics and communication technologies
PSO 3: Establishment of Business, Technological concepts: The ability to interpret and respond to
business agility with relevant software tools and skills and provide newer ideas and innovations in
information technology research
List of Program Outcomes
Engineering Knowledge: Apply knowledge of mathematics and science, with
PO1 fundamentals of
Engineering and Technology to be able to solve complex engineering problems related
to IT.
Problem Analysis: Identify, Formulate, review research literature and analyze
complex engineering
problems related to IT and reaching substantiated conclusions using first principles of
PO2 mathematics,
natural sciences and engineering sciences
Design/Development of solutions: Design solutions for complex engineering
problems related to IT
and design system components or processes that meet the specified needs with
PO3 appropriate
consideration for the public health and safety and the cultural societal and
environmental
considerations
Conduct Investigations of Complex problems: Use research–based knowledge
and research
methods including design of experiments, analysis and interpretation of data, and
PO4 synthesis of the
information to provide valid conclusions.
Modern Tool Usage: Create, Select and apply appropriate techniques, resources
and modern
engineering and IT tools including prediction and modeling to computer science
PO5 related complex
engineering activities with an understanding of the limitations
The Engineer and Society: Apply Reasoning informed by the contextual
knowledge to assess
societal, health, safety, legal and cultural issues and the consequent responsibilities
PO6 relevant to the IT

128
professional engineering practice
Environment and Sustainability: Understand the impact of the IT professional
engineering solutions
in societal and environmental contexts and demonstrate the knowledge of, and need
PO7 for sustainable
development
Ethics: Apply Ethical Principles and commit to professional ethics and responsibilities
PO8 and norms of
the engineering practice
Individual and Team Work: Function effectively as an individual and as a member
PO9 or leader in
diverse teams and in multidisciplinary Settings
Communication: Communicate effectively on complex engineering activities with
the engineering
community and with society at large such as able to comprehend and with write
PO10 effective reports and
design documentation, make effective presentations and give and receive clear
instructions.
Project Management and Finance: Demonstrate knowledge and understanding of
the engineering
management principles and apply these to one’s own work, as a member and leader in
PO11 a team, to
manage projects and in multi-disciplinary environments
Life-Long Learning: Recognize the need for and have the preparation and ability to
PO12 engage in
independent and life-long learning the broadest context of technological change

129
Java Lab Manual

Department of IT 130

You might also like