Java Variables
Variables are the containers that save the data values. Each variable is assigned according to the data type it is assigned.
Syntax:
data_type var_name;
Types of Variables
There are 3 types of Data types in Java as mentioned below:
1. Local Variables
A variable defined within a block or method or constructor is called a local variable.2. Instance Variables
Instance variables are non-static variables and are declared in a class outside of any method, constructor, or block.3. Static Variables
Static variables are also known as class variables. The static variables are declared using the static keyword within a class outside of any method, constructor, or block.
Below is the Example of the above topic:
Java
// Java Program to demonstrate // Variables import java.io.*; class GFG { // instance variable public int revise; // static variable public static int count = 0 ; public static void help( int i) { // here int i is local variable // changes will not affect original value GFG.count++; System.out.println(i); } public static void main(String[] args) { // local variable int i = 10 ; System.out.println( "Before Calling function count:" + GFG.count); help(i); System.out.println( "After Calling function count:" + GFG.count); GFG temp = new GFG(); temp.revise = i + count; System.out.println( "Instance variable value:" + temp.revise); } } |
Before Calling function count:0 10 After Calling function count:1 Instance variable value:11
Java Cheat Sheet
Java is a programming language and platform that has been widely used since its development by James Gosling in 1982. It follows the Object-oriented Programming concept and can run programs written in any programming language. Java is a high-level, object-oriented, secure, robust, platform-independent, multithreaded, and portable programming language All those words are collectively called Java Buzzwords. It is commonly used for programming web-based, window, enterprise, and mobile applications. This Java Cheat Sheet article has been written by experts in Java and based on the experience of students who have recently undergone Java interviews.
This Core Java Cheat Sheet has been designed by Java experts, based on the experience of students who have recently undergone Java interviews. Whether you are a beginner or an experienced Java developer, this Java Cheat Sheet is a valuable resource for quickly accessing essential syntax, concepts, and best practices related to Java Programming.