0% found this document useful (0 votes)
5 views8 pages

Java Data Types Explained: Basics & Concepts

Uploaded by

venu gopal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Java Data Types Explained: Basics & Concepts

Uploaded by

venu gopal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Agenda

Data Types in Java


1. Language categories according to data types
2. Deep explanation of data types
3. What are Wrapper Classes
4. What is Autoboxing & Unboxing
5. Interview Question

Language categories according to data types


Programming Language Fundamentals/Terminologies:
 Data Types
 Variables
 Tokens
 Literals
 Operators
 Separators
 Punctuators
 Comments
 Keywords / Reserved Words
 Identifiers

Data Type
What is data?
 DATA is raw facts and figures.
 These have very little meaning until they are sorted or they are used to make calculations.
 The process of sorting or calculating data is called DATA PROCESSING.
 The result of data processing is INFORMATION.
Example:
a, 10, venu, 2.5 are types of data

what is Data Type?


 Data type is a data storage format that can contain a specific type or range of values.
 When computer programs store data in variables, each variable must be assigned a
specific data type.
 Data types represents the type of information that can be stored in a variable.
 Data types are the keywords, which are used for Assigning a type to a variable.

Data type in Java?


The type of data that we are specifying to java is known as Data Type.
For example: -
 10 - int
 ‘a’ - char
 "Venu" - String
 true - boolean

According to data type, languages are divided into two categories: -


1. Statically Type Languages
In this type of languages, we have to specify the type of each data and thus compiler known
which type of data we have provided. For examples C, C++, Java, FORTRAIN, Pascal etc.

2. Dynamically Typed Languages


In this type of languages, we don’t need to specify the type of data that we have provided.
For examples Python, JavaScript, Objective C, Ruby etc.

Types of Datatypes:
1. Primitive Data Types (Predefined Data Type):
 The data types which are already provided by java and whose size are fixed are
known as primitive data type.
 Examples: -
There are 8 primitive data types: - boolean, char, byte, short, int, long, float,
double.
 To find the range of Integer primitive data type we can use the formula i.e., -
2(n-1) to 2(n-1) - 1 (where n is no of bits)
 To find the range (minimum and maximum value) of primitive data types
(excluding boolean) we can use static final int variables i.e., MIN_VALUE &
MAX_VALUE
 We can’t find MIN_VALUE & MAX_VALUE for Boolean Data Type.

2. Non-Primitive Data Types (User Defined Data Type or Derived Data Type):
 Non-Primitive data types are not pre-defined data types but are created by the
programmer. These are sometimes known as "reference variable" or "object
reference".
 The size of non-primitive data type is not fixed.
 Examples:
String, Array, Collection, Class, Abstract Class, Interface etc.
Wrapper classes:
The classes which are used to convert primitive into objects and objects into primitive.
There are 8 wrapper classes: Boolean, Character, Byte, Short, Integer, Long, Float & Double

Auto boxing and Unboxing:


 Java introduced autoboxing and unboxing in J2SE 5.0 version which coverts
primitive into object and object into primitive automatically
 The classes which are used to convert primitive into objects (Auto-Boxing) and
objects into primitive (Unboxing). (Not for interviews)
 Autoboxing is the automatic conversion of primitive data type into its corresponding
wrapper classes by java compiler.
 Unboxing is the automatic conversion of an object of wrapper type to its
corresponding primitive value
What is ADT (Abstract Data Type) or User Defined Data Type
 ADT is a set of operations.
 ADT specifies what is to be done but how it is done is not specified i.e., all the
implementation details are hidden.
For Example,
stack ADT have operations like push, pop but we don’t know how those operations
are implemented i.e., implementation details are hidden.
 ADT is a type (or class) which holds the different types of objects with some
specifications
 The definition of ADT only mentions what operations are to be Implemented and
performed but not how these operations
For example’s: Stack ADT, List ADT, Queue ADT etc.

Why java is not purely OOP's Language


 Java is not purely OOP's Language because:
 Usage of Primitive Data Types
o 'Purely object oriented' means it should contain only classes and objects. It should
not contain primitive data-types like int, float, char etc., since they are neither classes
nor objects.
 Usage of Static members
o In pure object-oriented languages, we should access everything by message
passing (through Objects). But Java contains static variables and methods which can
be accessed directly without using objects.
 Java does not contain multiple inheritance.

How primitive variables passed to methods - by value or by reference


Java supports, only pass by value

What is type casting? And What are different types of Type-Casting in java?
Type casting is a way to convert a variable from one data type to another data type.

You might also like