You are on page 1of 8

Programming with Java (2030106406) Enrollment (2227010601212)

PRACTICAL – 1

AIM : Install JDK and write a java program to print your name.

Step 1: Download and Install Java Development Kit (JDK)


The very first step is to download the Oracle Java Development Kit (JDK) from the Official
Oracle Website. For that, Head over to the Official Website.

You need to identify your system specifications to choose the Product/file description. The
website will contain the latest version for your corresponding system. For Windows, we’ll be
downloading the latest x64 Installer of Java SE Development Kit 18. After the download is
complete, proceed to install the JDK by following the bootstrapped steps.

Rakholiya Yash 1
Programming with Java (2030106406) Enrollment (2227010601212)

Step 2: Configure Environment Variables


After the installation is complete, we must configure environment variables to notify the system
about the directory in which JDK files are located. Proceed to C:\Program Files\Java\jdk-
{YOUR_JDK_VERSION}\bin (replace {-} with your JDK version)

To set the Environment Variables, you need to search Environment Variables in the Task Bar and
click on“Edit the system environment variables”.

Rakholiya Yash 2
Programming with Java (2030106406) Enrollment (2227010601212)

Under the Advanced section, Click on “Environment Variables”.

Under System variables, select the “Path” variable and click on “Edit”. Click on “New” then paste
the Path Address i.e. C:\Program Files\Java\jdk-{YOUR_JDK_VERSION} \bin. Click on “OK”.

Now, in the Environment Variables dialogue, under System variables, click on “New” and then
under Variable name: JAVA_HOME and Variable value: paste address i.e. C:\Program
Files\Java\jdk-
{YOUR_JDK_VERSION}. Click on OK => OK => OK.

Rakholiya Yash 3
Programming with Java (2030106406) Enrollment (2227010601212)

Step 3: Check the Java Version


Open Command Prompt and enter the following commands
 java –version
 javac –version

 code
public class name {
public static void main(String[] args) {
System.out.println("My name is Rakholiya Yash ");
}
}

 Output

Rakholiya Yash 4
Programming with Java (2030106406) Enrollment (2227010601212)

PRACTICAL – 2
AIM : create three variables to store marks of three subject and generate mark
sheet .(use if condition or switch case)

Rakholiya Yash 5
Programming with Java (2030106406) Enrollment (2227010601212)

PRACTICAL – 3
AIM :write a program in java to reverse the digits of a number using while loop .

 code
public class ReverseNumber
{
public static void main (String[] args)
{
int number =845743,reverse=0;
while(number !=0)
{
int remainder=number %10;
reverse=reverse * 10 + remainder;
number=number/10;
}
System.out.println("the reverse of the given number is :" + reverse);
}
}

 Output

Rakholiya Yash 6
Programming with Java (2030106406) Enrollment (2227010601212)

PRACTICAL – 4
AIM :write a program to demonstrate use of wrapper class .
 code
public class Wrapper
{
public static void main(String args [])
{
byte b=10;
short s=20;
int i=30;
long l=40;
float f=50.0F;
double d=60.0D;
char c='a';
boolean b2=true;

Byte byteobj=b;
Short shortobj=s;
Integer intobj=i;
Long longobj=l;
Float floatobj=f;
Double doubleobj=d;
Character charobj=c;
Boolean boolobj=b2;

System.out.println("---Printing object values---");


System.out.println("Byte object:"+byteobj);
System.out.println("Short object:"+shortobj);
System.out.println("Integer object:"+intobj);
System.out.println("Long object:"+longobj);
System.out.println("Float object:"+floatobj);
System.out.println("Double object:"+doubleobj);
System.out.println("Character object:"+charobj);
System.out.println("Boolean object:"+boolobj);

Rakholiya Yash 7
Programming with Java (2030106406) Enrollment (2227010601212)

byte bytevalue=byteobj;
short shortvalue=shortobj;
int intvalue=intobj;
long longvalue=longobj;
float floatvalue=floatobj;
double doublevalue=doubleobj;
char charvalue=charobj;
boolean boolvalue=boolobj;

System.out.println("---Printing primitive values---");


System.out.println("byte value: "+bytevalue);
System.out.println("short value: "+shortvalue);
System.out.println("int value: "+intvalue);
System.out.println("long value: "+longvalue);
System.out.println("float value: "+floatvalue);
System.out.println("double value: "+doublevalue);
System.out.println("char value: "+charvalue);
System.out.println("boolean value: "+boolvalue);
}
}
 Output

Rakholiya Yash 8

You might also like