ComProg1 Lesson 2 - Introduction To Programming
ComProg1 Lesson 2 - Introduction To Programming
Why is it called Java? It is customary for the creator of a programming language to name the
language anything he/she chooses. The original name of this language was Oak, until it was
discovered that a programming language already existed that was named Oak. As the story
goes, after many hours of trying to come up with a new name, the development team went out
for coffee and the name Java was born.
II. Terminologies:
a. Computer Program – a sequence of statements intended to accomplish a task.
b. Programming – process of planning and creating a program.
c. Programming Language – set of rules, symbols, and special words used to construct
programs.
d. Class – used to create Java programs. It is used to group a set of related operations.
e. Method – a Java mechanism where operations in a program is implemented.
f. Identifier – names of things, such as variables, constants and methods, that appear in
programs.
g. Variable – memory cells whose contents can be modified during program execution.
h. Declaration – declare things such as variable; naming and identifying the data type of a
variable.
i. Initialization – placing for the first time the value of a variable.
j. Debugging – removing the errors in a program.
k. Reserved Words are names that cannot be used for anything other than their intended
use. (Example: int, double, char, boolean etc.)
III. Rules in naming Java variables
a. Variable names are case-sensitive. A variable's name can be any legal identifier — an
unlimited-length sequence of Unicode letters and digits, beginning with a letter, the
dollar sign "$", or the underscore character "_". The convention, however, is to always
begin your variable names with a letter, not "$" or "_". 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.
White space is not permitted.
b. Subsequent characters may be letters, digits, dollar signs, or underscore characters.
Conventions (and common sense) apply to this rule as well. When choosing a name for
your variables, use full words instead of cryptic abbreviations. Doing so will make your
code easier to read and understand. In many cases it will also make your code self-
documenting; fields named cadence, speed, and gear, for example, are much more
intuitive than abbreviated versions, such as s, c, and g. Also keep in mind that the name
you choose must not be a keyword or reserved word.
c. If the name you choose consists of only one word, spell that word in all lowercase
letters. If it consists of more than one word, capitalize the first letter of each subsequent
word. The names gearRatio and currentGear are prime examples of this convention. If
your variable stores a constant value, such as static final int NUM_GEARS = 6, the
convention changes slightly, capitalizing every letter and separating subsequent words
with the underscore character. By convention, the underscore character is never used
elsewhere. (Camelized)
IV. Java Primitive Data Types
a. char (16 bits)
b. byte (8 bits)
c. short (16 bits)
d. int (32 bits)
e. long (64 bits)
f. boolean (true or false)
g. float (6 or 7 decimal points)
h. double (15 decimal points)
V. Input and Output
a. Output
i. System.out.print();
ii. System.out.println();
iii. BufferedWriter
b. Input
i. BufferedReader
ii. Scanner Class
1. Code:
import java.util.*;
Scanner console = new Scanner (System.in);
console.next(); nextLine(); nextInt(); nextDouble();