Variable is name of memory location. In java there are three types of variables instance variables, local variables, static variables.
There are two types of data types in java
1) Primitive data types.2) Non-Primitive data types.
Variable
Variable is name of reserved area allocated in memory. In other words, is name of memory location.
(1) int v = 20;
Here v is a variable, Which holds the value 20..
(2) double d = 30;
Here d is a variable, Which holds the value 30.
Variable declaration
- int a;
- int a, b, c;
Variable initialization
- int a = 10;
- int a = 10, b = 20, c = 30.
Types of Variable
- Instance Variable.
- Local Variable.
- Static Variable.
Instance Variable
Instance variable is a variable , which is declared inside a class but outside of method is called instance variable. Instance variable gets memory at run time when object is created.
Local Variable
Local variable is a variable , which is declared inside of method is called local variable.
Static Variable
Static variable is a variable , which is defined by the static keyword is known as static variable. static variable cannot be local variable. Static variable belongs to class level variable.
Let's see the example in program
class TypesOfVariableExample
{
int a=10; //instance variable
static int b=20; //static variable
void show()//method declaration
{
int c=30; //local variable
}
}
We can define a variable in two location in a class. For example
class Demo
{
int a;//class level variables
int b;//class level variables
public static void main(String args[])
{
int c;//Local variables
int d;//Local variables
}
}
Data Types In Java
Data Types: data types represent the different values to be stored in the variable. In java there are two types of data types.
(1) Primitive data type.
(2) Non-Primitive data type.
Primitive Data Type
(1) byte -Default Size - 1 Byte
Default Value - 0
Range : -128 to 127
For Example:
byte b=10;
(2) short -
Default Size - 2 Byte
Default Value- 0
Range : -32768 to 32767
For Example:
short s=10;
Default Size - 4 Byte
Default Value- 0
Range : -2147483648 to 2147483647
For Example:
int i=10;
Default Size - 8 Byte
Default Value- 0L
Range : -9223372036854775808 to 9223372036854775807
For Example:
long l=10;
Default Size - 2 Byte
Default Value- '\u0000'
Range : 0 to 65536 (Unsigned)
For Example:
char c='a';
Default Size - 1 bit
Default Value- false
Range : true/false
For Example:
boolean b=true or false;
(7) float -
Default Size - 4 Byte
Default Value - 0.0f
Range : approximately (+-) 3.40282347E+38F(6-7 significant decimal digits) Java implements IEEE 754 standard
For example :
float f=2.3f;
(8) double -
Default Size - 8 Byte
Default Value - 0.0d
Range : approximately (+-) 1.79769313486231570E+308(15 significant decimal digits)
For example :
double d=8.5d;
Default Size - 8 Byte
Default Value - 0.0d
Range : approximately (+-) 1.79769313486231570E+308(15 significant decimal digits)
For example :
double d=8.5d;
Note:There is 1 byte=8 bit;
Non-Primitive or reference or object Data types
What is signed and unsigned in java
Signed(+ or -): signed data types can hold both positive and negative values.
Unsigned(+): unsigned data types can hold large positive values but can't hold negative values.
For example:
A signed byte can represent values -128 to 127, while an unsigned byte can represent values from 0 to 255.
👉: In java all the data types or data types values are signed(except char)
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging…
ReplyDeleteRegards,
Dot Net Training in Chennai | Dot Net Training Center in Chennai | Dot Net Course in Chennai
Software Testing Training in Chennai | Best Software Testing Training Institute in Chennai | Testing Courses in Chennai
Java Training Institute in Chennai | Core Java Training in Chennai | Java Course and Certification
PHP Course in Chennai | PHP Training Institute in Chennai | PHP Course and Certification
Thanks for share this post, it very useful for update my knowledge
ReplyDeleteDot Net Training Institute in Chennai
Asp.Net Training in Chennai
Core Java Training in Chennai | Java Certification in Chennai | Java Training Institute in Chennai
PHP Training Institute in Chennai | Best PHP Course in Chennai
Manual Testing Training in Chennai | Software Testing Training in Chennai | Software Testing Course in Chennai
Please continue this great work and I look forward to more of your awesome blog posts
ReplyDeleteAndroid Training
PHP Programming Training
Nice article keep this great work up. There is good java variable tutorials Click Here
ReplyDeleteGood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeleteCore Java Online Training Hyderabad
I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. Keep up the good work.
ReplyDeleteVisit us: Java Online Training Hyderabad
Visit us: Core Java Online Course
Visit us: java course
Visit us: Best Online Java Course
ReplyDeleteThis post is so interactive and informative.keep updating more information...
Career In Java
Purpose Of Java
Nice blog! Your blog unique and very informative for everyone.
ReplyDeleteVisit us: Java Online Training Hyderabad
Visit us: Core Java Online Course
ReplyDeleteAwesome blog. Thanks for sharing such a worthy information....
Data science course in Delhi
Data Science Course in Gurgaon
Thank you ever so for you article. Really Cool.
ReplyDeleteonline training in java
online training on java
Hi, I read your whole blog. This is very nice. Good to know about the career in qa automation is broad in future. We are also providing various Java Training, anyone interested can Java Training Online for making their career in this field .
ReplyDeleteThankyou for such informative blog. You explain every point of data types in java. Java Course in Greater Noida is the best place for learning more about java.
ReplyDeleteIf you're seeking a Manual Testing Training Course in Noida that offers a comprehensive curriculum, industry-experienced instructors, hands-on training, certification, placement assistance, state-of-the-art facilities, and flexible learning options, look no further than APTRON Solutions Noida. Our commitment to providing top-notch education and helping you kickstart your career in manual testing is what sets us apart. Join us today and take the first step towards a successful and rewarding career in software testing.
ReplyDelete