scroll bar

Best blog for OCJP

Data types:



Data types: Every variable has a type, every expression has a type and all types are strictly define more over every assignment should be checked by the compiler by the type compatibility hence java language is considered as strongly typed language.
Java is pure object oriented programming or not?
 Java is not considered as pure object oriented programming language because several oops features (like multiple inheritance, operator overloading) are not supported by java moreover we are depending on primitive data types which are non objects.
Diagram:
 Except Boolean and char all remaining data types are considered as signed data types because we can represent both “+ve” and”-ve” numbers.
Byte:
Size: 1byte (8bits)
Maxvalue: +127
Minvalue:-128
Range:-128to 127[-27 to 27-1]
* 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 data type is best suitable if we are handling data in terms of streams either from the file or from the network.
Short:
* The most rarely used data type in java is short.
Size: 2 bytes
Range: -32768 to 32767(-215 to 215-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.
Int:
* This is most commonly used data type in java.
Size: 4 bytes
Range:-2147483648 to 2147483647 (-231 to 231-1)

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:-263 to 263-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.
Floating Point Data types:

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?


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
Summary of java primitive data type:


* The default value for the object references is “null”.

Labels:  Syllabus    Language Fundamentals 

1 comment:

  1. Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
    Regards,
    Asp.Net Training in Chennai
    Selenium Coaching Institute in Chennai
    Manual Testing Training in Chennai
    Java Training Institute in Chennai
    PHP Course in Chennai


    ReplyDelete