See also:
About prof. George
Get to know each other
Learning objectives:
Java background not assumed, but programming background is assumed
Projects:
Discussions:
Quizzes:
Final exam
Late homework not accepted, except in special circumstances
Project 1 out today; discussions start tomorrow.
You are encouraged to follow along while we do demos in lecture. We will also post the demo code in the public course repository
Today we will:
In Eclipse, a project is a set of related files that typically comprise a single program. You should create a new project for each assignment. I will create a project for the lectures, and share it with you. You should also create a project for the lectures.
Within a project, all code will go inside of a class. Much more on classes later.
We will want to save all of our editing history in source control. This allows us to keep track of what we've changed and look at old versions. A repository is a place to store the extra versioning information.
Now we will save (or commit) the empty project into the history:
This will save your history locally; We'll show you later how to share repositories with your teammates.
After you finish a task, you should go through the commit process again, reviewing the changes you've made, and adding a helpful message indicating what task you've completed.
Static / compile-time: Known before the program is run
Dynamic / run-time: May change while running the program
Java is statically typed: each variable has a type that is known at compile time.
Python and Matlab are dynamically typed: the type of a variable can change while the program is running.
Dynamic typing is usually less verbose, but more error prone. Static typing gives you much more support while developing a program (e.g. autocompletion, error detection and correction, source code navigation).
A Type is a set of possible values with operations on them.
There are two kinds of types in Java:
boolean
(true/false),int
(integer: -7, 0, 35),char
(character: 'a', 'b'),double
(double-precision floating point: 0.12, 3.14159, -1.1212)byte
, float
, short
, long
void
indicates the absense of a valueString
, JFrame
, System
MyType
Here we list the possible values and operations on primitive types:
Values: true
, false
Operations: * b1 && b2
means "b1
and b2
"; it evaluates to true
if both b1
and b2
are true, and false otherwise * b1 || b2
means "b1
or b2
"; it evaluates to true
if either b1
or b2
are true * !b
means "not b
"; it evaluates to true
if b
evaluates to false
Values: Integer.MIN_VALUE
.. Integer.MAX_VALUE
(which means −231…231 − 1
Operations wrap if the value is bigger than Integer.MAX_VALUE
: * i1 + i2
, i1 * i2
, -i1
, etc. * i1 / i2
gives the (integer) quotient of i1 divided by i2 * i1 % i2
gives the (integer) remainder of i1 divided by i2 * i1 == (i1 / i2)*i2 + (i1 % i2)
Values: 'a'
, 'b'
, '$'
, '\n'
(newline; some special characters start with a \
), \\
A character is only a single symbol; things like 'hello world'
won't compile
Operations: none of interest to us
Note: characters are actually integers! There is a well-defined lookup table (called the Unicode standard) giving symbols for each integer. For example:
'a'
is just a symbol for 97; 'A'
is a symbol for 65, '😀'
is a symbol for 128512.
Values: 3.14
, -17.0
, 6.02e23
(scientific notation), Double.NaN
, Double.NEGATIVE_INFINITY
, Math.PI
, etc
Operations: +
, *
, etc.
long
, short
, and byte
are just like int
but can hold smaller (or larger) numbers, to save space.
float
is just like double
, but smaller.
Object types are not built-in to the Java language (although some, like String
are packaged with the standard library). Each object has a class associated with it; the class determines the operations available.
For example, we created a class called Demo
. Inside Demo
, we created a method f(int)
. This means that if we have a variable of type Demo
, we can call it's method f
as follows:
Demo d = new Demo();
d.f(3);
We'll talk much more about Object types later.