Skip to main content

Data Types

 Data Types    

There are different types of data used by programmers in java like Numbers, Alphabets, Images etc. Computer does not know the difference between values like number or alphabets.Each type of data will be categorized into different types which are known as Datatypes in java.
Thus, Datatype is a classification of data according to its type that an object or a variable can hold. It is a kind of data storage that contains specific type or range of value. Whenever variable is created a storage is assigned to it according to the datatype.

Two main concepts of Datatypes are -
  • Type of data.
  • Size allocated to it.
It is classified into two main categories i.e Primitives and Referenced



There are 8 Primitive Type Datatypes and 4 Referenced Datatypes i.e

Primitives Datatypes - These are built-in or predefined by the language and their definition cannot be changed.
  • byte
  • short
  • char
  • int
  • long
  • float
  • double
  • boolean
Referenced Datatypes - These are user defined datatypes. these are created by user no reserve keywords are used.
  • Array
  • Class
  • Enum
  • Interface
Each Datatypes has its own size and range in memory. 



Default Value: They have specific default value, in case user doesn't initialize any value to a variable then default value according to its datatype will be assigned.
Size: Size specify the space that a variable will take to store in memory,this will done according to its datatype.
Range: Range specify the range number in which a value can be initialize to a variable, this can also be done according to datatypes to which it assign. If user initialize a variable out of its range then compiler will generate an error.

Comments

Post a Comment

Popular posts from this blog

Literals

Literals Literal is the value that we pass in the variables. In other words, Literals are syntactic representation of boolean,numeric,character and string type. These values can be fixed or constant and are stored in the variable. Generally literal are categorized into two types i.e. Numeric Literals and Non Numeric Literals. Integer Literal : They includes - int, short, long, byte. These are the value without any decimal. Int is default type of integer. if any value is out of range in integer literal then compiler will consider that value as int and generates an error. To represent any value in long L/l will be used at the end. There are 4 integer Literals type i.e. Decimal, Octal, Hexadecimal, Binary(added in java 7)  Decimal Literals has base 10 i.e from 0 to 9.          They must not be started with 0. Example :          int a = 111;          it will print 111 Octal...

Operators

Operators Operators are used to perform some operations. Operators are special symbols that works with variables and constants in java. These symbols performs specific operation and gave result accordingly. Operators work with Operands. For Eg: a + b; Here a, b are Operands to which operation is to be performed,          + is Operator symbol. To work with operators 3 things must be noticed before using them i.e. Use of operator. Type of operand you are using. Result of operation. Unary Operators   : These type of operators required only one operand. For e:. +, -, ++, -- Binary Operators  : These type of operators required two operands to perform some operation. For eg: +, -, *, =, >, <, && etc. Ternary Operators :  These type of operators required three operands to perform some operation. For eg: :? Arithmetic Operators :           Arithmetic operato...