Prework #3

String welcomingMessage = "Hi everybody, today I started learn Java!"
System.out.println(welcomingMessage);

 

How excited it is.
So today I learned basics about variables and methods.

I will tell You what I know now!

Variables

Variables for me is variable == some data, some value – this is not the end of the truth but I understand it that way.

In Java there are couple types of variables:

  • int – integer number eg. 10, 5, 4, 198273 etc.
  • double – floating numbers  eg. 10.5, 1.25, 45.4, etc.
  • stringtext variable eg. “this is my blog welcome” String is class represent character string
  • boolean – this variable has only two value true or false

So if You want to declare variable You should think about it type. I didn’t write all types in Java here. But I will later.

For e.g. my age – age is a number, it is not float number is integer – so You have to write it like this:

 int myAge = 36;

In this declaration I do one additional thing. I declared variable as integer with name variable myAge (first thing), but second I initialized it to the value 36. I do this by equal sign “=”.

Variables can be local variables or class variables. But this is history for another time.

Methods

Method is a function which You can execute, induce. You declare method because You want to do sth, count sth or show sth. I understand method as doing sth.

static void doSthAsIWant(){ // do something with variables, count sth, }

Ok, basic example. You want to say hello to a stranger girl!

static void sayHelloToStrangerGirl(){

System.out.println("Hi Stranger Girl, How are You?!");

}

To execute this method You write only:

sayHelloToStrangerGirl();

To understand look at this code:

public class Methods {

    public static void main(String[] args) {

        sayHelloToStrangerGirl(); // this is execute of method
    }

    static void sayHelloToStrangerGirl() { //this is Your method
        System.out.println("Hi Stranger Girl, How are You?!");

    }
    
}

to be continued…