



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




with Java, for Beginners
Process of ProgrammingFundamentals:
ESE
2/
Edit
(Syntax + Semantics)
Compile
Run
(observe your output)
Compile-time
or Syntax Error
Run-time
or
Semantic
Error
ESE
3/
http://www.cis.upenn.edu/~palsetia/java/installDrJava.html
ESE
4/
ESE
5/
// An integer has no decimal point
10.5 // a floating point double‘a’
// a character has single quotes
true // The boolean literals are of two types: true, false“hello world” // A string literal
ESE
6/
to indicate addition
-
to indicate subtraction
to indicate multiplication
/
to indicate division
%
to indicate remainder of a division
(integers only)
parentheses
( )
to indicate the order in
which to do things
ESE
7/
==
equal to
!=
not equal to
<
less than
>
greater than
<=
less than equal to
>=
greater than equal to
Note: Arithmetic
comparisons
result in a
Boolean
value of
true
or
false
ESE
8/
E.g. If there is a test and you did not study for it...
-> OR operator
¾
true if either operand* is true
-> AND operator
true only if both operands are true
-> NOT operator ¾
Is a unary operator – applied to only one operand
Reverses the truth value of its operand
ESE
13/
Numeric types in Java are characterized by their
size
how much memory they occupy
Integer types
Floating point types
0:
2 bytes
char
-2147483648:
4 bytes
int
range
size
type
smallest > 01.4E-454.9E-
1.7E
8 bytes
double
3.4E
4 byte
float
largest
size
ESE
14/
Java also has objects - cover objects later
"Java"
"3 Stooges"
"3" + " " + "Stooges"
3 Stooges
3 + " " + "Stooges"
3 Stooges
ESE
15/
ESE
16/
Variable names
Also class and method names – next topic to cover
Java Rule
: May consist of alphanumeric characters and
the underscore
and must start with a
letter
Style Rule
: Should be a noun that starts with an
lowercase letter
E.g.
sum, average
E.g.
firstName, lastName
ESE
17/
All variables must be
declared
before being used
With a declaration
statement
Declaration statement
Specifies the
type
of the variable, followed by
descriptive
variable name
, followed by
semicolon
Examples:
int
seats;
double
averageHeight;
boolean
isFriday;
String
houseName;
ESE
18/
To store values into variable we use the
assignment
operator i.e. “
Variable = Expression; ->
assignment statement
Assignment statement must end with a semicolon(;)
When a variable is assigned a value, the old value isdiscarded and totally forgotten
Examples:
seats = 150;averageHeight = (2.1 + 1.74 + 1.58)/3;isFriday = true;houseName = ”gryffindor"
;
ESE
19/
ESE
20/
ESE
25/
Has a value
Consists literals and operators – FOR NOW!
Must end with semicolon(;)
Tells or commands the computer to do something
They are explanations of your program for humanbeings to read