0% found this document useful (0 votes)
4 views

PRACTICAL_OF_JAVA[1] pratham

The document outlines practical assignments for a Java programming course, including installation of JDK, setting up an IDE, and writing basic Java programs. It covers various topics such as data types, swapping numbers, and control statements like if and switch-case. Each practical includes code examples and expected outputs to demonstrate the concepts learned.

Uploaded by

gatbackontrack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

PRACTICAL_OF_JAVA[1] pratham

The document outlines practical assignments for a Java programming course, including installation of JDK, setting up an IDE, and writing basic Java programs. It covers various topics such as data types, swapping numbers, and control statements like if and switch-case. Each practical includes code examples and expected outputs to demonstrate the concepts learned.

Uploaded by

gatbackontrack
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Name: Pratham Suthar Subject: OOP with JAVA

En no: 236420316053 Code: 4341602

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

Eclipse IDE Download Eclipse:

Go to the Eclipse download page and download the installer.


Install Eclipse:
Run the installer and follow the prompts.
Name: Pratham Suthar Subject: OOP with JAVA
En no: 236420316053 Code: 4341602

Configure JDK in Eclipse:


Open Eclipse, go to Window > Preferences > Java > Installed JREs, click "Add," select
"Standard VM," and browse to your JDK path.
Create a Java Project:
Go to File > New > Java Project, enter a project name, and click "Finish."
Name: Pratham Suthar Subject: OOP with JAVA
En no: 236420316053 Code: 4341602

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);

// Floating point data type


float myFloat = 10.5f;
System.out.println("Float: " + myFloat);

// Double data type


double myDouble = 20.99;
System.out.println("Double: " + myDouble);

// Character data type


char myChar = 'A';
System.out.println("Character: " + myChar);

// Boolean data type


boolean myBoolean = true;
System.out.println("Boolean: " + myBoolean);
Name: Pratham Suthar Subject: OOP with JAVA
En no: 236420316053 Code: 4341602

// Byte data type


byte myByte = 127;
System.out.println("Byte: " + myByte);

// Short data type


short myShort = 32767;
System.out.println("Short: " + myShort);

// Long data type


long myLong = 100000L;
System.out.println("Long: " + myLong);

// String data type (not a primitive type, but commonly used)


String myString = "Hello, Java!";
System.out.println("String: " + myString);
}
}

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

num1 = num1+ num2;


num2= num1- num2;
num1= num1 - num2;
System.out.println("After swapping:");
System.out.println("num1 = " + num1+", num2 = " + num2);
}
public static void swapWithTemp(int num1, int num2) {
System.out.println("\nSwapping with a temporary variable:");
int temp = num1;
num1= num2;
num2= temp;

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:

2) switch case statement


public class p5{
public static void main(String[] args) {
int dayOfWeek = 3;
String dayName;
switch (dayOfWeek) {
case 1:
dayName = "Monday";
break;
case 2:
dayName = "Tuesday";
break;
case 3:
dayName = "Wednesday";
break;
case 4:
dayName = "Thursday";
break;
Name: Pratham Suthar Subject: OOP with JAVA
En no: 236420316053 Code: 4341602

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

You might also like