Java File
Java File
BTech: II Year
Name :
Branch :
Section :
Roll No. :
Certificate
This is to certify that the experimental work entered in this journal as per the B
Tech II year III semester, syllabus prescribed by the RGPV was done by Mr.
………………………………… in the Java Programming Lab (CSIT 306) of
Acropolis Institute during the academic year 2023- 2024.
Signature of Faculty
To be an academic leader for the development of human potential so as to meet the global
challenges.
Course Objective:
The subject/course objectives support the program objectives and outcomes. This subject will help students to
learn and understand the concept of
CSIT-306.CEO1 Understand fundamentals of programming such as variables, conditional and
iterative execution, methods, etc
CSIT-306.CEO2 Understand fundamentals of object-oriented programming in Java and be familiar
of the important concepts like class, inheritance and multithreading, AWT and
JDBC.
CSIT-306.CEO3 Students will able to use the Java SDK environment to create, debug and run
simple Java programs.
Course Outcome:
Upon completion of this subject / course the student will be able to:
Bloom’s Course Outcomes
levels
CSIT-306.1 Apply The concepts of Java programming.
Analyze
understand
CSIT-306.2 Apply The basic terminology used in computer programming and write,
Analyze
compile and debug
programs in JAVA language.
understand
CSIT-306.3 Apply . The different data types, decision structures, loops, functions to design
Analyze
Java programs.
understand
CSIT-306.4 Apply Develop program using the java collection API as well as the java
Analyze standard class library.
understand
CSIT-306.5 Apply Develop Java applets.
Analyze
understand
DO’S
❖ While entering into the LAB students should wear their ID cards.
❖ Students should sign in the LOGIN REGISTER before entering into the laboratory.
❖ Students should come with observation and record notebooks to the laboratory.
❖ After completing the laboratory exercise, make sure to shutdown the system properly
DONT’S
SYLLABUS
I I-Overview of Java, Installation, First Simple Program, Compilation process , Java
Keywords , Identifiers , Literals, Comments, Data Types, Variables, Dynamic initialization, type
conversion and casting, Operators, Control Statements.
II -Declaring Objects, Introducing Methods, Constructors, this Keyword, Garbage
Collection, finalize Method, Overloading Methods, Overloading Constructors, Using Objects as
Parameters, Inheritance, Creating a Multilevel Hierarchy, Packages and Interfaces, Exception
Handling, Multithreaded.
III The Applet Class: Applet Basics, The Applet Class, Applet Architecture, Applet
Initialization and Termination , Simple Applet Display Methods, Simple Banner Applet, Using
the Status Window, The HTML APPLET Tag, Passing Parameters to Applets, Improving the
Banner Applet.
IV -Introducing the AWT: Working with Windows, Graphics, and Text, AWT Classes,
Window Fundamentals, Component, Container, Panel, Frame, Working with Frame Windows,
Handling Events in a Frame Window, AWT Controls, Layout Managers, and Menus, Adding
and Removing Controls, Grid Layout, Border Layout, introduction to swing and servlet.
V Event Handling, Two Event Handling Mechanisms, The Delegation Event Model,
Events, Event Sources, Event Listeners, Event Classes, The Mouse Event Class and others,
JDBC: JDBCODBC bridge, the connectivity model, the driver manager, navigating the result set
object contents, the JDBC exceptional classes, connecting to remote database
HARDWARE REQUIREMENTS:
Processors - 2.0 GHz or Higher
RAM - 512 MB or Higher
Hard Disk - 20 GB or Higher
SOFTWARE REQUIREMENTS
● Operating System: Windows 8/8.1/10/11
● JavaC Compiler
PREREQUISITE:-
Basics of OOPs
Java is a multi-purpose computer-based language that is created on the ideology of write-once run anywhere. It
was invented by James Gosling and Sun Microsystems back in 1991 and at that time their only intention was to
enhance the code reusability. Java is an object-oriented programming language based on C and C++ languages,
however, it is an improved and simplified programming language with the capability of handling errors in
programming. Java is used for multiple purposes such as web development, mobile application developments,
etc.
Aim:
class Main {
System.out.println("0827CI221061");
Output:
long l = 1000000000L;
float f = 3.14f;
double d = 3.141592653589793;
char c = 'A';
boolean b = true;
System.out.println("HIMANI NAMDEO\n0827CI221061");
Output:
int x = 7;
long y = x;
float z = y;
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
Output:
double d = 166.66;
long l = (long)d;
int i = (int)l;
System.out.println("\nHIMANI NAMDEO");
System.out.println("\n 0827CI221061");
Output:
name = sname;
{System.out.println("\nHIMANI NAMDEO");
s.printstud();
Output:
class Student{
int id;
String name;
class TestStudent2{
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
s1.id=27;
s1.name="Anuj";
Output:
count++;
obj1.increment();
obj2.increment();
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
Output:
return a + b;
System.out.println("HIMANI NAMDEO");
System.out.println("0827CI221061");
Output:
int a=20;
char b='a';
boolean d=true;
byte e=10;
short f=20;
long l=40;
float fl=50.0F;
double dl=60;
Integer i=Integer.valueOf(a);
Integer j=a;
Character c=b;
Boolean g=d;
Byte h=e;
Short k=f;
Long m=l;
Float n=fl;
Double o=dl;
System.out.println("0827CI221061");
System.out.println(b+" "+c);
System.out.println(d+" "+g);
System.out.println(e+" "+h);
System.out.println(f+" "+k);
System.out.println(l+" "+m);
System.out.println(fl+" "+n);
System.out.println(dl+" "+o);
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
int a=i.intValue();
int b=i;
char c=ch;
boolean d=bl;
long g=l;
float h=fl;
double j=dl;
System.out.println(ch+" "+c);
System.out.println(d+" "+bl);
System.out.println(l+" "+g);
CSIT Department Java Programming Lab Manual Session July-Dec2023
System.out.println(fl+" "+h);
System.out.println(dl+" "+j); }}
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
System.out.println("Command-Line arguments");
System.out.println(str);
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
if (args.length > 0) {
System.out.println(arg);
} else {
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
System.out.println("Enter a number:");
int a=sc.nextInt();
if(a%2==0)
System.out.println("Even Number");
else
System.out.println("Odd Number");
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
int a=sc.nextInt();
int b=sc.nextInt();
int c;
c=a;
a=b;
b=c;
Output:
// protected method
System.out.println("dog is an animal");
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
dog.display();
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
System.out.println("i am an animal");
System.out.println("i have"+legCount+"legs");
animal.legCount=4;
animal.display();
Output:
Main() {
System.out.println("\nHIMANI NAMDEOI");
System.out.println("0827CI221061");
System.out.println("Constructor Called:");
name = "Programiz";
Output:
String languages;
Main(String lang) {
languages = lang;
System.out.println("\nHIMANI NAMDEOI");
System.out.println("0827CI221061");
Output:
String name;
class Main {
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
labrador.display();
labrador.eat();
} }
@Override
class Main {
System.out.println("0827CI221061");
labrador.eat();
labrador.bark();
Output:
return a + b;
return a + b + c;
return a + b;
System.out.println("\nHIMANI NAMDEOI");
System.out.println("0827CI221061");
System.out.println("Bark");
System.out.println("Meow");
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
Bike10(){
speedlimit=70;
System.out.println(speedlimit);
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
new Bike10();
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
System.out.println(obj.constantValue); // Outputs 10
Output:
this.age = age;
System.out.println("\nHIMANI NAMDEOI");
System.out.println("0827CI221061");
student1.setDetails("John", 20);
student1.displayDetails();
CSIT Department Java Programming Lab Manual Session July-Dec2023
Student student2 = new Student();
student2.setDetails("Alice", 22);
student2.displayDetails();
} }
Output:
this.length = length;
this.width = width;
this(side, side); }
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
square.displayArea();
} }
Output:
void start() {
System.out.println("Vehicle started");
void start() {
System.out.println("Car started");
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
myCar.start();
Output:
String sound;
Animal(String sound) {
this.sound = sound;
void makeSound() {
String breed;
this.breed = breed;
void displayDetails() {
System.out.println("\nHIMANI NAMDEOI");
System.out.println("0827CI221061");
myDog.displayDetails();
System.out.println("\nHIMANI NAMDEOI");
System.out.println("0827CI221061");
Parent.staticMethod();
staticMethod();
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
staticVariable = 20;
Output:
Parent() {
Child() {
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
Output:
int parentVar;
Parent(int value) {
this.parentVar = value;
int childVar;
this.childVar = childValue;
System.out.println("Parameterized constructor of Child class with values: " + parentValue + ", " +
childValue);
System.out.println("\nHIMANI NAMDEO");
CSIT Department Java Programming Lab Manual Session July-Dec2023
System.out.println("0827CI221061");
}}
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
obj.run();
Output:
class TestBank{
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
Bank b;
b=new SBI();
b=new PNB();
Output:
void print();
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
obj.print();
Output:
interface Language {
class Main {
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
language.getName("Java");
}}
Output:
Aim: Two Programs on Difference between Abstract class and Interface in Java
interface A{
void b();
void c();
void d();
} class M extends B{
class Test5{
System.out.println("\nHIMANI NAMDEO");
a.a();
a.b();
Output:
Aim: Two Programs on Difference between Abstract class and Interface in Java
//same logic using abstract class
void display() {
void draw() {
System.out.println("Drawing a circle.");
}}
System.out.println("HIMANI NAMDEO\n0827CI221061");
circle.draw();
circle.display();
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
System.out.println(numbers[i]);
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
int sum = 0;
sum += numbers[i];
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
int sum = 0;
sum += matrix[i][j];
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
// Extract a substring
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
try {
int divideByZero = 5 / 0;
catch (ArithmeticException e) {
System.out.println("\nAKSHAT TIWARI");
System.out.println("0827CI221015");
try {
int divideByZero = 5 / 0;
catch (ArithmeticException e) {
finally {
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
try {
} catch (NullPointerException e) {
// Handle NullPointerException
Output:
CSIT Department Java Programming Lab Manual Session July-Dec2023
Program No. 25(b)
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
try {
} catch (ArrayStoreException e) {
// Handle ArrayStoreException
Output:
class Testthrows1{
m();
} void p(){
try{
n();
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
obj.p();
System.out.println("normal flow...");
Output:
class M{
class Testthrows3{
System.out.println("\nHIMANI ANMDEO");
System.out.println("0827CI221061");
M m=new M();
m.method();
System.out.println("normal flow...");
Output:
System.out.println("thread is running...");
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
t1.start();
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
t.start();
System.out.println(str);
Output:
System.out.println("thread is running..."); }
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
th1.start();
System.out.println(str);
Output:
import java.util.*;
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
g1. start();
Output:
for(int i=1;i<5;i++){
try{Thread.sleep(500);}catch(InterruptedException e){System.out.println(e);}
System.out.println(i);
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
t2.start();
Output:
import java.io.IOException;
class CreateFile {
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061\n");
try {
if (f0.createNewFile()) {
} else {
exception.printStackTrace();
Output:
class FileInfo {
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
if (f0.exists()) {
} else {
Output:
import java.io.IOException;
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
try {
} else {
} catch (IOException e) {
}}
Output:
import java.io.IOException;
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
if (file.exists()) {
if (file.createNewFile()) {
} else {
} catch (IOException e) {
}}
import java.io.IOException;
System.out.println("\nHIMANI NAMDEO");
try (FileOutputStream fos = new FileOutputStream(filePath)) // Binary data (in this case, an array of bytes)
fos.write(binaryData)
} catch (IOException e) {
Output:
import java.io.IOException;
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
fos.write(textToWrite.getBytes());
}}
Output:
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
try {
int i = input.read();
while(i != -1) {
System.out.print((char)i);
input.close();
catch(Exception e) {
e.getStackTrace();
Output:
import java.io.FileInputStream;
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
int character;
while (input.available()!=0) {
character = input.read();
} input.close();
catch (Exception e) {
e.printStackTrace();
}}}
Output:
{ this.name = name;
this.age = age;
this.ID = nextId++;
class UseEmployee {
System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");
E.show();
F.show();
G.show();
E.showNextId();
F.showNextId();
G.showNextId();
X.show();
Y.show();
X.showNextId();
Y.showNextId();
E.showNextId();
Output:
class prep {
{ try
catch (Throwable e) {
throw e;
finally {
super.finalize();
d.finalize();
Output:
import java.applet.Applet;
import java.awt.Graphics;
@Override
Output:
import java.applet.Applet;
import java.awt.Graphics;
@Override
Output:
Import java.util.Scanner;
{ System.out.println("\nHIMANI NAMDEO");
System.out.println("0827CI221061");