Java For Beginners Level 1
Java For Beginners Level 1
Beginners
University
Greenwich
Computing At
School
DASCO
Chris
Coetzee
What do you learn last time?
Wordle.org
3 Laws of Java
Project: CheeseCake
Class: CheeseCake
Method: main()
Main method
Levels of Java coding
• 1: Syntax, laws, variables, output
• 2: Input, calculations, String manipulation
• 3: Selection (IF-ELSE)
• 4: Iteration/Loops (FOR/WHILE)
• 5: Complex algorithms
• 6: Arrays
• 7: File management
• 8: Methods
• 9: Objects and classes
• 10: Graphical user interface elements
Variables vs. Value
double
boolean
int
char
String
Why not have just 1 type?
• Only type big enough to cope with
sentences is Strings
• Strings are BIG compared with
booleans/ints
• To save space, we only use the box
type that is “just big enough” to contain
the value we want.
• Less waste = faster programs!
Strings: “cat” “DA1 2HW”
double
boolean
int
char
String
int: 23 0 -98 39290 -321
double
boolean
int
char
String
double: 1.2 -5.93 3.3333
double
boolean
int
char
String
boolean: true / false
double
boolean
int
char
String
char: ‘a’ ‘3’ ‘@’ ‘A’ ‘ ’
double
boolean
int
char
String
What data type is each of
the following?
-9 double
4.5 boolean
int
chicken char
false
% String
£ 2.90
The cat is hungry now.
192.168.1.190
Declare vs. Instantiate
number = 3; Instantiate
!
ne
li no
!
ne
i no
!
ne
i no
23
Output
23
23
Combining values and variables
int num1 = 5;
int num2 = 10;
System.out.println(num1+num2);
System.out.println(num1+” + ”+num2);
15
Output
5 + 10
What went wrong?!
22
Output
8