Data Types

Data types in Java

Every variable in java has a data type. Data types specify the type and size of the value that can be stored.

 

Type

Size

Minimum Value

Maximum Value

Byte

1 byte

  • 128

127

Short

2 bytes

  • 32,768

32,767

Int

4 bytes

  • 2,147,483,648

2,147,483,647

long

8 bytes

  • 923,372,036,854,775,808

923,372,036,854,775,807

 

                                             Size and Range of Integer Data types

Reading Data from Keyboard

readLine() is used to take input from the user in java .

import java.io.DataInputStream;

class reading

{

Public static void main ( String args[])

{

DataInputStream in = new DataInputStram(System.in);

Int intnumber = 0;

Float floatnumber = 0.0f:

Try

{

System.out.println(“Enter an Integer : “ );

Int number = Integer.parseInt(in.readLine());

System.out.println(“Enter a Float number “);

Floatnumber = Float.valueOf(in.readLine()).floatValue();

}

Catch( Exception e ){}

System.out.println(“ Integer number “ + intnumber);

System.ouyt.println(“ Float Value “ + floatNumber);

}

}

The intereactive input and output of the above program is as follows :

Enter and integer :

123

Enter a float number

123.45

Int number = 123

Floatnumber = 123.45

Leave Comment

Important Topics

Title
OOPS
Data Types
JAVA
JVM
Command Line Args
Machine Neutral
Scope of Variables
Operators :
Generic Type Casting
IF Else
Switch Statement
The while statement
The do statement
The for statement
Classes, objects and methods
Constructors
Methods Overloading
Static Members
Nesting of methods
Inheritance : Extending a Class
Overriding methods
Overriding methods
Final variable and methods
Abstract class in Java
Visibility control