PRACTICAL_OF_JAVA[1] pratham
PRACTICAL_OF_JAVA[1] pratham
PRACTICAL-1
AIM:- Install JDK and Setup a Java Programming development environment by
using:
1) Command Prompt (SET PATH command and using Environment Variable).
2) Any open source IDE (Eclipse, Jcreater etc)
Install JDK
Download JDK:
Go to the Oracle JDK download page and download the installer.
Install JDK:
Run the installer and follow the prompts.
Set Up Environment Variables Set JAVA_HOME:
Right-click "This PC" > "Properties" > "Advanced system settings" > "Environment Variables."
Click "New" under System variables, set Variable name as JAVA_HOME, and Variable
value as your JDK path (e.g., C:\Program Files\Java\jdk-[version]).
Update PATH:
In the same Environment Variables window, find Path, click "Edit," and add a new entry for
%JAVA_HOME%\bin.
Verify Installation:
Open Command Prompt and run:
bash java -version javac -version Install
PRACTICAL-2
AIM: Test the java development environment setup by implementing a simple java
program (print: “OOP with JAVA”).
Code:
class p1 {
public static void main(String[] args)
{
System.out.println("OOP With JAVA");
}
}
Output:
Name: Pratham Suthar Subject: OOP with JAVA
En no: 236420316053 Code: 4341602
PRACTICAL-3
AIM: Develop a basic java program that demonstrates data types of JAVA.
CODE:
public class p3
{
public static void main(String[] args) {
// Integer data type
int myInt = 100;
System.out.println("Integer: " + myInt);
OUTPUT:
Name: Pratham Suthar Subject: OOP with JAVA
En no: 236420316053 Code: 4341602
Practical:4
Aim: Develop a Java program to swap two numbers without using a temporary variable and
with using a temporary variable (use command line argument to accept value from user).
Code:
public class j4
{
public static void main(String[] args)
{
if (args.length != 2)
{
System.out.println("Please provide exactly two numbers as arguments.");
return;
}
int num1= Integer.parseInt(args[0]);
int num2 = Integer.parseInt(args[1]);
System.out.println("Before swapping:");
System.out.println("num1 = " + num1 + ", num2 = " + num2);
swapWithoutTemp(num1, num2);
swapWithTemp(num1, num2);
}
public static void swapWithoutTemp(int num1, int num2) {
System.out.println("\nSwapping without a temporary variable:");
Name: Pratham Suthar Subject: OOP with JAVA
En no: 236420316053 Code: 4341602
System.out.println("After swapping:");
System.out.println("num1 = " + num1 + ", num2 = " + num2);
}
}
Output:
Name: Pratham Suthar Subject: OOP with JAVA
En no: 236420316053 Code: 4341602
PRACTICAL-5
AIM: Develop programs to demonstrate use of -
1) if statement and its different form
CODE:
1) public class p5
{
public static void main(String[] args)
{
//defining a variable
int number=13;
//Check if the number is divisible by 2 or not
if(number%2==0){
System.out.println("even number");
}
else
{
System.out.println("odd number");
}
}
}
Name: Pratham Suthar Subject: OOP with JAVA
En no: 236420316053 Code: 4341602
OUTPUT:
case 5:
dayName = "Friday";
break;
case 6:
dayName = "Saturday";
break;
case 7:
dayName = "Sunday";
break;
default:
dayName = "Invalid day of week";
break;
}
System.out.println("Day of week: " + dayOfWeek);
System.out.println("Day name: " + dayName);
}
}
OUTPUT:
Name: Pratham Suthar Subject: OOP with JAVA
En no: 236420316053 Code: 4341602