variables java

// instance variable in java example
public class InstanceVariableDemo
{
   // instance variable declared inside the class and outside the method
   int c;
   public void subtract()
   {
      int x = 100;
      int y = 50;
      c = x - y;
      System.out.println("Subtraction: " + c);
   }
   public void multiply()
   {
      int m = 10;
      int n = 5;
      c = m * n;
      System.out.println("Multiplication: " + c);
   }
   public static void main(String[] args)
   {
      InstanceVariableDemo obj = new InstanceVariableDemo();
      obj.subtract();
      obj.multiply();
   }
}

3.88
8
Bburhans 90 points

                                    // static variable in java example
public class StaticVariableExample
{
   // static variable
   static int a = 0;
   public void add()
   {
      a++;
   }
   public static void main(String[] args)
   {
      StaticVariableExample obj1 = new StaticVariableExample();
      StaticVariableExample obj2 = new StaticVariableExample();
      obj1.add();
      obj2.add();
      // both objects are sharing same copy of static variable
      System.out.println("Object 1 value is: " + a);
      System.out.println("Object 2 value is: " + a);
   }
}

3.88 (8 Votes)
0
3.86
7
Praestans 80 points

                                    int myVariable = 42;    //This is the most commonly used variable. Only use other variables if you have a good reason to.

3.86 (7 Votes)
0
4
5
Guildenstern 115 points

                                    /* Depending on what variables you want to declare */
String hello = "hello"; //characters
short one = 12;//shorter integers
int two = 2000; //complete integer up too 32 bits
long number = 2000000; //complete integer up to 64 bits
float decimal = 1.512 //up to 7 decimal digits
double million = 1.387892847395 //up tp 16 decmial digits
Bool condition = true; // true or false
char a = "a"; // unicode character

4 (5 Votes)
0
5
1

                                    /*
##	Variable
- Container which holds the value while the Java program is executed. 
- Assigned with a data type. 
- Name of memory location. 

##	There are three types of variables in java: 
1) Local variable 
2) Static (or class) variable 
3) Instance variable
*/

5 (1 Votes)
0
4.4
10
Rosuav 85 points

                                    // local variable in java example
public class LocalVariableExample
{
   public void employeeDetails()
   {
      // local variable empAge and name
      int empAge = 22;
      String name = "Sachin";
   }
   public static void main(String[] args)
   {
      LocalVariableExample obj = new LocalVariableExample();
      // name and empAge cannot 
      // be resolved to a variable
      System.out.println("Employee name is : " + name + ", and age : " + empAge);
   }
}

4.4 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
make var java les variables java variable in java explanation reference variables in java var variable java what is .var in java define variable injava varible java variable definition in java how to take variables in java java how to declare variables java "?" variable definition how to define a variable in java what is java variables define variable java howdo you declare a variable in java variable declaration java variables declaration in java variable declare in java variablen java how define var in java var in jva Java Variable? java $variable java $ variable variable javas what are variables in java programming variables in javas create variable in java why to declare var a variable in java how to declare var in java declare variable in method using java what is var in java var en java var-- in java using var in java varilbles in java this.variable in java how to define variables in java class how to define variables in java vars java declaring variable in java declaration variable in java coding variables in java how to create variables in java variables coding in java variables program in java creating variables in java EXAMPLES OF JAVA VARIABLES what is a java variable value using var java variable-- java declare variable java what is the use of var in java what is var hs in java syntax for declaring variable in java java variable | variable java declare variables setting a new variable in java How to set variebles in java should i use var in java java varaiables how to declare reference variable in java how to use var in java Java variable ... java vars stands variable in java create a variable in java what is a variable java how this variable works in java what does var do in java how to make a variable in java java create var new variable in java what is a variable in java programming how to make variables in java do we have 'var" in java java define variable variable: java declaring variables in java varibalen java declare variable in java java defining variables how to define variables java what does declaring a variable mean java what is variable in java variable in java variable in java example java var declaration can we declare variable in java java variable T declaring a variable in java best way to declare variables in java define variables java how to create and use variable in java create variable java what does (variable) mean java java declare variab my create variable java what is variable ... in java reference variable in java reference variable example in java java variables with - how to declare variable in java what is variable in java java how to declare variable how to make a new variable in java what are the @ variables in java declaring var in java var java define variable in java java varable CREATING A VARIABLE IN JAVA variable with * java example of a java variable java variable variablesin java Java Variable Syntax declare variables java how to create a variable in java how to declare a variable in java what does @variable do java what is a -variable in java make a var in java how to create variable java how to make a varoble on java java variables java how to make variables java differnet ways to declare an variables Variables are: java var java java create variable java new variable variable java java declare variable how to set a variable in hava how to use this variable in java what are the variables in java variables in java example java variable declaration reference variable java declare a variable java java where to declare variables what is variable in java? java what is var In Java, variables are (is) which of the following: var in java varvio java variable java ? howto variable java variable declaration in java declare a variable jabva crete variable in java java make a variable variables in java can i make a variable with T java great ways to define variable in java variable i java java this.variable = variable How to code for variables in java variables en java java var varibles java java variables tutorial how use var in java creating a new variable in Java java add variable and number how do declare a variable in java how to create an int in java whats proper way to declare java variables what are varibles in java int declaration in java make variables java java where variables how to state a variable in java for int i : variable java ways to define same variables in java java declaration java variables declaration type of varibale in java how to declare java variables how to add ne variable in java constructor variables java java how to make a variable how do i declare a variable in java assign variables within varables java java for variable java create varrible description class variables java how to define a integer in java how to declare ints in java how to make a varaible an int in java how to create a variable java varibale in java java varible types declaring variables java java env variables assigning a variable in java examples of variable in java local variables java how to delcare variables in java declare varialb e java java type of variable create varable in java set variable java declare a variable in java java varialbles int variable java how to use ? with variable in java how to create a variables in java java values java varibles java variable to variables java variable in function what's a variable java assigning data in java a variable in java variable description in java how to decclare variable in java all variable in java with example all variables in java java variable variable What is Variable? in programs in java meaning of variable in java java assign variable different types of variables in java type of the variable in java java variab;es declaration of variable in java what is variable description in java set variable in java java variables examples types of variables in java with examples varable types java how to use a variable in java variable java definition types of variable in java how to construct variable in java java asign variable declare value java Variables are java java programming variables java e vars java types of variables setting a variable in java variable type in java java ? values what are variables in java variable declarations java variable types java how to write variables in java variables in hava example of variable in java how to set variables in java what is a java variable "" + variable java java all variables java variables types java declare a variable java var types java _ variable how to set a variable in java variable types jaa variable types in java type of variable java decleare variable in java types of variables in java java assigning variables how to declare variables in java what is a variable in java java variable types java create a variable type of variable in java variables java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source