- What is Java?
- History of Java
- Hello Java Program
- Features of Java
- Basic Syntax
- Java Setup
- Data Types in Java
- Java Variables
- Operators in Java
- Java If-else Statement
- Switch Case Statement
- Java Loops
- Do-While Loop
- Java While Loop
- Continue Statement
- Break Statement in Java
- Constructors in Java
- Oops Concept in Java
- Features of OOPs
- Exeception handeling
- Aggregation (HAS-A relationship) in Java
- Method Overriding in Java
- Method Overloading
- Java Static Keyword
- Java This Keyword
- Java Final Keyword
- Static Binding and Dynamic Binding
- Abstract class in Java
- Access Modifiers in Java
- Difference between abstract class and interface
- Interface in Java
- Garbage Collection in Java
- Java Package
- Serialization and Deserialization in Java
- Java Inner Classes
- Java Applets
- Multithreading in Java
- Thread Priorities in Java
- Thread Creation
- Inter Thread Communication
- Wrapper Classes in Java
- Java Input Output
- Java AWT Introduction
- Java Layout Manager
- Java Layout Policy
- Java AWT Events
- Collection Framework
- Collection Framework List Interface
- Swing in Java
- Swing Utility Classes
- Swing Layout Managers
- Java JDBC
Data Types in Java
Variables are only saved memory areas to store values. This implies that when you make a variable, you save some space in memory. In light of the data type of a variable, the working framework distributes memory and chooses what can be put in the held memory. Consequently, by appointing diverse data types to variables, you can store whole numbers, decimals, or characters in these variables.
There are two data types accessible in Java:
- Reference/Object Data Types
- Primitive Data Types
Primitive Data Types
There are eight primitive information types, which are supported by Java. Primitive data types are predefined by the dialect and named by a catchphrase. This section discusses these data types in detail.
- Byte information sort is an 8-bit marked two’s supplement whole number.
- Maximum worth is 2^7 -1, which is equal to 127. This value is also included in the range of these values.
- Minimum worth is -2^7, which is equal to -128.
- Default value stored in a variable of this type is 0.
- Byte information sort is utilized to spare space in vast exhibits, principally set up of numbers, since a byte is four times littler than an int.
- Example: byte x = 200, byte y = -20
- Short information sort is a 16-bit marked two’s supplement number.
- The Maximum value is 2^15 -1, which is equal to 32,767. This number is also included in the range.
- The Minimum value is -2^15, which is equal to -32,768.
- Short information sort can likewise be utilized to spare memory as byte information sort. A short is 2 times littler than an int
- The default value for this data type is 0.
- Example: short x = 425164, short y = -76686
- Int information sort is a 32-bit marked two’s supplement number.
- The Maximum value for this data type is 2^31 -1, which is equal to 2,147,483,647. This number is also included in the range for this data type.
- Minimum value for this data type is -2^31, which is equal to – 2,147,483,648.
- Int is, for the most part, utilized as the default information sort for its indispensable qualities unless there is a worry about memory.
- The default value for this data type is 0.
- Example: int x = 826378, int y = -64782
- long information sort is a 64-bit marked two’s supplement whole number.
- Maximum value for this data type is 2^63 -1, which is equal to 9,223,372,036,854,775,807.
- Minimum value for this data type is -2^63, which is equal to -9,223,372,036,854,775,808.
- This sort is utilized when a more extensive memory range than int is required.
- The default value for those data type is 01.
- Example: long x = 174636l, int y = -536452l
- Float is a data type, which is known for its solitary exactness, 32-bit IEEE 754 gliding point.
- Float is, for the most part, used to spare memory in vast exhibits of coasting point numbers.
- The default value for this data type is 0.0f.
- Float information sort is never utilized for exact values, for example, money.
- Example: float x = 254.3f
- Double information sort is a float with twofold exactness 64-bit IEEE 754 drifting point.
- This information sort is, for the most part, utilized as the default information sort for decimal qualities.
- Double information sort ought to never be utilized for exact values, for example, money.
- The default value for this data type is 0.0d.
- Example: double x = 321.4
- boolean information sort speaks to one bit of data.
- Any boolean variable can assume one of the two values: true or false.
- This information sort is utilized for basic banners that track natural/false conditions.
- The default value for this data type is false.
- Example: boolean check = true;
- char information sort is a solitary 16-bit Unicode character.
- The Maximum value for a variable of this type is “\uffff” (or 65,535 comprehensive).
- The minimum value for a variable of this type is “\u0000” (or 0).
- char information sort is utilized to store any character.
- example: char text =‘a’
Reference Data Types
- Reference variables are made utilizing characterized constructors of the classes.
- They are utilized to get to objects. These variables are proclaimed to be of a particular data type that can’t be changed. A few examples of such data types are Employee and Dog.
- Class objects and different kind of variables go under reference data type.
- Default estimation of any reference variable is invalid.
- A reference variable can be utilized to allude to any object of the announced sort.
- Example: myanimal = new Animals(“rabbit”);