0% found this document useful (0 votes)
5 views37 pages

Java Word File..

The document is a practical file for a Java programming course, detailing various exercises and programs to be completed by the student, Ayush Kawaduji Mandwe. It includes tasks related to setting up the Java environment, using control statements, implementing classes and methods, working with arrays and vectors, and database connectivity. Each practical section provides code examples and expected outputs for the exercises.

Uploaded by

djalokchrono576
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views37 pages

Java Word File..

The document is a practical file for a Java programming course, detailing various exercises and programs to be completed by the student, Ayush Kawaduji Mandwe. It includes tasks related to setting up the Java environment, using control statements, implementing classes and methods, working with arrays and vectors, and database connectivity. Each practical section provides code examples and expected outputs for the exercises.

Uploaded by

djalokchrono576
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 37

Department of Computer Science & Engineering

SESSION : 24-25

PRACTICAL FILE

NAME OF SUBJECT : JAVA


NAME OF STUDENT : AYUSH KAWADUJI MANDWE
ENROLLMENT NO : 2331800166
INDEX
SR. NO NAME OF PRACTICAL
Setup Java Programming development environment using:
1  Command prompt.(Classpath and path setup)
 Any IDE (Eclipse, Netbeans, VScode, Jcreator etc.).

Write programs to evaluate different types of expressions.


2
Write programs to demonstrate use of: if statements (all forms of
3
 if statement
 Switch – Case statement
 Different types of Loops(for,while and do..while).

4 Write programs for implementation of different methods of:

 String class.
 StringBuffer class.

Write programs to demonstrate:


5  Use of Array.
 Use of Vectors.

Write programs using Wrapper Class:


6
 to convert primitive into object.
 to convert object into primitive.

Develop a program for implementation of


7
different types of constructors.

Develop program to implement:


8
 Single inheritance.
 Multilevel inheritance.

Develop program for implementation of interface.


9
10 *Write programs to demonstrate use of:

 Built in packages
 User defined packages.

11 *Write programs using multithreading.

Write programs for implementation of try, catch and finally block.


12
13 *Write programs for implementation of throw, throws clause.

Write program to design any type of form using AWT components.


14
Write program to create a menu bar with various menu items and sub menu items.
15
Write program to demonstrate the use of border layout. The layout shows four buttons
16 at four sides with captions “left”, “right”, “top” and “bottom” using Swing
Components.

17 *Write program to design a calculator to demonstrate the use of grid layout


using swing components

Write program using swing to display a JComboBox in a JFrame .


18
Write program to create JTree and JTable.
19
Write program to handle key events and mouse events.
20
21 Write program to implement action event in frame using swing components.

Write program to handle text event on swing components.


22
Write program to retrieve hostname and IP address using InetAddress class.
23
24 *Write program to demonstrate various methods of:

 URL class.
 URLConnection.
25 *Write program that demonstrates connection oriented communication using
socket.

Write program to demonstrate sending and receiving data through datagram.


26
27 *Write program to:

 Create sample database.


 Make connectivity with database.

28 *Write program to implement following operations on database:

 Insert record.
 Update record.
 Delete record.

Write program to demonstrate the use of PreparedStatement.


29
30 *Write program to retrieve data from table using ResultSet interface.(Use
various methods of navigation methods).

Name of Faculty & Sign HOD


SIGN

Practical 1 : Setup Java Programming development


environment using:
 Command prompt.(Classpath and path setup)
 Any IDE (Eclipse, Netbeans, VScode, Jcreator etc.).
:

 package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

System.out.println("welcome in java programming");

Output :
Practical 2 : Write programs to evaluate different types of
expressions.
:

 package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

int a = 10;

int b = 5;

int sum = a + b;

int difference = a - b;

int product = a * b;

double quotient = (double) a / b;

int remainder = a % b;

System.out.println("Arithmetic Expressions:");

System.out.println("Sum: " + sum);

System.out.println("Difference: " + difference);

System.out.println("Product: " + product);

System.out.println("Quotient: " + quotient);

System.out.println("Remainder: " + remainder);

}
Output :
Practical 3 : Write programs to demonstrate use of: if
statements (all forms of
 if statement
 Switch – Case statement
 Different types of Loops(for,while and do..while).
:

1) Write a program to check multiple conditions using if statement along with


logical
Operators.

:
package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter your age: ");

int age = scanner.nextInt();

System.out.print("Enter your salary: ");

double salary = scanner.nextDouble();

if (age >= 18 && salary >= 30000) {

System.out.println("You are eligible for the loan.");

} else {

System.out.println("You are not eligible for the loan.");

}
}
}
Output:

2) Write a program to check no is even or odd.


: package javaapplication1;
import java.util.Scanner;
public class JavaApplication1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a number: ");
int number = scanner.nextInt();
if (number % 2 == 0) {
System.out.println(number + " is even.");
} else {
System.out.println(number + " is odd.");
}
scanner.close();
}
}

Output : 3
3) Write a program to check switch-case using character datatype.

:
package javaapplication1;
import java.util.Scanner;
public class JavaApplication1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a character (A, B, C): ");
char ch = scanner.next().charAt(0);
switch (ch) {
case 'A':
System.out.println("You entered A.");
break;
case 'B':
System.out.println("You entered B.");
break;
case 'C':
System.out.println("You entered C.");
break;
default:
System.out.println("Invalid character.");
break;
}
scanner.close();
}
}

Output :

4) Write a program to display 1 to 20 numbers using for, while and do-while loop.
:
package javaapplication1;
import java.util.Scanner;
public class JavaApplication1 {
public static void main(String[] args) {
System.out.println("Using for loop:");
for (int i = 1; i <= 20; i++) {
System.out.print(i + " ");
}
System.out.println("\n\nUsing while loop:");
int j = 1;
while (j <= 20) {
System.out.print(j + " ");
j++;
}
System.out.println("\n\nUsing do-while loop:");
int k = 1;
do {
System.out.print(k + " ");
k++;
} while (k <= 20);
}
}
Output :

5) Develop a program to use logical operators in do-while loop.

:
package javaapplication1;
import java.util.Scanner;
public class JavaApplication1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int number;
do {
System.out.print("Enter a number (1-10) to continue or 0 to exit: ");
number = scanner.nextInt();
if (number >= 1 && number <= 10) {
System.out.println("You entered: " + number);
} else if (number != 0) {
System.out.println("Invalid input. Please enter a number between 1 and 10.");
}
}
while (number != 0);
System.out.println("Exiting the program.");
scanner.close();
}
}
Output :
Practical 4: Write programs for implementation of different
methods of:

 String class.
 StringBuffer class.

:
1) Write a program to show the use of all methods of String class.

package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

String str = "Hello, World!";

System.out.println("Length: " + str.length());

System.out.println("Character at index 7: " + str.charAt(7));

System.out.println("Substring (7, 12): " + str.substring(7, 12));

System.out.println("Index of 'o': " + str.indexOf('o'));

System.out.println("Last index of 'o': " + str.lastIndexOf('o'));

System.out.println("Replace 'World' with 'Java': " + str.replace("World", "Java"));

System.out.println("Uppercase: " + str.toUpperCase());

System.out.println("Lowercase: " + str.toLowerCase());

String strWithSpaces = " Hello, World! ";

System.out.println("Trimmed: '" + strWithSpaces.trim() + "'");

String[] words = str.split(", ");

System.out.println("Split: ");
for (String word : words) {

System.out.println(word);

System.out.println("Contains 'World': " + str.contains("World"));

System.out.println("Starts with 'Hello': " + str.startsWith("Hello"));

System.out.println("Ends with '!': " + str.endsWith("!"));

char[] charArray = str.toCharArray();

System.out.println("Character Array: ");

for (char c : charArray) {

System.out.print(c + " ");

String str2 = "Hello, World!";

System.out.println("\nEquals 'Hello, World!': " + str.equals(str2));

System.out.println("Equals ignore case 'hello, world!': " + str.equalsIgnoreCase("hello, world!"));

Output :
2) Write a program to implement all methods of StringBuffer class.

Output :
Practical 5: Write programs to demonstrate:
 Use of Array.
 Use of Vectors.

:
1) Write a program to implement multidimensional array.

: package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

int[][] matrix = {

{1, 2, 3},

{4, 5, 6},

{7, 8, 9}

};

System.out.println("Multidimensional Array (Matrix):");

for (int i = 0; i < matrix.length; i++) {

for (int j = 0; j < matrix[i].length; j++) {

System.out.print(matrix[i][j] + " ");

System.out.println();

Output :
2) Write a program to display array elements using for-each loop.

: package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

String[] fruits = {"Apple", "Banana", "Cherry", "Date"};

System.out.println("Array Elements:");

for (String fruit : fruits) {

System.out.println(fruit);

Output :
3) Write a program to insert different elements in the Vector & display them

: package javaapplication1;

import java.util.Scanner;

import java.util.Vector;

public class JavaApplication1 {

public static void main(String[] args) {

Vector<Object> vector = new Vector<>();

vector.add("Hello");

vector.add(123);

vector.add(45.67);

vector.add(true);

System.out.println("Elements in the Vector:");

for (Object element : vector) {

System.out.println(element);

Output :
4) Write a program to use different methods of Vector class.
: package javaapplication1;

import java.util.Scanner;

import java.util.Vector;

public class JavaApplication1 {

public static void main(String[] args) {

Vector<String> vector = new Vector<>();

vector.add("Apple");

vector.add("Banana");

vector.add("Cherry");

System.out.println("Initial Vector: " + vector);

vector.add(1, "Orange");

System.out.println("After adding 'Orange' at index 1: " + vector);

vector.remove("Banana");

System.out.println("After removing 'Banana': " + vector);

String elementAtIndex1 = vector.get(1);

System.out.println("Element at index 1: " + elementAtIndex1);

System.out.println("Size of the vector: " + vector.size());

System.out.println("Is the vector empty? " + vector.isEmpty());

vector.clear();

System.out.println("After clearing the vector, is it empty? " + vector.isEmpty());

vector.add("Grapes");
System.out.println("Vector after adding 'Grapes': " + vector);

Output :
Practical 6: Write programs using Wrapper Class:
 to convert primitive into object.
 to convert object into primitive.

1. Write a program to show the use of Integer Wrapper class methods.

package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

Integer intObj1 = new Integer(10);

Integer intObj2 = new Integer("20");

System.out.println("Integer Object 1: " + intObj1);

System.out.println("Integer Object 2: " + intObj2);

String strNumber = "30";

int parsedInt = Integer.parseInt(strNumber);

System.out.println("Parsed Integer from String: " + parsedInt);

String intToString = intObj1.toString();

System.out.println("Integer to String: " + intToString);

int comparisonResult = intObj1.compareTo(intObj2);

if (comparisonResult < 0) {

System.out.println(intObj1 + " is less than " + intObj2);

} else if (comparisonResult > 0) {

System.out.println(intObj1 + " is greater than " + intObj2);

} else {

System.out.println(intObj1 + " is equal to " + intObj2);

int max = Integer.max(intObj1, intObj2);


int min = Integer.min(intObj1, intObj2);

System.out.println("Maximum: " + max);

System.out.println("Minimum: " + min);

int number = 15;

String binaryString = Integer.toBinaryString(number);

String octalString = Integer.toOctalString(number);

String hexString = Integer.toHexString(number);

System.out.println("Binary representation of " + number + ": " + binaryString);

System.out.println("Octal representation of " + number + ": " + octalString);

System.out.println("Hexadecimal representation of " + number + ": " + hexString);

System.out.println("Maximum Integer value: " + Integer.MAX_VALUE);

System.out.println("Minimum Integer value: " + Integer.MIN_VALUE);

Output :

2. Write a program to convert String value into Integer class object

package javaapplication1;
import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

String strValue = "12345";

Integer intValue = Integer.valueOf(strValue);

System.out.println("String value: " + strValue);

System.out.println("Converted Integer object: " + intValue);

Output :

3) Write a program to make use of Character Wrapper class Methods.


:
package javaapplication1;

import java.util.Scanner;
public class JavaApplication1 {

public static void main(String[] args) {

char ch = 'A';
Character charObj = Character.valueOf(ch);

System.out.println("Character Object: " + charObj);


System.out.println("Is '" + ch + "' a digit? " + Character.isDigit(ch));
System.out.println("Is '" + ch + "' a letter? " + Character.isLetter(ch));
System.out.println("Is '" + ch + "' uppercase? " + Character.isUpperCase(ch));
System.out.println("Is '" + ch + "' lowercase? " + Character.isLowerCase(ch));
char lowerCh = 'b';
char upperCh = Character.toUpperCase(lowerCh);
System.out.println("Uppercase of '" + lowerCh + "' is '" + upperCh + "'");

char upperCh2 = 'C';


char lowerCh2 = Character.toLowerCase(upperCh2);
System.out.println("Lowercase of '" + upperCh2 + "' is '" + lowerCh2 + "'");

char digitChar = '5';


int numericValue = Character.getNumericValue(digitChar);
System.out.println("Numeric value of '" + digitChar + "' is: " + numericValue);

char spaceChar = ' ';


System.out.println("Is '" + spaceChar + "' whitespace? " +
Character.isWhitespace(spaceChar));
}
}

Output :

4) Write a program to convert Integer object value into primitive datatype byte, short and
double value
:
package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

Integer intObj = Integer.valueOf(12345);


byte byteValue = intObj.byteValue();
short shortValue = intObj.shortValue();
double doubleValue = intObj.doubleValue();

System.out.println("Integer Object: " + intObj);


System.out.println("Converted to byte: " + byteValue);
System.out.println("Converted to short: " + shortValue);
System.out.println("Converted to double: " + doubleValue);
}
}

Output :
Practical 7 : Develop a program for implementation of
different types of constructors.

:
1) Write a program to implement different types of constructors to perform addition of
complex numbers?
:
package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

class Complex {
private double real;
private double imaginary;

public Complex() {
this.real = 0;
this.imaginary = 0;
}

public Complex(double real, double imaginary) {


this.real = real;
this.imaginary = imaginary;
}

public Complex(Complex other) {


this.real = other.real;
this.imaginary = other.imaginary;
}

public Complex add(Complex other) {


return new Complex(this.real + other.real, this.imaginary + other.imaginary);
}

public void display() {


if (imaginary >= 0) {
System.out.println(real + " + " + imaginary + "i");
} else {
System.out.println(real + " - " + Math.abs(imaginary) + "i");
}
}
}

Complex c1 = new Complex(3, 2);


Complex c2 = new Complex(1, 7);
Complex sum = c1.add(c2);

System.out.print("First Complex Number: ");


c1.display();

System.out.print("Second Complex Number: ");


c2.display();

System.out.print("Sum of Complex Numbers: ");


sum.display();
}
}

Output :
Practical 8 : Develop program to implement:
 Single inheritance.
 Multilevel inheritance

1) . Write a program to implement single inheritance.


:
package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {


class Animal {
public void eat() {
System.out.println("This animal eats food.");
}
}

class Dog extends Animal {


public void bark() {
System.out.println("The dog barks.");
}
}

Dog dog = new Dog();


dog.eat();
dog.bark();
}
}

Output :
2) Write a program to implement multilevel inheritance
: class Animal {
public void eat() {
System.out.println("This animal eats food.");
}
}

class Dog extends Animal {


public void bark() {
System.out.println("The dog barks.");
}
}

class Puppy extends Dog {


public void weep() {
System.out.println("The puppy weeps.");
}
}

public class MultilevelInheritanceExample {


public static void main(String[] args) {
Puppy puppy = new Puppy();
puppy.eat();
puppy.bark();
puppy.weep();
}
}

Output :

3) Develop a program to implement the multilevel inheritance.

: class Person {
private String name;
private int age;

public Person(String name, int age) {


this.name = name;
this.age = age;
}

public void displayInfo() {


System.out.println("Name: " + name);
System.out.println("Age: " + age);
}
}

class Employee extends Person {


private String employeeId;

public Employee(String name, int age, String employeeId) {


super(name, age);
this.employeeId = employeeId;
}

public void displayEmployeeInfo() {


displayInfo();
System.out.println("Employee ID: " + employeeId);
}
}

class Manager extends Employee {


private String department;

public Manager(String name, int age, String employeeId, String department) {


super(name, age, employeeId);
this.department = department;
}

public void displayManagerInfo() {


displayEmployeeInfo();
System.out.println("Department: " + department);
}
}

public class MultilevelInheritanceExample {


public static void main(String[] args) {
Manager manager = new Manager("Ayush", 35, "E123", "Sales");
manager.displayManagerInfo();
}
}
Output :

4) Develop a program to calculate he room area and volume to illustrate the concept of single
inheritance.

package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

class Room {

private double length;

private double width;

public Room(double length, double width) {

this.length = length;

this.width = width;

public double calculateArea() {

return length * width;

class RoomWithHeight extends Room {


private double height;

public RoomWithHeight(double length, double width, double height) {

super(length, width);

this.height = height;

public double calculateVolume() {

return calculateArea() * height;

RoomWithHeight room = new RoomWithHeight(5.0, 4.0, 3.0);

double area = room.calculateArea();

double volume = room.calculateVolume();

System.out.println("Room Area: " + area + " square units");

System.out.println("Room Volume: " + volume + " cubic units");

Output :
Practical 9 : Develop program for implementation of
interface.

1) Demonstrate the use of interfaces to implement the concept of multiple inheritance.( Attach
the code at the end).
:
package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

interface Animal {
void eat();
void sleep();
}

interface Pet {
void play();
void groom();
}

class Dog implements Animal, Pet {


public void eat() {
System.out.println("The dog eats dog food.");
}

public void sleep() {


System.out.println("The dog sleeps in its kennel.");
}

public void play() {


System.out.println("The dog plays fetch.");
}

public void groom() {


System.out.println("The dog is being groomed.");
}
}
Dog dog = new Dog();

dog.eat();
dog.sleep();
dog.play();
dog.groom();
}
}

Output :

2) Develop a program to find area of rectangle and circle using interfaces


: package javaapplication1;

import java.util.Scanner;

public class JavaApplication1 {

public static void main(String[] args) {

interface Shape { double calculateArea(); }

class Rectangle implements Shape { private double length; private double width;

public Rectangle(double length, double width) {


this.length = length;
this.width = width;
}

@Override
public double calculateArea() {
return length * width;
}
}

class Circle implements Shape { private double radius;

public Circle(double radius) {


this.radius = radius;
}

@Override
public double calculateArea() {
return Math.PI * radius * radius;
}

Shape rectangle = new Rectangle(5.0, 3.0);


Shape circle = new Circle(4.0);

System.out.println("Area of Rectangle: " +


rectangle.calculateArea() + " square units");
System.out.println("Area of Circle: " + circle.calculateArea() +
" square units");
}

Output :
Practical 10 : *Write programs to demonstrate use of:
 Built in packages
 User defined packages.

You might also like