Sahi Papers: Sample Questions 3 - 4 of 7

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 3

» Languages » Java

Short Answer Question▾

Write in Short

Which are data types of JAVA and give classification of it.

Explanation

  • Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory. Therefore, by assigning different data types to variables, you can store integers, decimals, or characters in these variables. The basic data types and its classification is as follows.

Basic data types and its classification

int type variable will occupy 4 bytes in memory. Same way, short 2 bytes, long 8 bytes, byte 1 bye, float 4 bytes, double 8 bytes, character 2 bytes and Boolean will occupy 1 bit in memory. All these occupancies of memory are depended on compiler.

Type

Explanation

int

A 32-bit (4-byte) integer value

short

A 16-bit (2-byte) integer value

long

A 64-bit (8-byte) integer value

byte

An 8-bit (1-byte) integer value

float

A 32-bit (4-byte) floating-point value

double

A 64-bit (8-byte) floating-point value

char

A 16-bit character using the Unicode encoding scheme

Boolean

A true or false value

Question number: 4

» Languages » Java

Short Answer Question▾

Write in Short

What are the types of casting in JAVA? (2009 - 10)

Explanation

  • Assigning a value of one type to a variable of another type is known as Type Casting.
  • Widening Casting (Implicit): It takes place when, target type is larger than the source type.
  • The modifiers define the amount of storage allocated to the variable.
  • short int < = int < = long int < = float < = double < = long double
  • Here, short type occupies 1 byte of memory, short occupies 2 bytes of memory, int occupies 4 bytes of memory. So, we can assign one type of variable into another type by implicit casting.
  • Narrowing Casting (Explicitly): When we assign a larger type value to a variable of smaller type, then we need to perform explicit type casting.
  • long double = > double > = float > = long int > = int > = short int
  • Here, long double type occupies 12 byte of memory, double occupies 8 bytes of memory, float occupies 4 bytes of memory. So, we can assign one type of variable into another type by explicit type casting.