Java Variables

Published by StudyMuch on

Java Variables

Java Variables with Programming Examples

In this tutorial you will learn about the “Java Variables” with programming examples, Types of Variables in Java, and you also see programming examples of all the Variables. What is Variable and how many types of Variables in Java. Here we read all the main topic about the Java Variable.

What is Variables?

A variables is a container which holds the value while the java program is executed. A Variable is assigned with a datatype. Variable is a name of memory location.

A Variable is an identifier that denotes a storage location use to store a data value. Unlike constants that remain unchanged during the execution of java program. A variable may take different values at the different time during the execution of the program.

A Variable name can be chosen by the programmer as the meaning way.

Variable is name of reserved area allocated in memory. In other words, it is a name of memory location. It is a combination of “vary + able” that means its value can be change.

Example of Variable;

public class tutorial {
public static void main (String [] args)
   int a = 10;
   float b = 1.5F;
   String c = “Shubham”;
//Here a, b, and c is Variable.

you can see above programming we take the variable in data type “int, float, and string”, a, b and c is a Variable in above programming.

Java Variables StudyMuch

Types of Variables in Java

Mainly there are three types of variables in java;

  • Local Variable
  • Instance Variable
  • Static Variable

Local Variable

A variable declared inside the body of the method is called local variable. You can use this variable only within that method and the other methods in the class aren’t even aware that the variable exists.

A local variable cannot be defined with “static” keyword.

Instance Variable

A variable declared inside the class but outside the body of the method, is called instance variable. It is not declared as static.

It is called instance variable because its value is instance specific and is not shared among instances.

Static variable

A variable which is declared as static is called static variable. It cannot be local. You can create a single copy of static variable and share among all the instances of the class. Memory allocation for static variable happens only once when the class is loaded in the memory.

Now you see below, all the programming examples are available related Java Variable, we written here different – different types of examples, so that you can understand better.

Example of all variable in one programming examples;

public class example {
  int data = 50; //instance variable
  static int b = 100; //static variable
void method () {
    int n = 40; //local variable

Widening: Java Variable Programming Example;

public class example {
public static void main (String [ ] args){
      int a =20;
      float f = a;





Narrowing: Java Variable Example;

public class example {
public static void main (String [] args){
     float f = 10.7f;
     int a = (int)f;





Adding Lower Type: Java Variable Example;

public class example {
public static void main (String [] args){
      byte a =50;
      byte b =50;
      byte c = (byte)(a+b);




So, in this tutorial (Java Variable) you learned about the Java Variables, it’s definition, types of variables with programming examples, I hope you guys, you read this tutorial better and learn something new. If you have any doubt you can ask in the comment section.

Read Also


Blaine Nanez · January 16, 2023 at 7:31 am

Hey there! I know this is kinda off topic but I was wondering if you knew where I could locate a captcha plugin for my comment form? I’m using the same blog platform as yours and I’m having problems finding one? Thanks a lot!

best cheap seo services · August 10, 2023 at 10:21 am

Great article.Really thank you! Awesome.

vivegam collection · August 15, 2023 at 9:45 pm

I appreciate you sharing this blog.Really looking forward to read more. Awesome.

dhoti kurta new style · August 16, 2023 at 9:28 am

Enjoyed every bit of your post.Really looking forward to read more. Really Cool.

tubidy mp4 · August 24, 2023 at 5:28 am

I like it when folks get together and share thoughts. Great blog, continue the good work!

vinhomes vu yen hai phong · August 30, 2023 at 6:48 am

It’s actually a cool and useful piece of information. I am happy that you shared this helpful info with us.Please stay us up to date like this. Thank you for sharing.

la-plastic · September 16, 2023 at 7:56 am

Fantastic post.Really thank you! Cool.

Fildena 100 · September 16, 2023 at 11:24 am

Im grateful for the article.Much thanks again. Will read on…

Herbs & Spices · September 16, 2023 at 3:20 pm

Really enjoyed this post.Much thanks again. Really Cool.

Agra Delhi Jaipur tour packages · September 28, 2023 at 7:08 pm

Thank you ever so for you blog post.Really thank you! Will read on…

Mosaic| Marble Onyx Suppliers| black edging stones| pure white granite| stone basin countertop} · September 30, 2023 at 11:32 pm

Muchos Gracias for your blog article.Really thank you! Fantastic.

抖音网红黑料 · October 2, 2023 at 8:45 pm

Great article post.Really looking forward to read more. Will read on…

Richard Medina · October 3, 2023 at 6:28 am

I do not even know how I ended up here, but I thought thispost was good. I don’t know who you are but certainly you’regoing to a famous blogger if you are not already 😉 Cheers!Check out my blog –

tongwei solar co., ltd. · October 3, 2023 at 7:02 am

Very informative post.Much thanks again. Awesome.

开医院证明 · October 7, 2023 at 3:02 pm

Thanks for the blog.Much thanks again. Awesome.

Magnesium cluoride sputtering targets · October 20, 2023 at 2:44 pm

I really enjoy the article.Really looking forward to read more. Will read on…

code promo gshopper · October 20, 2023 at 7:32 pm

Major thankies for the blog post.

kurzy · October 25, 2023 at 9:13 pm

It’s enormous that you are getting thoughts from this piece of writing as well as from our discussion made at this place.

Australian Visa Singapore · October 26, 2023 at 4:55 pm

I loved your post.Much thanks again. Much obliged.

Australian High Commission · October 27, 2023 at 6:55 am

Thank you for your article post.Thanks Again. Want more.

manali hotels 4 star · October 27, 2023 at 3:17 pm

I loved your article post.Really thank you! Cool.

Silicone Resin · October 27, 2023 at 9:56 pm

Very good article. Awesome.

chemical raw material suppliers · October 28, 2023 at 9:04 pm

Major thanks for the post.Really thank you!

Keratin hair extensions · October 29, 2023 at 11:01 am

Enjoyed every bit of your blog article.Much thanks again. Much obliged.

prenajom autobusu na svadbu · October 31, 2023 at 9:43 am

Hello There. I found your blog using msn. This is an extremely well written article.I will be sure to bookmark it and return to read more of your usefulinformation. Thanks for the post. I’ll definitelyreturn.

kem boi da cho tre so sinh · October 31, 2023 at 5:12 pm

An interesting discussion is definitely worth comment. I do think that you should write more on this subject matter, it might not be a taboo matter but generally people do not discuss such topics. To the next! Kind regards!!

JIANGHEHAI · November 4, 2023 at 11:40 pm

Great blog.Much thanks again. Will read on…

YuehouDZ · November 5, 2023 at 10:38 am

Im thankful for the blog post. Want more.

Absorb King Desiccant · November 5, 2023 at 11:53 am

Hey, thanks for the article.Really looking forward to read more. Fantastic.

playdoit casino bono · November 5, 2023 at 1:39 pm

A motivating discussion is definitely worth comment. I do think that you need to publish more on this topic, it might not be a taboo matter but generally folks don’t talk about such issues. To the next! Cheers!!

laira plus · November 5, 2023 at 4:02 pm

I value the blog post.Much thanks again. Much obliged.

block making machine · November 6, 2023 at 8:12 am

Im obliged for the blog.Really looking forward to read more. Great.

kubet · November 7, 2023 at 9:37 am

I really like and appreciate your post.Really looking forward to read more. Really Cool.

hosting mexico · November 7, 2023 at 2:28 pm

Heya i am for the first time here. I found this board and I find It really useful& it helped me out much. I hope to give somethingback and aid others like you aided me.

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *