create account

Java Variables For Day 4 Of 30 Days Of Java by run.vince.run

View this thread on: hive.blogpeakd.comecency.com
· @run.vince.run ·
$1.79
Java Variables For Day 4 Of 30 Days Of Java
<h3>When Will The Progress Stop</h3>

![codes-coding-computer-270623.jpg](https://cdn.steemitimages.com/DQmVyzdbBUgcdw5mozSkQg7wpLNHpZDEEeBoaxDtxkh2U3R/codes-coding-computer-270623.jpg)
[Image not Java but courtesy of pexels.com](pexels.com)

I know I’m not going to be able to keep this up forever. Sooner or later my progress is going to stop. For now I hope I’m still making sense with what I’m posting. So let’s not delay and get my day 4 update out. 

<h2>What Did I Learn Today</h2>
- Java Variables: Variable is a name associated with a value that can be changed. Specifically, we name the address of where the value is stored in memory, instead of having to remember the complex memory address. When you declare a variable in java you need to specify the data type as well as the variable name, eg: int i = 10;

So declaring a variable
```data_type variable_name = value;```

You can also declare the variable and then assign a value
```int i;```
```i = 100;```

- Variable Naming Conventions: Variables names need to adhere to a set of standards during your code and these include. 
1. Variables cannot start with white space
2. Variables can begin with a special character
3. Variable names should start with a lowercase and second words should start with a capital letter
4. Variable names are case sensitive

- There are 3 types of Variables in Java: 
1. Static or class variables: they are associated with the class and common for all instances of class. If you create an object from a class, the variable would be the same for each object. A static variable remains constant and cannot be changed. When declaring the variable you use the word static before declaring the variable, eg: public static String variableName="Variable";
2. Instance Variable: Instance variables are declared inside a class but outside and member, constructor of class. Each object has their own copy of the variable.
3. Local Variable: Variable declared inside the method of the class and their scope is limited to the method which means you can't change the variable or access them outside the method.

<h2>Code For The Day</h2>
Below is a sample program illustrating the use of Static, Instance and Local variables:

```
public class VariableExample {
        // instance variable
        public String myVar="instance variable";

        public void myMethod(){
                // local variable
                String myVar = "Inside Method";
                System.out.println(myVar);
        }

        public static void main(String args[]){
                VariableExample obj = new VariableExample();

                System.out.println("Calling Method");
                obj.myMethod();
                System.out.println(obj.myVar);
        }
}
```

Output
```
$ java VariableExample 
Calling Method
Inside Method
instance variable
```

<h3>I'll be posting daily, sharing my experiences on my “1 Month of Java Code” experiences”, my previous post on day 3 can be found below, so feel free to have a look:
https://steemit.com/java/@run.vince.run/day-3-of-javatober-and-learning-what-the-jvm-is</h3>

<h3>If you have found this post useful or interesting, please consider Commenting, Upvoting, Following and/or Resteeming</h3>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authorrun.vince.run
permlinkjava-variables-for-day-4-of-30-days-of-java
categoryjava
json_metadata{"tags":["java","coding","steemit","teamaustralia","programming"],"image":["https://cdn.steemitimages.com/DQmVyzdbBUgcdw5mozSkQg7wpLNHpZDEEeBoaxDtxkh2U3R/codes-coding-computer-270623.jpg"],"links":["pexels.com","https://steemit.com/java/@run.vince.run/day-3-of-javatober-and-learning-what-the-jvm-is"],"app":"steemit/0.1","format":"markdown"}
created2018-10-03 19:57:36
last_update2018-10-03 19:57:36
depth0
children256
last_payout2018-10-10 19:57:36
cashout_time1969-12-31 23:59:59
total_payout_value1.402 HBD
curator_payout_value0.384 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3,226
author_reputation202,014,829,756,154
root_title"Java Variables For Day 4 Of 30 Days Of Java"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id72,567,563
net_rshares1,036,517,304,869
author_curate_reward""
vote details (44)
@arcange ·
Congratulations @run.vince.run!
Your post was mentioned in the [Steemit Hit Parade](https://steemit.com/hit-parade/@arcange/daily-hit-parade-20181003) in the following category:

* Comments - Ranked 1 with 255 comments
👍  
properties (23)
authorarcange
permlinkre-java-variables-for-day-4-of-30-days-of-java-20181003t184654000z
categoryjava
json_metadata""
created2018-10-04 16:53:57
last_update2018-10-04 16:53:57
depth1
children0
last_payout2018-10-11 16:53:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length219
author_reputation1,148,200,457,989,592
root_title"Java Variables For Day 4 Of 30 Days Of Java"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id72,626,230
net_rshares10,558,686,803
author_curate_reward""
vote details (1)
@ilovecoding ·
Hello! Your post has been resteemed and upvoted by @ilovecoding because **we love coding**! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On! 
 ![](https://codingforspeed.com/images/i-love-coding.jpg) 
*Reply !stop to disable the comment. Thanks!*
👍  ,
properties (23)
authorilovecoding
permlink20181003t195750846z
categoryjava
json_metadata{"tags":["ilovecoding"],"app":"ilovecoding"}
created2018-10-03 19:57:51
last_update2018-10-03 19:57:51
depth1
children254
last_payout2018-10-10 19:57:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length323
author_reputation40,845,997,808
root_title"Java Variables For Day 4 Of 30 Days Of Java"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id72,567,574
net_rshares10,612,569,512
author_curate_reward""
vote details (2)
@ilovecoding ·
Hello! Your post has been resteemed and upvoted by @ilovecoding because **we love coding**! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On! 
 ![](https://codingforspeed.com/images/i-love-coding.jpg) 
*Reply !stop to disable the comment. Thanks!*
👍  
properties (23)
authorilovecoding
permlink20181003t195756946z
categoryjava
json_metadata{"tags":["ilovecoding"],"app":"ilovecoding"}
created2018-10-03 19:57:57
last_update2018-10-03 19:57:57
depth2
children253
last_payout2018-10-10 19:57:57
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length323
author_reputation40,845,997,808
root_title"Java Variables For Day 4 Of 30 Days Of Java"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id72,567,578
net_rshares374,631,394
author_curate_reward""
vote details (1)
@ilovecoding ·
Hello! Your post has been resteemed and upvoted by @ilovecoding because **we love coding**! Keep up good work! Consider upvoting this comment to support the @ilovecoding and increase your future rewards! ^_^ Steem On! 
 ![](https://codingforspeed.com/images/i-love-coding.jpg) 
*Reply !stop to disable the comment. Thanks!*
👍  
properties (23)
authorilovecoding
permlink20181003t195802978z
categoryjava
json_metadata{"tags":["ilovecoding"],"app":"ilovecoding"}
created2018-10-03 19:58:03
last_update2018-10-03 19:58:03
depth3
children252
last_payout2018-10-10 19:58:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length323
author_reputation40,845,997,808
root_title"Java Variables For Day 4 Of 30 Days Of Java"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id72,567,580
net_rshares374,215,304
author_curate_reward""
vote details (1)