Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Java Basics

Course Module 2: Fundamentals of Programming

Java Basics

Elmer M. Aliño
Faculty, BSIT
Java Basics

TOPIC OUTLINE

2 Java Basics

• Special symbols
• Word symbols (Keywords)
• Naming convention for identifiers
• Primitive data types
• Rules of thumb in selecting data type
Java Basics

OBJECTIVES
A F T E R R E A D I N G T H I S P A R T O F T H E M O D U L E ,
T H E L E A R N E R S W I L L B E A B L E T O :

• Learn special symbols, word symbols,


identifiers and invalid symbols in Java

• Identify the primitive data type


categories

• Learn how to different data types


appropriately
Java Basics

Basic elements of Java


In this module, we will discuss the basic elements of java
which includes the character sets, escape sequences, tokens
and primitive data types.
Let us first discuss, character sets. These character sets are
simply a collection of characters that are used in Java
programming. You can see below the list of character sets
that are used in writing Java programs:

1. Letters (Uppercase A-Z and Lowercase a-z)


2. Digits (0-9)
3. Special symbols (Operators)

+ - * / !
&& || > < ++
<= != == >= %

4. Delimiters
a. Braces ( ), [ ], { }
b. Punctuation marks

, . ? ;

Aside from characters, word symbols or keywords are also


used in java. These keywords have special meaning in the
programming language and are also called reserved words.
Java Basics

Basic elements of Java


As mentioned in the earlier module, computers do not have
the capability to directly understand human language, that
is why every character are encoded or converted into
numeric form that the computer can be processed or
understood by the computer. There are different types of
encoding schemes that are supported by the Java Platform
[1]:
1. US-ASCII
2. ISO-8859-1
3. UTF-8
4. UTF-16
You can find more information about the encoding schemes
here:
https://docs.oracle.com/javaee/5/tutorial/doc/bncno.html

You can find a list of some of the keywords in Java below:

Figure 1. Some Java Keywords [2]


Java Basics

Naming convention

Identifiers are names for classes, variables, and methods.


Some identifiers are predefined; others are defined by the
programmer. Here are some rules in defining an identifier.
1. Should begin with letter, currency character (‘$’), or
underscore(‘_’)
2. After the first character, identifiers can have any
combination of characters.
3. Identifiers are case sensitive and cannot start with
a digit.
4. A reserved word cannot be used as an identifier.
5. Special symbols are not allowed to use, and space.
Java Basics

Primitive Data Types


Java categorizes data into different types and only certain
operations can be performed on particular types of data.
Every data type is associated with its own set of values. The
data type also determines how those values are represented in
memory and consequently, the amount of memory used.
A data type also defines a set of operations on its data values.
The primitive data types are fundamental data types in Java.

Categories of primitive data types:


a. Integral data type – represents integers or whole numbers.
Data type Range
byte -128 to 127
short -32768 to 32767
int -2147483648 to 2147483647
long -922337203684547758808 to
922337203684547758807
char represents single Unicode character values
such as letters, digits and special symbols, char
data type enclosed each character
represented within single quotation marks
(apostrophes ‘ ‘).

b. Floating-point data type – represents numbers with


fractional parts.
Data type Range Maximum significant
digits
float -3.4E+38 to 3.4E+38 6 or 7

double -1.7E+308 to 1.7E+308 15

The maximum number of significant digits of a data type is


called its precision.
Java Basics

Primitive Data Types


Rules of thumb in choosing data types [3]:
1. For numbers, use an integer type if possible. Use a
floating-point type only if the number contains a
fractional part.
Although floating-point numbers includes integers (e.g.,
1.0, 2.0, 3.0), floating-point numbers are approximation
(not precise) and require more resources (computational
and storage) for operations.
2. Although there are 4 integer types: 8-bit byte, 16-bit
short, 32-bit int and 64-bit long, we shall use int for
integers in general.
Use byte, short, and long only if you have a good reason
to choose that particular precision.
3. Among there are two floating-point types: 32-bit float
and 64-bit double, we shall use double in general.
Use float only if you wish to conserve storage and do not
need the precision of double.

4. char, boolean and String have


their specific usage.
Java Basics

References
• Java Keyword List. Retrieved August 3, 2020 from
http://bytesofgigabytes.com/java/java-keywords/
• Java Encoding Schemes. Retrieved August 3, 2020
from
https://docs.oracle.com/javaee/5/tutorial/doc/bn
cno.html
• Java Programming Tutorial. Retrieved July 21,
2020 from:
https://www.ntu.edu.sg/home/ehchua/programmi
ng/java/J2_Basics.html#zz-2.1

You might also like