Lecture 6

a refresh of previous course is done…with a focus on division operator

after some brief example proving how / (division operator) works with both, integer and double numbers, the discussion turns towards operator precedence

6:44 cast – or how to transform between different types of data

so, how can you help temporarily an expression to handle double data if it has only integer parameters, that after a division result in a double

12:52  the discussion until this moment in time was about casting and rules of operations, it will follow “some shorthands of mathematical expressions

those refer to the notorious += or to increment operator ++

15:30 Constants are introduced (as opposed to variables :), to quote Mehran “variables vary, constants remain the same“)

some commonly used constants, like the PI number, are introduced

how can you define a constant in Java?

private static final …

why private? because the constants should not be accessed outside the class where they are defined.

why static? this constant lives for the class and it is just one of them, only one instance. It is not the case for different instances of this class (objects) each one to have their own version of a static variable, all of them are sharing the same.

why final? get your hands out of my PI! this value cannot be changed, like the const in C

in the end it becomes

private static final double PI = 3.14;

what are constants good for, changes apply into one single place (where they are defined), there is no need to go through the code and search where they are used and manually change those values.

21:06 a rule of thumb concerning constants  – give relevant names

23:57 next topic … booleans, but before going into the “technical stuff” it really worths listening the history about George Boole’s death, even in essence is a tragic event the story is really funny

boolean expressions are just a test test (they can be either true of false)condition which are assigned to a bool variable

operators that may generate such conditions (like >=, ==, != … and many others including also the binary boolean operators && and )  are introduced

30:20 short circuit evaluation – if you are familiar with logical operations this has to be trivial, mainly this is about the fact that TRUE ORed with anything else results in a TRUE, and FALSE AND anything else results in a FALSE

32:07 it is time to talk about statements (do you think this is boring?, or maybe not who knows, even if I doubt this): the most basic statement is the block, which looks like this:

{

… //declaration

}

why is important? because it is the scope (scope meaning also lifetime of the variabel, if the variable is not a static one) of variables declared inside it

32:39 they way we can refer to scope, is not a mouth wash (that was good! :))

35:30 it is always a good idea to use braces even if it is only one if statement pro bably a well known rule of thumb in programming but it worths mentioning it again

36:00 well.. the worldwide known example of testig the parity of a number using if else statements

38:22 aything you could do with a cascading if statement you can do with a switch statement

it follows then the for and while and … that’s all folks!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: