COMP 210 -- Welcome!
Lecture 0
Thanks to Kris Jordan, Ketan Mayer-Patel and Dave Stotts for their help and large parts of the course material!
1
Welcome!
2
What are we learning in this class?
…and..
But first… a crash course on Java.
3
Warm-up!
4
Time to dive in! :)
https://www.cs.unc.edu/~kakiryan/teaching/summer-210/exercises/ex01.html
5
Let’s Begin!
6
Writing Programs in Java! (1/2)
7
Writing Programs in Java! (2/2)
public static void main(String[] args)
8
Compiling Java to Bytecode
9
Java’s Intermediate Representation Model
10
Main.java
Main.class
2. Run
Main.class
Java Virtual Machine (JVM) Program
Just-in-Time Machine Code
Zooming out for a moment: Execution Models
11
The “Main” Method
public static void main(String[] args)
12
Declaring Variables in Java
13
Value Data Types
14
Reference Data Types
15
Strings in Java
16
Scopes
17
Arrays
18
Control Flow
if (boolean_expression) {
// Block executes if expression is true
} else if (boolean_expression) {
// Can chain multiple ”else if” blocks as needed.
} else {
// Trailing optional else block executes if none above do.
}
19
For Loops
for (init; test; update) {
// Loop body
}
20
While Loops
while (boolean_expression) {
// Loop body
}
21
Defining Functions and Procedures in Java (1/6)
static access_modifier return_type name (param list) {
...
// method body
...
}
22
If present, indicates that method is a “class” method.
If not present, indicates that method is an “instance” method.
Defining Functions and Procedures in Java (2/6)
static access_modifier return_type name (param list) {
...
// method body
...
}
23
One of the following:
Defining Functions and Procedures in Java (3/6)
static access_modifier return_type name (param list) {
...
// method body
...
}
24
Type of value returned or void if method does not have a return value
return expression;
return;
Examples:
Defining Functions and Procedures in Java (4/6)
static access_modifier return_type name (param list) {
...
// method body
...
}
25
Name of the method… named using the camelCaseConvention!
Defining Functions and Procedures in Java (5/6)
static access_modifier return_type name (param list) {
...
// method body
...
}
26
Comma separated list of parameter names preceded with their type.
If absent, then method needs no parameters.
Examples:
Defining Functions and Procedures in Java (6/6)
static access_modifier return_type name (param list) {
...
// method body
...
}
27
A sequence of statements… each ends in a semicolon!
Calling (Static) Methods
28
Objects
29
The Scanner Class
30
Reminders
31