Week 011 - 012-Presentation Java Architecture
Week 011 - 012-Presentation Java Architecture
Module Overview
This module covers the basic Java architecture including comments,
identifiers, keywords, literals, separators, primitive and integer data
types, expressions and declarations. Appropriate syntax for each are
discussed as well.
After completing this module, students are expected to:
1. write comments;
2. determine identifiers, reserved keywords, literals and separators;
3. enumerate different primitive data and integer types and identify their
difference; and
4. distinguish expressions and declarations in a Java program.
Comments
• Comments, as a part of Java internal documentation, provide
explanation for the purpose of a particular piece of code in a
program.
• They are usually written in plain and simple English language.
• Comments are ignored by the compiler. It will not affect the
program except add to the number of lines.
Comments (cont.)
• There are three types of comments:
1. Traditional comment. All text from /* and */ is ignored by the
compiler.
2. End-of-line comment. All text from // up to the end of the line
is ignored.
3. Javadoc comments. All text from /** and */ is ignored by the
compiler. A Javadoc comment is written for people who do not
read the Java program itself. There’s a certain program called
Javadoc which extracts all the Javadoc comments and turn them
into a web page.
Comments (cont.)
• Syntax for a traditional comment is shown below. Double
forward slash followed by the comment text.
// comment
Example:
Comments (cont.)
• Syntax for a traditional comment is shown below. Forward
slash, asterisk, the comment text, asterisk and forward slash
again.
/* comment */
Example:
Comments (cont.)
• Syntax for a Javadoc is shown below. Forward slash, two
asterisks, the comment text, an asterisk and forward slash
again.
/** comment */
Example:
Identifiers
• Identifiers are basically names you give to a variable, method,
class or other Java elements. Its meaning can change from one
program to another, unlike keywords.
• Examples of identifiers are:
1. String
2. weight
3. MAX_VALUE
4. perfectScore
5. isPerfect
Identifiers (cont.)
• Remember that an identifier cannot have the same spelling as a
keyword, a Boolean data type or a null literal.
• There are also identifiers from Java API (Application Program
Interface):
1. Integer
2. File
3. String
4. JWindow
5. JButton
Keywords
• The words listed in the table at
the right are Java keywords or
reserved words.
• They have their special
meaning in Java programming
language and this meaning
remains constant from one
program to another.
• You cannot use these words
as identifiers or name for your
variables and constants.
Separators
• Java uses the following separators or punctuators to divide
code into segments.
• ( ) Parentheses. Used in control statements and parameter
list in a method.
• { } Curly Braces. These are used to define the scope of
Java code, class and methods.
• [ ] Square Brackets. Used in array declaration.
Separators (cont.)
• ; Semicolon. Used to terminate a Java statement.
• , Comma. Used in method parameter list and variables
declared in a single line.
• . Period. Used in package name and class name and in
separating a variable or method from its instance or object.
Primitive Data Types
• In Java, there are primitive data types, or simple types, that we
will be working with most of the time.
• These are the lowest-level objects in Java programming since
they are non-grouped pieces of data.
Primitive Data Types (cont.)
Integer Data Type
• Integers, or simply whole numbers, are used in Java
programming if you are dealing with numbers WITHOUT
decimals.
• There are four (4) types of integer data type – byte, short,
int and long.
• Each integer data type can handle different range of value, as
shown in the previous table.
Integer Data Type (cont.)
• The syntax in declaring an integer data type is:
<data type> <name> = <value>;
Examples:
Decimal Data Types
• Floating-point numbers, or decimal data types, are equivalent to
real numbers in Mathematics (e.g. 3.141516, -77.7)
• Don’t worry, we’re not doing Math here.
• Java has two (2) kinds of floating point data types – float and
double.
• Float is a single precision floating point while double is a
double precision floating point.
• They also vary in the value range they can handle as shown in
the previous table.
Decimal Data Types (cont.)
• The syntax in declaring an integer data type is:
<data type> <name> = <value>;
Examples:
Character Data Type
• Character literals are specified with single quotes (‘’) such as
‘a’, ‘A’, ‘@’ or ‘7’.
• Characters from the ASCII set are considered character literals
as well as escape sequence.
• There are 128 ASCII characters composed of letters, numbers
and special characters.
Character Data Type (cont.)
• The syntax in declaring a character data type is:
char <character name> = ‘<value>’;
Examples:
Character Data Type (cont.)
• There are also ASCII characters which are not readily available
through the keyboard but you may include them in your code
using their special characters.
Boolean Data Type
• A Boolean data type can only have two values – true or
false.
• Other programming languages have boolean values of 0 for
false and 1 for true.
Boolean Data Type (cont.)
• The syntax in declaring a boolean data type is:
boolean <boolean name> = <value>;
Examples:
References
• Gosling, J., Joy, B., Steele, G., Bracha, G. & Buckley, A. (2015). The Java
Language Specification. Java SE 8 Edition. California: Oracle America, Inc.
• Oracle. Java™ Platform Standard Ed. 7. Retrieved from:
https://docs.oracle.com/javase/tutorial/java/