Java Practice Programs
Java Practice Programs
Java and Java applications; Java Development Kit (JDK); Java is interpreted,
Byte Code, JVM; Object-oriented programming; Simple Java programs. Data
types and other tokens: Boolean variables, int, long, char, operators, arrays,
white spaces, literals, assigning values; Creating and destroying objects;
Access specifiers. Operators and Expressions: Arithmetic Operators, Bitwise
operators, Relational operators, The Assignment Operator, The ? Operator;
Operator Precedence; Logical expression; Type casting; Strings, Control
Statements: Selection statements, iteration statements, Jump Statements.
Unit 2: Classes (6
Hours)
Classes in Java; Declaring a class; Class name; Super classes; Constructors;
Creating instances of class; Inner classes. Inheritance: Simple, multiple, and
multilevel inheritance; Overriding, overloading. Exception handling:
Exception handling in Java. The Applet Class: Two types of Applets; Applet
basics; Applet Architecture; An Applet skeleton; Simple Applet display
methods; Requesting repainting; Using the Status Window; The HTML
APPLET tag; Passing parameters to Applets; getDocumentbase() and
getCodebase(); ApletContext and showDocument(); The AudioClip Interface;
The AppletStub Interface; Output to the Console.
What are threads? How to make the classes threadable; Extending threads;
Implementing runnable; Synchronization; Changing state of the thread;
Bounded buffer problems, read-write problem, producer consumer
problems. Event Handling: Two event handling mechanisms; The delegation
event model; Event classes; Sources of events; Event listener interfaces;
Using the delegation event model; Adapter classes; Inner classes. Swings:
Swings: The origins of Swing; Two key Swing features; Components and
Containers; The Swing Packages; A simple Swing Application; Create a Swing
Applet; Jlabel and ImageIcon; JTextField;The Swing Buttons; JTabbedpane;
JScrollPane; JList; JComboBox; JTable.
The Concept of JDBC; JDBC Driver Types; JDBC Packages; A Brief Overview of
the JDBC process; Database Connection; Associating the JDBC/ODBC Bridge
with the Database; Statement Objects; ResultSet; Transaction Processing;
Metadata, Data types; Exceptions. Servlets: Background; The Life Cycle of a
Servlet; Using Tomcat for Servlet Development; A simple Servlet; The Servlet
API; The Javax.servlet Package; Reading Servlet Parameter; The
Javax.servlet.http package; Handling HTTP Requests and Responses; Using
Cookies; Session Tracking.
JSP, JSP Tags, Tomcat, Request String, Us5er Sessions, Cookies, Session
Objects Java Remote Method Invocation: Remote Method Invocation
concept; Server side, Client side. Enterprise java Beans; Deployment
Descriptors; Session Java Bean, Entity Java Bean; Message-Driven Bean; The
JAR File
Suggested Readings:
• Keogh, J. (2007). J2EE: The Complete Reference (Chapters 5, 6, 11, 12, 15)
Java Practice Programs
1. Java Program to Display Even Numbers From 1 to 100.
int number=100;
if (i%2==0)
//prints stars
System.out.print("* ");
System.out.println();
}
3. A Java program to create an ATM program for representing ATM transaction.
import java.util.Scanner;
while(true)
switch(choice)
case 1:
withdraw = sc.nextInt();
//check whether the balance is greater than or equal to the withdrawal amount
else
System.out.println("Insufficient Balance");
System.out.println("");
break;
case 2:
deposit = sc.nextInt();
System.out.println("");
break;
case 3:
System.out.println("Balance : "+balance);
System.out.println("");
break;
case 4:
System.exit(0);
}
4. Program to print the elements of an array in reverse order.
//Initialize array
System.out.println();
int a[][]={{1,3,4},{2,4,3},{3,4,5}};
int b[][]={{1,3,4},{2,4,3},{1,2,4}};
//creating another matrix to store the sum of two matrices
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(c[i][j]+" ");
}}
import java.util.Scanner;
class ReverseStringExample1
String s;
{
System.out.print(s.charAt(i-1)); //printing the character at index i-1
import java.util.Scanner;
class ReverseStringExample2
String s;
s=sc.nextLine();
while(i>0)