CORE JAVA Basics

CORE JAVA Basics Information about Basics Core JAVA

10/09/2015

Char data type:
In java we are allowed to use any worldwide alphabets character and java is Unicode based to represent all these characters one byte is not enough compulsory we should go for 2 bytes.

Size: 2 bytes
Range: 0 to 65535

Example:
char ch1=97;
char ch2=65536;//C.E:possible loss of precision

boolean data type:Size: Not applicable (virtual machine dependent)Range: Not applicable but allowed values are true or f...
10/09/2015

boolean data type:
Size: Not applicable (virtual machine dependent)
Range: Not applicable but allowed values are true or false.
Which of the following boolean declarations are valid?

Example 1:
boolean b=true;
boolean b=True;//C.E:cannot find symbol
boolean b="True";//C.E:incompatible types
boolean b=0;//C.E:incompatible types

Example 2:

Floating Point Data types:
10/09/2015

Floating Point Data types:

10/09/2015

Long:
Whenever int is not enough to hold big values then we should go for long data type.

Example:
To hold the no. Of characters present in a big file int may not enough hence the return type of length() method is long.
long l=f.length();//f is a file
Size: 8 bytes

Range:-2^63 to 2^63-1

***
Note: All the above data types (byte, short, int and long) can be used to represent whole numbers. If we want to represent real numbers then we should go for floating point data types.

10/09/2015

Int:
This is most commonly used data type in java.
Size: 4 bytes
Range: -2147483648 to 2147483647 (-2^31 to 2^31-1)

Example:
int i=130;
int i=10.5;//C.E:possible loss of precision
int i=true;//C.E:incompatible types

10/09/2015

Short:
The most rarely used data type in java is short.
Size: 2 bytes
Range: -32768 to 32767(-2^15 to 2^15-1)

Example:
short s=130;
short s=32768;//C.E:possible loss of precision
short s=true;//C.E:incompatible types

Short data type is best suitable for 16 bit processors like 8086 but these processors are completely outdated and hence the corresponding short data type is also out data type.

10/09/2015

Example:

byte b=10;
byte b2=130;//C.E:possible loss of precision
byte b=10.5;//C.E:possible loss of precision
byte b=true;//C.E:incompatible types
byte b="durga";//C.E:incompatible types

byte data type is best suitable if we are handling data in terms of streams either from the file or from the network.

10/09/2015

The most significant bit acts as sign bit. “0” means “+ve” number and “1” means “–ve” number.

“+ve” numbers will be represented directly in the memory whereas “–ve” numbers will be represented in 2’s complement form.

Byte:Size: 1byte (8bits)Maxvalue: +127Minvalue:-128Range:-128to 127[-27 to 27-1]
10/09/2015

Byte:

Size: 1byte (8bits)
Maxvalue: +127
Minvalue:-128
Range:-128to 127[-27 to 27-1]

10/09/2015

NOTE :

Except Boolean and char all remaining data types are considered as signed data types because we can represent both “+ve” and”-ve” numbers.

Diagram
10/09/2015

Diagram

Address

BTM 1st Stage
Bangalore
560029

Opening Hours

Monday 7am - 9am
Tuesday 7am - 9am
Wednesday 7am - 9am
Thursday 7am - 9am
Friday 7am - 9am
Saturday 7am - 9am
Sunday 7am - 9am

Telephone

+919871356369

Website

Alerts

Be the first to know and let us send you an email when CORE JAVA Basics posts news and promotions. Your email address will not be used for any other purpose, and you can unsubscribe at any time.

Contact The University

Send a message to CORE JAVA Basics:

Share