JAVA PRIMITIVE TYPES AND WRAPPER CLASSES :
Object class, which is stored in the java. lang package is ultimate super class of all classes. and below are the methods of Object class it means behaviour of Object class as mentioned in my previous post. Just know these methods will be more useful as we will go more deeper.- Object getClass(). : returns Class class object
- int hashCode() : returns the hashcode number for object being used.
- boolean equals(Object obj) : compares the argument object to calling object.
- Object clone() : Creates copy of invoking object
- String toString() : returns the string representation of invoking object
- void notify() : wakes up a thread, waiting on invoking object's monitor.
- void notifyAll() : wakes up all the threads, waiting on invoking object's monitor.
- void wait() : causes the current thread to wait, until another thread notifies.
- void wait(long,int) : causes the current thread to wait for the specified milliseconds and nanoseconds, until another thread notifies.
- void finalize() : It is invoked by the garbage collector before an object is being garbage collected.
You guys should now be able to understand the method signature along with return type as explained in my previous post JAVA BASIC OVERVIEW .
Now, let's understand how java understand variable type.
In Java Syntax , a variable can be defined as below :
AccessSpecifier TypeOfVariable ReferenceName;
Example : public int input1;
Here public is the Access specifier and int is the type of variable and input1 is nothing but a name to this variable which can be anything , only thing we need to remember that while updating or accessing we need to use the same name.
I already explained about access specifier in my previous post JAVA BASIC OVERVIEW, so in this post we will be discussion only about variable types.
In java for variables mainly we use primitive datatypes, which are not object and they doesn't have any methods, because of this only java is not fully object oriented programming language .
There are 8 primitive types in java : boolean, char, byte, short, int, long, float and double. Below is Wrapper Class mapping for each primitive types. We need wrap our primitive type to their respective wrapper class to use the Object class methods.
Primitive types : boolean, byte, short, char, int, long, float, double
Wrapper classes : Boolean, Byte, Short, Character, Integer, Long, Float, Double
boolean : Can be either true or false
byte : Can store one byte (8 bit) like capital character ASCII value starts from 65 so if we store A in byte
example : byte input1='A'; it will print 65
byte input1='C'; it will print 67
char : char is 16-bit Unicode character , Can store only one character at a time like char input1='C';
short : short data type is a 16-bit integer. It has a minimum value of -32,768 and a maximum value of 32,767. So we can't store value more than 32,767.
int : int is a numeric data type and is of 32 bit and can hold minimum value of -2^31 and a maximum value of 2^31-1
long : long is also a numeric data type of 64 bit.
float : float is numeric data type for floating point like 12.65 , 23.98
double : double is also numeric data type for floating point it has double has 2x more precision then float.
- Non-primitive variables can be String , Arrays etc.
Variables scope can be of 3 types : Local, instance and static.
1) Local Variable : Variable declares inside method or enclosed brackets has scope till inside the methods or brackets it can't be use or recognise outside of methods or brackets.
2) Instance Variable : A class can have multiple variables declared inside , all these variables belongs to the instance of the same class. Once the object will be created of class instance variables will also come into the picture.
3) Static Variable : Already explained in my previous post JAVA BASIC OVERVIEW, static means it belongs the Class not with the object of class. So it can be use by without object creation and can be accessible to all static blocks.
- BASIC OVERVIEW OF JAVA (SESSION 1)
- PRIMITIVE TYPES AND WRAPPER CLASS (SESSION 2)
- JAVA OPERATORS (SESSION 3)
- LOOPS IN JAVA (SESSION 4)
- NAMING CONVENTION WITH FACTORIAL PROGRAM (SESSION 5)
Comments
Post a Comment