Languages [Sahi Placement]: Sample Questions 3 - 4 of 7

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 3

Languages
Edit

Write in Short

Short Answer▾

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.
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
TypeExplanation
intA 32-bit (4-byte) integer value
shortA 16-bit (2-byte) integer value
longA 64-bit (8-byte) integer value
byteAn 8-bit (1-byte) integer value
floatA 32-bit (4-byte) floating-point value
doubleA 64-bit (8-byte) floating-point value
charA 16-bit character using the Unicode encoding scheme
BooleanA true or false value

Question 4

Languages
Edit

Write in Short

Short Answer▾

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.

Developed by: