- Java Programming Basics
Keywords, types, values, operators, expressions, variables, assignment statements etc.
Object-oriented programming: a class is a container. It contains:
a) static members
b) a blueprint
Classes don't need to be public all the time. If they are the file must bear their name.
Let's take a look at HelloApp2.java and Greeter.java.
You compile: javac HelloApp2.java which automatically compiles the other file.
Then run the class with the main: java HelloApp2
Now rewrite Greeter.java as follows. Then re-compile and run HelloApp2 again.
Similar, but quite different, right? (But definitely similar. Except distinctly different, as well).
- Working with Variables and Data Types
Describe how this program works when compiled and run.
Same question here.
Example of using a Scanner.
Getting input from a GUI element.
- Working with Numbers and Expressions
Compile and run this program. What does it do? How (does it work)?
Same question for this program.
Can you come up with a similar, useful variant of this program?
What's the purpose of this program? What is there to learn from it?
Same questions for this program, and for this one as well.
This is not the easiest way of formatting, but it's the most powerful.
- Making Choices
Lots of useful things, no full program developed.
- Loops
This already uses material from the previous chapter, but on a higher level.
Programs to look at, in order:
EvenCounter,
Duodecaphobia,
CountForever.
New version of Duodecaphobia, followed
NumberPhobia,
NumberPhobia2,
Duodecaphobia2.
Now start with EvenCounter2, then look at GetABet,
GetABet2 and
GetABet3.
Next we look at CountToTen,
CountToTenError,
CountToTenErrorFixed
and ForEvenCounter.
New group includes: CountDown,
LaunchControl,
TerseCoder,
CountBothWays and
ExpressionGanging.
We end with ForDuodecaphobia,
ForDuodecaphobia2,
NestedLoop, and the
GuessingGame.
- Using the Switch Statement
Here's VoterApp, and its variant VoterApp2.
Here's CarWashApp with the variant CarWashApp2.
- Methods
Simple example: HelloWorldMethod.
Have we seen this before?
When we say "function" we usually mean return type: example.
Now here's a rewrite of an earlier program. And
another. Can you explain the difference?
Two more examples: ParameterScope and
ChangeParameters.
And then: another rewrite.
Conclusions.
- Handling Exceptions
Read the chapter for all the details (though we need just a basic idea).
Programs: DivideByZero, GetInteger,
GetInteger2 introduce the topic.
Also: CrazyWithZeros,
FileException2
and MyException.