507-Shashwat Tripathi Java Exp 3

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

PRACTICAL FILE

OF

Java Programming Lab


(Paper code: ETCS-357)

Submitted to: Submitted by:


Mr. Vedprakash Sharma Shashwat Tripathi
Assistant Professor 50715603120
IT Dept. Section: T-8 (B)

DR. AKHILESH DAS GUPTA INSTITUTE OF TECHNOLOGY


AND MANAGEMENT
NEW DELHI
INDEX
S.No. Experiment Date Remarks T. Sign
1. Write a program in java to perform addition of 2
numbers using command Line
Argument.
2. Write a program in to implement different types of
variables in Java (local, static and
instance variables).
3. Write a program in java to Perform basic arithmetic
calculations using switch case.
4. Write a program in java to perform sorting.
5. Create a java program to implement stack and
queue concept.
6. Write a program in java to perform single level
inheritance.
7. Write a program in java to perform Multilevel
inheritance.
8. Write a java package to show dynamic
polymorphism and interfaces.
9. Write a program in java to perform constructor
overloading.
10. Create a customized exception and also make use
of all the 5 exception keywords.
11. Write a program to show use of customized
packages.
12. Write a program to show that String is immutable
and String buffer is mutable.
13. Write a program to perform all String operations.
14. Write a program to check String is Palindrome or
not.
15. Develop an analog clock using applet.
16. (a) Write a program to print table of 2 numbers
without using synchronization using
multithreading.
(b) Write a program to print table of 2 numbers
using synchronization using
multithreading.
17. Write a java program to show multithreaded
producer and consumer application.
18. Write a program to perform event handling in Java.
Create a GUI using AWT that
performs arithmetic operations.
19. Convert the content of a given file into the
uppercase content of the same file.
20. Write a program to perform operations such as
insertion, deletion, updation and
retrieval of records on Employee database using
JDBC.
21. Develop a scientific calculator using swings.
22. Create an editor like MS-word using swings.

Experiment No. 1

Aim: Write a program to perform addition of two numbers using command line.

Theory: In Java, finding the sum of two or more numbers is very easy. First,
declare and initialize two variables to be added. Another variable to store the sum of
numbers. Apply mathematical operator (+) between the declared variable and store
the result. The following program calculates and prints the sum of two numbers.

Program:

public class Sum

public static void main(String arg[])

int n1 = 10, n2 = 20, sum;

sum = n1 + n2;

System.out.println("The sum of numbers is: "+sum);

}
}

Output:

Experiment No. 2

Aim: Write a program to implement different types of variables in java.

Theory:
1) Local Variable
A variable declared inside the body of the method is called local variable. You can
use this variable only within that method and the other methods in the class aren't
even aware that the variable exists.

2) Instance Variable
A variable declared inside the class but outside the body of the method, is called an
instance variable. It is not declared as static.

3) Static variable
A variable that is declared as static is called a static variable. It cannot be local. You
can create a single copy of the static variable and share it among all the instances of
the class. Memory allocation for static variables happens only once when the class
is loaded in the memory.

Program:

class Variables {
int var = 20; //local

public String geek; //Declared Instance Variable

public static String stavar; //Declared static variable

public Variables()
{
this.geek = "This is instance variable"; //Initialize Instance Variable
}

public static void main (String arg[])


{

System.out.println("Static : "+ Variables.stavar);

Variables name=new Variables();


System.out.println("Instance : "+ name.geek);

}}

Output:
Experiment No. 3

Aim: Write a program to implement basic arithmetic calculation using switch.

Theory: Switch statements are basically a combination of if-else statement.

Program

import java.util.Scanner;
class Calc {
public static void main(String[] args) {

char operator;
Double number1, number2, result;

Scanner input = new Scanner(System.in);

System.out.println("Choose an operator: +, -, *, or /");


operator = input.next().charAt(0);

System.out.println("Enter first number");


number1 = input.nextDouble();

System.out.println("Enter second number");


number2 = input.nextDouble();

switch (operator) {

case '+':
result = number1 + number2;
System.out.println(number1 + " + " + number2 + " = " + result);
break;

case '-':
result = number1 - number2;
System.out.println(number1 + " - " + number2 + " = " + result);
break;

case '*':
result = number1 * number2;
System.out.println(number1 + " * " + number2 + " = " + result);
break;
case '/':
result = number1 / number2;
System.out.println(number1 + " / " + number2 + " = " + result);
break;

default:
System.out.println("Invalid operator!");
break;
}

input.close();
}
}

Output:

You might also like