Java: Keywords and Variables

keywords and variables

Keywords and Variables

Here, in this page we will discuss about keywords and variables in Java Programming Language. We will discuss each of them in brief.

List Of Keywords

abstract assert boolean break
byte case catch char
class const continue default
do double else enum
extends final finally float
for  go to if implements
import instance of int interface
long native new package
private protected public return
short static strictfp super
switch synchronized this throw
throws transient try void

1. Local Variable

  • A local variable is the one which is declared with the body of a method.
  • It’s scope is limited to the body of that method and the other methods in the class aren’t even aware of the existence of such variable.
  • Initial declaration of local variable is compulsory. 
  • Static variables are declared using the static keyword within a class outside any method constructor or block.

2. Instance Variable

  • Instance variables are those which are declared inside the body of a class but not within any methods.
  • These differ with each instance of the class created although they have the same identity.
  • It is called instance variable because its value is instance specific and is not shared among instances.
  • It’s default value is zero.

3. Static Variable

  • Static variables are also known as class variable because they are associated with the class and common for all the instances of class.
  • We can create a single static variable which can be shared among all the instances of the class.
  • Static variables are declared using the static keyword within a class outside any method constructor or block.

Prime Course Trailer

Related Banners

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription