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

Programming in Java Laboratory (2)

This document outlines the laboratory program for Programming in Java, specifically focusing on handling various data types. It details the two main categories of data types in Java: primitive and non-primitive, along with specific examples of each type, including their syntax and memory size. The document is submitted by Tarunpreet Kaur as part of the requirements for a Bachelor of Technology degree in Information Technology at Guru Nanak Dev Engineering College.

Uploaded by

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

Programming in Java Laboratory (2)

This document outlines the laboratory program for Programming in Java, specifically focusing on handling various data types. It details the two main categories of data types in Java: primitive and non-primitive, along with specific examples of each type, including their syntax and memory size. The document is submitted by Tarunpreet Kaur as part of the requirements for a Bachelor of Technology degree in Information Technology at Guru Nanak Dev Engineering College.

Uploaded by

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

PROGRAMMING IN JAVA LABORATORY

(LPCIT-109)
SUBMITTED IN PARTIAL FULFILLMENT OF THE REǪUIREMENTS FOR
THE AWARD OF THE DEGREE OF

BACHELOR OF TECHNOLOGY
(INFORMATION TECHNOLOGY)

SUBMITTED BY: SUBMITTED TO:


Name: Tarunpreet Kaur Mrs. Reema Verma
U.R.N: 2203902
C.R.N: 2221127

Department of Information Technology


GURU NANAK DEV ENGINEERING COLLEGE
LUDHIANA
(An Autonomous College Under UGC Act 1956)
INDEX

S.No Name of Practical Date


PRACTICAL – 1
HANDLING VARIOUS DATATYPES

Introduction to datatypes:
In Java, data types specify the type of data that can be stored in a variable. Java is a
statically-typed language, which means that all variables must be declared with a
data type. There are two main categories of data types in Java:
1. Primitive Data Types- Primitive data types are the most basic data types
available in Java. They are predefined by the language and named by a reserved
keyword. They represent single values and occupy a fixed amount of memory.
2. Non-Primitive Data Types- Non-primitive data types, also known as reference
data types, are types created by the programmer and are not defined by Java. They
refer to objects and hold memory addresses where the data is stored. These types
are more complex than primitive data types and can be used to store collections of
data.
PRIMITIVE NUMERIC DATATYPES:
1. byte:
The byte data type is an 8-bit signed two’s complement integer. The byte data type
is useful for saving memory in large arrays.
Syntax:
byte byteVar;
Size: 1 byte (8 bits)
CODE:

OUTPUT:

2. short
The short data type is a 16-bit signed two’s complement integer. Similar to byte,
use a short to save memory in large arrays, in situations where the memory savings
actually matters.
Syntax:
short shortVar;
Size: 2 bytes (16 bits)
CODE:

OUTPUT:

3. int
It is a 32-bit signed two’s complement integer.
Syntax:
int intVar;
Size: 4 bytes ( 32 bits )
CODE:

OUTPUT:
4. long
The long data type is a 64-bit two’s complement integer.
Syntax:
long longVar;
Size: 8 bytes ( 64 bits )
CODE:

OUTPUT:

5. float
The float data type is a single-precision 32-bit IEEE 754 floating-point. Use a float
(instead of double) if you need to save memory in large arrays of floating-point
numbers.
Syntax:
float floatVar;
Size: 4 bytes ( 32 bits )
CODE:
OUTPUT:

6. double
The double data type is a double-precision 64-bit IEEE 754 floating-point. For
decimal values, this data type is generally the default choice.
Syntax:
double doubleVar;
Size: 8 bytes ( 64 bits )
CODE:

OUTPUT:
PRIMITIVE NON-NUMERIC DATATYPES:
1. boolean
A boolean variable is defined using the keyword boolean.
Syntax:
boolean variableName;
Size: 1 bytes ( 8 bits )
CODE:

OUTPUT:

2. char
The char data type is a single 16-bit Unicode character with the size of 2 bytes (16
bits).
Syntax:
char charVar;
Size: 2 bytes ( 16 bits )
CODE:

OUTPUT:

You might also like