Programming Notes

LESSON 2:Data Types, Variables and Java Packages
1. Data Types
I think coming from C++ to java is one of the easiest programming language transformations. You get most of the things are what you already know, and thus you wont have a hard time. Java supports 8 primitive data types;
 byte
 short
 int
 long
 float
 double
 boolean
 char
Unlike in C++, the data type ‘String’ is a class in Java. It contains numerous methods that can be used to handle and manipulate strings in Java.
2. Variables
Java programming language has 4 kinds of variables.
i) Instance variables
ii) Class variables
iii) Local variables
iv) Parameters
Coming from C++, (iii) and (iv) should be very familiar to you. The good thing is, everything you knew about them in C++ is also true in Java!
Naming Variables
Just like in C++, there are various housekeeping rules and conventions that you have to follow when you are declaring variables in java.
i) Variables are case sensitive.
ii) A variable name can be any length of Unicode1 letters and digits, beginning with a letter, the dollar sign "$", or the underscore character "_".
Additionally, the dollar sign character, by convention, is never used at all. You may find some situations where auto-generated names will contain the dollar sign, but your variable names should always avoid using it. A similar convention exists for the underscore character; while it's technically legal to begin your variable's name with "_", this practice is discouraged.
iii) White space is not permitted.
iv) Subsequent characters may be letters, digits, dollar signs, or underscore characters. When choosing a name for your variables, use full words instead of cryptic abbreviations. E.g. studentID instead of stdid, sid or stdntid ; grade instead of grd, gd or grde, etc. This will make it easier to understand what your variables are meant for.
v) The name that you choose for your variable name must not be a keyword2.
vi) If the name you...