Week 2 Lecture 4 - Programming Basics in Java Part 1
Week 2 Lecture 4 - Programming Basics in Java Part 1
❑ Lexical Issues
❑ Reserve Words
❑ Data Types
Tokens/ Lexical Issues
Tokens are the smallest meaningful symbols in the language.
Token type Description/Purpose Examples
Keywords are the reserved names of a language and cannot be used as int, double, for, while
names of variables, functions etc. Words with special meaning
to the compiler
Identifiers refers to the names of variable, arrays, functions, classes, std, x, myFunction, sum
Interfaces etc.
Literals refer to fixed values that we cannot change in a program. "Hello, world!", 24.3, 0, ’c’
Operators are special symbols which operate on variable & constants, and +, -, &&, %, <
form an expression.
Punctuation Are the special characters used to separate statements. {}(),;
/Separators Punctuation defining the structure of a program
Whitespace Spaces of various sorts; ignored by the compiler Spaces, tabs, newlines,
comments
Identifiers
An identifier is a word used in a program to name
a variable, method (function), class, interface,
package etc.
Identifiers
To name an identifier you must follow some rules:
▪An identifier (a name) can contain only letters, digits 0 through 9, and the underscore
character (_).
▪The first character in an identifier cannot be a digit.
▪In particular, no name can contain a space or any other special character other than $
and underscore _.
▪There is no limit to the length of an identifier.
▪Java is case sensitive. That is, uppercase and lowercase letters are considered to be
different characters. For example, Java considers mystuff, myStuff, and MyStuff to be
three different identifiers, and you could have three different variables with these
three names.
▪Keywords cannot be used as identifiers.
Contin....
Reserve Words
oReserved words or keywords are words that have a specific meaning
to the compiler and cannot be used for other purposes in the
program.
oFor example:
When the compiler sees the word class, it understands that the word
after class is the name for the class.
Reserve Words
There are 50 reserved keywords in Java.
The keyword const and goto are reserved but not used.
All keywords are in lower case.
true, false, and null are literals not keywords .
In any program, you need to store particular type of data in the computer’s
memory. The compiler should know the amount of memory that has to be
allocated to that particular data. It directs the compiler to allocate specific
amount of memory to a particular type of data.