Use the arrow keys to navigate. Press 'm' to see all the slides.
javac Example1.java
This creates a file called Example1.class, containing the bytecode
java Example1
Primitive types
Assignment of values
Declarations
Everything lives inside a class
Methods
Basic Input and Output
Conditionals
Loops
Arrays
Variables are how we represent data stored in memory
In Java, variables have types
boolean
int
double
char
String
Variables are how we represent data stored in memory
Variables need to be declared before using them
a+b, a+y, a-b, a/b, a*b, a%b, p|q, p&q
!w, a+, a--
a=b, a+=b, a-=b, x=y,
a=10, p=false, y=1.5
Data is stored in binary
We use bytes to measure an amount of binary data
1 byte: 8 binary digits, or bits
8 bits can represent numbers from 0000 0000
to 1111 1111
boolean
→ 1 bit (The actual size is not this) int
→ 4 bytes double
→ 8 bytes char
→ 2 bytes String
of n characters → 2*n bytes What is the range of numbers we can represent with an int
variable?
How are real numbers represented with the bits of an double
variable?
{ }
;
public
means "anyone" can load this class or execute this method (More on this later) public static void main
defines the starting point of execution
static
on method declaration means "anyone" can execute this method from any part of the code public static void
means the method won't return anything public static int
means the method will return an integer number
Scanner
classimport java.util.Scanner
allows us to use the Scanner code, written by someone else/