Skip to main content

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 programming 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. 

Integral data types :

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.

Example:
 byte b=10;
 byte b2=130;//C.E:possible loss of precision found : int ,required : byte 
 C.E=COMPILE TIME ERROR.

byte b=10.5;//C.E:possible loss of precision 
byte b=true;//C.E:incompatible types 
byte b="rehan";//C.E:incompatible types 
 found : java.lang.String required : byte
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) 
Example: int i=130;
int i=10.5;//C.E:possible loss of precision 
int i=true;//C.E:incompatible types

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:-263to 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?

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: 
                   

Char data type:
  • In old languages like C & C++ are ASCII code based the no.Of ASCII code characters are < 256 to represent these 256 characters 8 - bits enough hence char size in old languages 1 byte.
  •  In java we are allowed to use any worldwide alphabets character and java is Unicode based and no.Of unicode characters are > 256 and <= 65536 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:


Comments

Popular posts from this blog

Industry Ethics and Legal Issues MCQ Questions With Answer

ETHICS ALL POSSIBLE QUESTION - SET 1 Q1. Before 16 Jan, How many states were already working in Startup India policies? a) 1 b) 3 c) 4 d) 7 Q2. Which of the following is not a part of Funding Innovation? a) Incubation Center b) Startup Yatra Funds c) Research Parks d) Manak Q3. For R& D, human resource started a new scheme for students a) Tinkering labs b) Manak c) Avishkar yojana d) Uchhatar Avishkar yojana Q4. Startup India Scheme? 1. Age should not be more than 3 years 2. Should develop innovative product. 3. Must be Private Limited Company/ Registered Partnership firm/ Limited Liability Partnership 4. Has patent granted in areas affiliated with the nature of business being promoted a) 1, 3 6) 1,2 and3 c) 2, 3 and 4 d) All of the above Q5. The period of business when an entrepreneur must position the venture in a market and make necessary adjustments to assure survival is called the: a) pre-Startup stage b) Startup singe

SET 2

ETHIC MCQ- SET 2 Q101. SISHU stage of MUDRA loan scheme provides maximum amount of? a) RS 10 Thousand b) RS 20 Thousand c) RS 30 Thousand d) RS 50 Thousand Q102. A criminal activity within the information technology infrastructure. a) Digital crime b) Intellectual property c) Cyber-crime d) All of them Q103. Law is the system of rules of conduct established by the government of a society to maintain a) Justice b) Consistency c) None of these d) Both A & B Q104. ln which year Pradhan Mantri MUDRA Yojana was launched? a) 2015 b) 2016 c) 2014 d) 2013 Q105. Minimum how many numbers of directors required in Public company a) 9 b) 8 c) 3 d) 10 Q106. Which of the following is not considered while selecting the region? a) Law and order b) Price of land c) Availability of raw materials d) Proximity to the product market Q107. A genetic term that is concerned to the legal and regulatory aspects of Internet and computer technolo

DIGITAL MARKETING

DIGITAL MARKETING END TERM PRACTICAL PAPERS: