Friday, November 17, 2017

Understanding Variables and Data Types in Java with Examples

Variable in Java:

The variable is the name of held range distributed in memory. At the end of the day, it is a name of the memory area. It is a mix of "differ + capable" that implies its esteem can be changed.

Types of Variables in Java

  1. Local variable
  2. Instance variable
  3. Static variable


1. Local Variable in Java:
A variable which is asserted inside the method is called local variable.
2. Instance Variable in Java:
A variable which is said within the magnificence but outside the method is called example variable. It is not declared as static.
3. Static variable in java
A variable this is declared as static is known as the static variable. It cannot be nearby.

Example:

class A

{  

int data=70;//instance variable  

static int m=100;//static variable  

void method(){  

int n=900;//local variable  

}  

}//end of class  

Data Types in Java:

  •  Each variable has a kind, each expression has a type, and every type is exactly described.
  • All assignments, whether specific or via parameter passing in technique calls, are checked for type compatibility. 
  • There aren't any automatic coercion or conversions of conflicting types as in some languages. 
  • The java compiler tests all expressions and parameters to make sure that the sorts are compatible.
  • Information sorts speak to the diverse esteems to be put away in the variable. In Java, there are two sorts of information sort

  1. Primitive Data Types in Java
  2. Non-primitive Data Types in Java





    No comments:

    Post a Comment

    Top 200+ Core Java Interview Questions And Answers For 2019

    Most Popular Java Interview Questions Given below is a comprehensive list of most important and commonly asked basic and advanced Java p...