Learn Java Coding

Everything You Have To Know About Java

Variables

Variables are names for every information you save in Java.

values java

In Java it looks like this:
String name = "Jack the Programmer";
int age = 60;
double length = 1.9;
String hobby = "Hit the Gym!";
String Haircolor = "Black";

Why use types? (String, int, double)

WHY? CLICK HERE!

Different Variables

In Java, 2 kind of variables exists, variables containing:

 CONSTANTS

  JUST VALUES

If a value can be used multiple times you make it constant. The rest are just values because of its uniqueness .

Example

values java

You can see the different color circles.

CONSTANTS

JUST VALUES

·      “hit the gym!”

·     “black”

·      “Jack the Programmer”

·      60

·      1.90

why?

Hobby and hair color are characteristics that could be the same for many people. Name is definitely some unique value. However, you can argue about age and length, in this example we say it are unique values, with not so much similarities among other people.

programming language

We should rewrite the above code; WORK AS MUCH WITH CONSTANTS AS POSSIBLE

In Java it looks like this:
static final String GYM = "Hit the Gym!";	//constant
static final String BLACK = "Black";			//constant

String name = "Jack the Programmer";
int age = 60;
double length = 1.9;
String hobby = GYM;
String Haircolor = BLACK;

How to write:

 CONSTANTS (also some info about FINAL and STATIC)

  VARIABLES

 

 

GO TO NEXT

Next Post

Previous Post

© 2024 Learn Java Coding