Making Java Great Again Part 2

Language Building Blocks

Now that we got some important concepts let us take a look at the language itself.

Comments

Comments are used to document your code. Writing comments in your code while you are learning as well as developing is a very powerful habit to obtain. These comments can be used by other developers that might come along later to maintain or modify the code you wrote. Also comments can be extremely useful to you the author-many times to help you remind why you did something a certain way or why you didn’t do something.

Single Line, Multi Line & Doc comments

Single line comments begin with // and then your comment. The compiler will ignore anything written between // and the end of the line. Multi line comments begin with /* can span multiple lines but must end with */ and like the single line, everything written between the /* and */ will be ignored by the compiler. Doc comments begin with /** and can also span multiple lines but must end with */ The compiler ignores everything between the /** and */ then are used by Javadoc utility to generate HTML documentation for your program.

Identifiers & Data Types

Identifiers

An identifier is a sequence of characters used to name a variable, method class or package. A Java identifier must adhere to the following rules.

  • It cannot span multiple lines
  • It must only contain numbers, letters, underscores, dashes, and dollar signs.
  • It must start with a letter, underscore, dash or dollar sign.
  • It cannot contain any spaces

Before creating an identifier, research the Java reserved keywords; because you cannot use them as identifiers.

Data Types

Data types describes the internal representation of a piece of data and the operations that can be applied to the data. Java has two kinds of data types: primitive and developer defined. Research all the Java data types with any search engine like google.

Literals, Variables & Expressions

A literal is a sequence of characters that represent a data item in the program. Java has six data literals:

  • Boolean : Reserved words True and False are boolean literals
  • Character : A character literal is represented by a single character
  • Floating point number : A number with a decimal
  • Whole number : Pretty self explanatory….A whole number
  • Null : Research via google
  • String : a sequence of characters surrounded by double quotes
Variables

A variable is a named piece of memory where you can store the value of something. To store that value you must declare your variable like : data_type variable_name;

Expressions

An expression is a statement that can be evaluated to produce a result. The result of the expression can be used in your program. Expressions can be simple or complex but in the end they are all made up of the same components- operators and operands. If you are not familiar with the terms operators or operands, well then google it…=]

 

Leave a comment