Programming 1 Laboratory and Lecture
Programming 1 Laboratory and Lecture
Steps to Implement Java Program The next line of code is shown here. Notice
that it occurs inside the main() method.
Implementation of a Java application
program involves the following steps. They System.out.println("Hello, World");
include:
This line outputs the string “Hello, World” Char- a single character
followed by a new line on the screen. Boolean -a boolean character (true or false)
Output is accomplished by the built-in
println( ) method. The eight data types in Table are called
primitive because they are simple and
Comments uncomplicated.
They can either be multiline or single-line Primitive types also serve as the building
comments. blocks for more complex data types, called
reference types, which hold memory
// This is a simple Java program. addresses.
// Call this file "HelloWorld.java".
Declaring Variables
Declaring and Using Constants and A variable declaration is a statement that
Variables reserves a named memory location and
includes the following:
A data item is constant when its value • A data type that identifies the type of data
cannot be changed while a program is that the variable will store
running. For example, when you include the • An identifier that is the variable’s name
following statement in a Java class, the • An optional assignment operator and
number 459 is a constant: assigned value, if you want a variable to
contain an initial value • An ending
System.out.println(459); semicolon
Every time an application containing the Variable names must be legal Java
constant 459 is executed, the value 459 is identifiers.
displayed. Programmers refer to a number a variable name must start with a letter,
such as 459 in several ways: cannot contain spaces, and cannot be a
• It is a literal constant because its value is reserved keyword.
taken literally at each use.
• It is a numeric constant as opposed to a Camel casing- Beginning an identifier with
character or string constant. a lowercase letter and capitalizing
• It is an unnamed constant as opposed to subsequent words within the identifier
a named one because no identifier is
associated with it. An assignment made when you declare a
variable is an initialization
A variable- is a named memory location
that can store a value. Associativity refers to the order in which
values are used with operators.
Byte - bytelength integer
Short - short integer An identifier that can appear on the left side
Int - integer of an assignment operator sometimes is
Long- long integer referred to as an lvalue
Float- single precision floating point
Double- double precision floating point
an item that can appear only on the right
side of an assignment operator is an rvalue.
Arithmetic Operators