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

LAB JAVA Programming

Uploaded by

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

LAB JAVA Programming

Uploaded by

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

ALAGAPPA UNIVERSITY

[Accredited with ‘A+’ Grade by NAAC (CGPA:3.64) in the Third Cycle


and Graded as Category–I University by MHRD-UGC]
(A State University Established by the Government of Tamil Nadu)
KARAIKUDI – 630 003

Directorate of Distance Education

BCA
IV - Semester
101 44

LAB: INTERNET AND


JAVA PROGRAMMING
Author:
Deepak Gupta, Asst. Professor, G. L. Bajaj Institute of Technology & Management, Greater Noida

"The copyright shall be vested with Alagappa University"

All rights reserved. No part of this publication which is material protected by this copyright notice
may be reproduced or transmitted or utilized or stored in any form or by any means now known or
hereinafter invented, electronic, digital or mechanical, including photocopying, scanning, recording
or by any information storage or retrieval system, without prior written permission from the Alagappa
University, Karaikudi, Tamil Nadu.

Information contained in this book has been published by VIKAS® Publishing House Pvt. Ltd. and has
been obtained by its Authors from sources believed to be reliable and are correct to the best of their
knowledge. However, the Alagappa University, Publisher and its Authors shall in no event be liable for
any errors, omissions or damages arising out of use of this information and specifically disclaim any
implied warranties or merchantability or fitness for any particular use.

Vikas® is the registered trademark of Vikas® Publishing House Pvt. Ltd.


VIKAS® PUBLISHING HOUSE PVT. LTD.
E-28, Sector-8, Noida - 201301 (UP)
Phone: 0120-4078900 x Fax: 0120-4078999
Regd. Office: A-27, 2nd Floor, Mohan Co-operative Industrial Estate, New Delhi 1100 44
x Website: www.vikaspublishing.com x Email: helpline@vikaspublishing.com

Work Order No. AU/DDE/DE12/Printing of Course Material/2020 Dated 06.05.2020 Copies - 200
LAB: INTERNET AND JAVA PROGRAMMING
SYLLABI

BLOCK 1: JAVA FUNDAMENTAL PROBLEMS


Simple Java Problems
Class and Objects
Conditional Control using Java
Looping using Java

BLOCK 2: OOP CONCEPTS


Function Overloading Programs
Operator Overloading Programs
Inheritance Programs, Packages
Polymorphism Programs, Message Passing Programs

BLOCK 3: THREAD & VIRTUAL FUNCTION


Threads
Virtual Function Programs

BLOCK 4: I/O AND EXCEPTION HANDLING


Exception Handling Programs
I/O Manipulation Programs

BLOCK 5: NETWORK PROGRAMMING


Applet Programs
Implementation of Simple Network Programs using Java
INTRODUCTION
Java is a class-based, Object-Oriented Programming (OOP) language that is specifically designed to have
as few implementation dependencies as possible. It is a general-purpose programming language intended
to let application developers Write Once, Run Anywhere (WORA), meaning that compiled Java code can
run on all platforms that support Java without the need for recompilation. Java applications are typically
compiled to bytecode that can run on any Java Virtual Machine (JVM) regardless of the underlying computer
architecture.
Java is strongly associated with the Internet. Internet helped Java to bring it to the forefront and Java
influenced Internet by simplifying the web programming and inventing Applet programming. Applets expanded
the scope of Internet. Java also addressed two other important issues of Internet, which are security and
portability. Internet users can also setup their websites containing Java Applets that could be used by other
remote users of the Internet. This feature made Java most popular programming language for the Internet.
This lab manual, Internet and Java Programming, contains several programs based on Java
concepts, such as class and objects, conditional control using Java, looping using Java, function overloading,
operator overloading, inheritance, packages, polymorphism, threads, exception handling, I/O manipulation,
Applets and simple network programs using Java. In addition, it will help students in coding and debugging
their programs. The manual provides all logical, mathematical and conceptual programs that can help to
write programs very easily in Java language. These exercises shall be taken as the base reference during
lab activities for students. There are also many Try Yourself Questions provided to students for implementation
in the lab.
LAB: Internet and
BLOCK I : JAVA FUNDAMENTAL PROBLEMS JAVA Programming

This block contains the programs related to the following concepts:


1. Classes and Objects NOTES
2. Conditional Control and Looping in Java
Java is an object-oriented programming language, hence in Java everything is related
with classes and objects, along with its attributes and methods. A Class is like an
object constructor, or a ‘blueprint’ for creating objects. In Java, an object is created
from a class. You can create multiple objects of one class.
1. Write a Java program for finding the largest of the three numbers.
Program

Self-Instructional
Material 1
LAB: Internet and Output of the program:
JAVA Programming

NOTES

2. Write a Java program for finding the factorial of a given number.


Program

Output of the program:

Self-Instructional
2 Material
3. Write a Java program for finding the product of digits of input numbers. LAB: Internet and
JAVA Programming
Program

NOTES

Output of the program:

4. Write a Java program for swapping the two given numbers.


Program

Self-Instructional
Material 3
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

5. Write a Java program for printing the Fibonacci series upto given
number of terms.
Program

Self-Instructional
4 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

6. Write a Java program for generating a pattern using @ symbol.


Program

Self-Instructional
Material 5
LAB: Internet and Output of the program:
JAVA Programming

NOTES

7. Write a Java program for generating the prime number series.


Program

Self-Instructional
6 Material
Output of the program: LAB: Internet and
JAVA Programming

NOTES

8. Write a Java program for finding whether the given string is palindrome
or not.
Program

Output of the program:

Self-Instructional
Material 7
LAB: Internet and 9. Write a Java program for finding the quadratic roots and their types.
JAVA Programming
Program

NOTES

Self-Instructional
8 Material
LAB: Internet and
JAVA Programming

Output of the program: NOTES

10. Write a Java program to print the product of two given matrices
using arrays.
Program

Self-Instructional
Material 9
LAB: Internet and
JAVA Programming

NOTES

Self-Instructional
10 Material
LAB: Internet and
JAVA Programming

NOTES

Self-Instructional
Material 11
LAB: Internet and Output of the program:
JAVA Programming

NOTES

11. Write a Java program for generating a pyramid of numbers.


Program

Self-Instructional
12 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

Try Yourself Questions


1. Write a Java program for finding the largest of five numbers.
2. Write a Java program for finding the factorial of any number.
3. Write a Java program for finding the product of three input digits.
4. Write a Java program for swapping the four input numbers.
5. Write a Java program for displaying the Fibonacci series up to Nth Fibonacci
numbers.
6. Write a Java program to generate random number.
7. Write a Java program for generating a pattern using * symbol.
8. Write a Java program for generating the series of ‘Even’ and ‘Odd’ numbers.
9. Write a Java program for finding whether the given string is palindrome or
not.
10. Write a Java program to print the product of three given matrices using
arrays.
11. Write a Java program for generating a pyramid pattern of numbers.
Self-Instructional
Material 13
LAB: Internet and
JAVA Programming BLOCK II: OOP CONCEPTS

This block contains the programs related to the following topics:


NOTES 1. Function Overloading
2. Inheritance, Packages and Interfaces
3. Polymorphism
Function Overloading
Function overloading is used to reduce complexity and increase the efficiency of
the program by involving more functions that are segregated and can be used to
distinguish among each other with respect to their individual functionality.
Overloaded functions are related to compile-time or static polymorphism. Function
overloading in Java takes place when there are functions having the same name
but have the different numbers of parameters passed to it which can be different in
datatype like int, double, float and are used to return different values which are
computed inside the respective overloaded method. There is also a concept of
type conversion which is basically used in overloaded functions used to calculate
the conversion of type in variables.
Advantages of Function Overloading
1. Function overloading works with the same name. So you do not have to
create methods again which is already defined inside a respective function.
2. The functionality not only resolves the problem of conflicting naming but
also improves the readability of the program.
1. Write a Java program for displaying the volume of cuboids when their
dimensions are given.
Program

Self-Instructional
14 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

Self-Instructional
Material 15
LAB: Internet and 2. Write a Java program for displaying the perimeter of rectangles when
JAVA Programming
their dimensions are given.
Program
NOTES

Self-Instructional
16 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

3. Write a Java program for displaying back the already entered employee
information.
Program

Self-Instructional
Material 17
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

4. Write a Java program to illustrate the concept of operator precedence.


Program

Self-Instructional
18 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

Inheritance
In Java, inheritance is a mechanism in which one object acquires all the properties
and behaviors of a parent object. It is an important part of OOPs (Object-Oriented
Programming system). In Java it helps you to create new classes that are built
upon existing classes. When you inherit from an existing class, you can reuse
methods and fields of the parent class. Moreover, you can add new methods and
fields in your current class also.
Advantages of Inheritance
1. Inheritance is a process of defining a new class based on an existing class
by extending its common data members and methods.
2. Inheritance allows to reuse of code, and it improves reusability in the Java
application. Self-Instructional
Material 19
LAB: Internet and 3. Inheritance is a process for method overriding so that the runtime
JAVA Programming
polymorphism can be achieved.
4. The biggest advantage of inheritance is that the code that is already present
in base class need not be rewritten in the child class.
NOTES
5. Write a Java program for demonstrating the concept of multilevel
inheritance.
Program

Self-Instructional
20 Material
Output of the program: LAB: Internet and
JAVA Programming

NOTES

6. Write a Java program for illustrating the concept of abstract classes.


Program

Self-Instructional
Material 21
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

7. Write a Java program for explaining the concept of Super keyword.


Program

Self-Instructional
22 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

Packages
A package is a group of similar types of classes, interfaces and sub-packages.
Package can be categorized into two types, i.e., built-in package and user-defined
package. Keyword import is used to access a package from the library.
Advantages of a Package
1. Package is used to categorize the classes and interfaces so that they can be
easily maintained.
2. Package provides access protection.
3. Package removes naming collision.

Self-Instructional
Material 23
LAB: Internet and 8. Write a Java program to illustrate the concept of user defined
JAVA Programming
packages.
Program
NOTES

Output of the program:

9. Write a Java package program for class book and then import the
data from the package and display the result.
Program

Self-Instructional
24 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

10. Write a Java program for finding the cube of a number using package
for various data types and then import it in another class and display the
results.
Program

Self-Instructional
Material 25
LAB: Internet and
JAVA Programming

NOTES

Output of the program:


javac –d . Mathmethods.java
javac Cube.java
java Cube

Self-Instructional
26 Material
LAB: Internet and
JAVA Programming

NOTES

Interfaces
Interface is a blueprint of a Class that can contain constants and abstract methods.
They cannot be instantiated and can only be implemented by classes or extended
by other interfaces. Syntax for defining interfaces is given below:

Advantages of Interface
1. Interface can be used for the abstraction.
2. Interface supports the functionality of multiple inheritance.
3. Interface allows you to make your application loosely coupled.
11. Write a Java program for demonstrating the use of interfaces.
Program

Self-Instructional
Material 27
LAB: Internet and
JAVA Programming

NOTES

Self-Instructional
28 Material
Output of the program: LAB: Internet and
JAVA Programming

NOTES

12. Write a program on the concept of polymorphism.


Program

Self-Instructional
Material 29
LAB: Internet and
JAVA Programming

NOTES

13. Write a program to demonstrate compile time polymorphism in Java.


Program

Self-Instructional
30 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

14. Write a program to perform runtime polymorphism in Java.


Program

Self-Instructional
Material 31
LAB: Internet and Output of the program:
JAVA Programming

NOTES

Try Yourself Questions


1. Write a Java program for displaying the volume of a rectangle when their
dimensions are given.
2. Write a Java program to find area of square, cuboid, rectangle and circle
using method overloading.
3. Write a Java program for displaying the perimeter of 5 rectangles when
their dimensions are given.
4. Write a Java program for displaying back the student information already
entered in student table.
5. Write a Java program to illustrate the instance of operator.
6. Write a Java program to illustrate max of three numbers using ternary
operator.
7. Write a Java program to illustrate the concept of inheritance.
8. Write a Java program to illustrate the concept of multilevel inheritance.
9. Write a Java program to illustrate the concept of hierarchical inheritance.
10. Write a Java program using method overriding to demonstrate why we
need to call the method of parent class with child class object.
11. Write a Java program for explaining the concept of Super keyword.
12. Write a Java program to illustrate the concept of user defined packages.
13. Write a Java program to demonstrate accessing of members when
corresponding classes are imported and not imported.
14. Write a Java program for finding the square of a number using package for
various data types and then import it in another class and display the results.
15. Write a Java program for providing the implementation of Bank interface.
16. Write a Java program to perform runtime polymorphism. Consider a scenario
where Bank is a class that provides a method to get the rate of interest.
However, the rate of interest may differ according to banks. For example,
SBI, ICICI, and AXIS banks are providing 8.4%, 7.3%, and 9.7% rate of
interest.
17. Write a Java program to demonstrate compile time polymorphism.
Self-Instructional
32 Material
LAB: Internet and
BLOCK III: THREAD AND VIRTUAL FUNCTION JAVA Programming

This block contains the programs related to the following topics:


1. Threads NOTES
2. Virtual Functions
Threads are sometimes called as lightweight processes. It allows performing various
tasks in the background at the same time without interrupting the main program.
Following are the two ways of creating threads:
x Extending the Thread Class
x Overriding the run() Method
Virtual function is a function or method which is used in an inherited class to override
the behaviour of the function having the same definition to achieve the polymorphism.
In Java, virtual keyword is not used to define the virtual functions.
1. Write a Java program for demonstrating the threading concept.
Program

Self-Instructional
Material 33
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

Self-Instructional
34 Material
2. Write a Java program for demonstrating the concept of multithreading. LAB: Internet and
JAVA Programming
Program

NOTES

Output of the program:

Self-Instructional
Material 35
LAB: Internet and 3. Write a Java program for understanding the concept of daemon threads.
JAVA Programming
Program

NOTES

Output of the program:

4. Write a program using virtual methods/functions in Java.


Program

Self-Instructional
36 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

Try Yourself Questions


1. Write a Java program for demonstrating the threading concept. Demonstrate
that how Java creates a new thread and starts running it successfully.
2. Write a Java program for demonstrate how to extend the thread.
3. Write a Java program to demonstrate the usage of exception in Daemon()
thread.
4. Write a Java program for demonstrating the concept of multithreading.
5. Write a Java program to demonstrate the usage of setDaemon() and
isDaemon() method.
6. Write a program using virtual methods in Java.
7. Write a program using virtual functions in Java.

Self-Instructional
Material 37
LAB: Internet and
JAVA Programming BLOCK IV: I/O AND EXCEPTION HANDLING

This block contains the program related to the following topics:


NOTES 1. String and Exception Handling
2. I/O and Stream Handling
String and Exception Handling
The ‘Exception Handling’ in Java is one of the powerful mechanism to handle the
runtime errors so that normal flow of the application can be maintained. In Java,
an exception is an event that disrupts the normal flow of the program. It is an
object which is thrown at runtime.
Basically, an exception (or exceptional event) is a problem that arises during
the execution of a program. When an ‘Exception’ occurs in the program then the
normal flow of the program is disrupted and the Program/Application terminates
abnormally, which is not recommended and therefore these exceptions must be
checked and controlled.
An exception can occur for many different reasons, such as a user has
entered an invalid data, a file that needs to be opened cannot be found, a network
connection has been lost in the middle of communications or the JVM has run out
of memory, etc. Some of these exceptions are caused by user error, others by
programmer error, and others by physical resources that have failed in some manner.
Advantage of Exception Handling
The core advantage of exception handling is to maintain the normal flow of the
application. An exception normally disrupts the normal flow of the application that
is why exception handling is used.
I/O and Stream Handling
The java.io package contains nearly every class essential to perform an Input
and Output (I/O) in Java. All these streams represent an input source and an
output destination. In Java, streams are the sequence of data that are read from
the source and written to the destination. An input stream is used to read data
from the source while an output stream is used to write data to the destination.
Java byte streams are used to perform input and output of 8-bit bytes.
1. Write a Java program for sorting the strings.
Program

Self-Instructional
38 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

2. Write a Java program for sorting names using array.


Program

Self-Instructional
Material 39
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

3. Write a Java program for iterating a list using collection.


Program

Self-Instructional
40 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

4. Write a Java program for demonstrating the use of


StringTokenizer class.
Program

Self-Instructional
Material 41
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

5. Write a Java program for demonstrating the exception handling


mechanism.
Program

Self-Instructional
42 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

6. Write a Java program for demonstrating the divide by zero exception


handling.
Program

Self-Instructional
Material 43
LAB: Internet and
JAVA Programming

NOTES
Output of the program:

7. Write a Java program for explaining the concept of exception handling


using the insufficient balance exception while displaying the Bank
balance.
Program

Self-Instructional
44 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

File I/O and Streams


A file is a collection of related records placed in a particular area on disk. Storing
and managing data using files is known as file processing which includes creating,
updating files and manipulation of data. Reading and writing of data in a file can be
done at the level of bytes or characters or fields. Java byte streams are typically
used for performing specific input and output of 8-bit bytes. Though there are
many classes related to byte streams but the most frequently used classes are,
FileInputStream and FileOutputStream.
Input refers to the flow of data into a program and output means the flow of
data out of a program. A stream in Java is a path along which data flows. The
java.io package contains a large number of stream classes that provide capabilities
for processing all type of data.

Self-Instructional
Material 45
LAB: Internet and 8. Write a program for implementing a FileInputStream in Java.
JAVA Programming
Program

NOTES

Output of the program:

Self-Instructional
46 Material
9. Write a Java program to demonstrate the use of FileOutputStream LAB: Internet and
JAVA Programming
and PrintStream classes.
Program
NOTES

Output of the program:

Self-Instructional
Material 47
LAB: Internet and 10. Write a Java program for writing bytes to a file.
JAVA Programming
Program

NOTES

Output of the program:

Self-Instructional
48 Material
11. Write a Java program to copy one file to another. LAB: Internet and
JAVA Programming
Program

NOTES

Self-Instructional
Material 49
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

Try Yourself Questions


1. Write a Java program for sorting the strings.
2. Write a Java Program to count the number of words in a string.
3. Write a Java program for sorting names using array.
4. Write a Java Program to find whether a string or number is palindrome or
not.
5. Write a Java Program to find the duplicate characters in a string.
6. Write a Java program to demonstrate why collection framework is needed.
7. Write a Java program for demonstrating the working of
StringTokenizer class.
8. Write a Java program for demonstrating the exception handling mechanism
using the Java throws keyword.
9. Write a program for implementing a FileInputStream in Java.
10. Write a Java program to demonstrate the use of FileOutputStream
and PrintStream classes.
11. Write a Java program for writing bytes to a file.
12. Write a Java program to convert a string into byte[] and write to a file.
13. Write a Java program to copy one file to another.
14. Write a Java program for explaining the concept of exception handling
using the insufficient balance exception while displaying the Bank balance.
Create an Account class, which represents a Bank account where you can
deposit and withdraw money, and can check the Amount when you have to
withdraw money weather it will exceed your bank balance. Using user
defined exception create a custom exception called InSufficient Fund
Self-Instructional Exception to handle this scenario.
50 Material
LAB: Internet and
BLOCK V: NETWORK PROGRAMMING JAVA Programming

This block contains the programs related to Applet, Swing and Networking.
Abstract Window Toolkit (AWT) NOTES

Abstract Window Toolkit (AWT) contains numerous classes and methods that
allow you to create and manage windows. AWT is a platform-dependent API
(Application Programming Interface) to develop GUI (Graphical User Interface)
or Window-based applications in Java. A common use of the AWT is in Applets,
it is also used to create stand-alone windows that run in a GUI environment, such
as Windows.
Java Networking
Java networking is a concept of connecting two or more computing devices together
so that the resources can be shared. Java socket programming provides facility to
share data between different computing devices.
Advantage of Java Networking
1. Java networking helps in sharing resources.
2. Java networking centralizes the software management.
Applet
In Java, JApplet is a class that enables Applets to use Swing components. JApplet
is a subclass of java.applet.Applet or any Applet that contains Swing components
must be implemented with a subclass of JApplet.
Swing
Swing is a Java GUI that is used to create various applications. Swing has
components which are platform-independent. It enables the user to create buttons
and scroll bars. Swing includes packages for creating desktop applications in Java.
Swing components are written in Java language and is a part of Java Foundation
Classes (JFC).
Applet Programs

1. Write a Java Applet program demonstrating the ball bouncing animation.


Program

Self-Instructional
Material 51
LAB: Internet and
JAVA Programming

NOTES

Self-Instructional
52 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

2. Write a Java Applet program for displaying a banner.


Program

Self-Instructional
Material 53
LAB: Internet and
JAVA Programming

NOTES

Self-Instructional
54 Material
LAB: Internet and
JAVA Programming

Output of the program:


NOTES

3. Write a Java Applet program for drawing objects and displaying strings.
Program

Self-Instructional
Material 55
LAB: Internet and Output of the program:
JAVA Programming

NOTES

4. Write a Java program that prints a message by clicking on the button


using AWT Events and Applets.
Program

Self-Instructional
56 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

5. Write a Java Applet program for handling Mouse Events.


Program

Self-Instructional
Material 57
LAB: Internet and
JAVA Programming

NOTES

Self-Instructional
58 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

Self-Instructional
Material 59
LAB: Internet and 6. Write a Java program for creating a notepad like application.
JAVA Programming
Program

NOTES

Self-Instructional
60 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

Self-Instructional
Material 61
LAB: Internet and Swing Programs
JAVA Programming

7. Write a Java Swing program for displaying a list in tree like structure.

NOTES Program

Self-Instructional
62 Material
Output of the program: LAB: Internet and
JAVA Programming

NOTES

8. Write a Java Swing program for displaying numbers in the grid layout.
Program

Self-Instructional
Material 63
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

9. Write a Java Swing program for creating a calculator.


Program

Self-Instructional
64 Material
LAB: Internet and
JAVA Programming

NOTES

Self-Instructional
Material 65
LAB: Internet and
JAVA Programming

NOTES

Self-Instructional
66 Material
LAB: Internet and
JAVA Programming

NOTES

Self-Instructional
Material 67
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

Self-Instructional
68 Material
LAB: Internet and
JAVA Programming

NOTES

10. Write a Java Swing program for creating a Menu.


Program

Self-Instructional
Material 69
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

11. Write a Java program for implementing a colour changer of


background with a slider using Swing and Applet.

Program

Self-Instructional
70 Material
LAB: Internet and
JAVA Programming

NOTES

Self-Instructional
Material 71
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

12. Write a Java program for printing a chessboard pattern using Swing
and Applet.
Program

Self-Instructional
72 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

13. Write a Java program for performing encryption and decryption


of a string.
Program

Self-Instructional
Material 73
LAB: Internet and
JAVA Programming

NOTES

14. Write a Java program to create radio buttons using Swing and Applet.
Program

Self-Instructional
74 Material
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

15. Write a Java program to show the use of enumerator - enum.


Program

Self-Instructional
Material 75
LAB: Internet and
JAVA Programming

NOTES

Output of the program:

16. Write a program on socket programming in Java.


Program
Server.java

Self-Instructional
76 Material
LAB: Internet and
JAVA Programming

NOTES

Client.java

Self-Instructional
Material 77
LAB: Internet and
JAVA Programming

NOTES

Steps to Execute the Program


1. First open a command prompt and run server program. The server will
wait for client to be connected.

Self-Instructional
78 Material
2. Now, open another command prompt and run client program. This will LAB: Internet and
JAVA Programming
connect client with server. Enter a message at client side to send it to server.

NOTES

Try Yourself Questions


1. Write a Java Applet program demonstrating the vehicle moving animation.
2. Write a Java Applet program code to demonstrate that paint() method
can be called again and again.
3. Write a Java Applet program for displaying a banner “ALAGAPPA
UNIVERSITY, KARAIKUDI, TAMIL NADU”.
4. Write a Java Applet program for drawing objects and displaying strings.
5. Write a Java Applet program to draw a polygon using drawPolygon
(Polygon p) function.

Self-Instructional
Material 79
LAB: Internet and 6. Write a Java program that prints a message “WELCOME TO ALAGAPPA
JAVA Programming
UNIVERSITY” by clicking on the button using AWT Events and Applets.
7. Write a Java Applet program for handling MouseListener events.
NOTES 8. Write a Java Program to illustrate MouseMotionListener events.
9. Write a Java Applet program which displays x and y coordinate in its status
bar, whenever the user clicks anywhere in the Applet Window.
10. Write a Java Applet program for creating a notepad like application.
11. Write a Java Swing program for displaying numbers in the grid layout.
12. Write a Java Swing program for displaying a list of 10 colours in tree like
structure.
13. Write a Java Swing program for creating a simple calculator.
14. Write a Java program for implementing a colour changer of background
with a slider using Swing and Applet.
15. Write a Java program for drawing a chessboard pattern using Swing and
Applet.
16. Write a Java program to encrypt and decrypt a given string.
17. Write a Java program to demonstrate working on enum in switch case.
18. Write a Java program using socket programming where client sends a text
and server receives and prints it.

Self-Instructional
80 Material

You might also like