Introduction

Welcome to the Java Trainer. This system was designed to help beginning students develop the  ability to solve simple programming puzzles using the Java programming language.

As you progress through the Java Trainer, you will get a chance to practice on many programming puzzles. Depending on your background and your aptitude for such puzzles, you may find them a bit difficult at times. But don't give up!  The puzzles build on each other, so if you get stuck on one you will probably find yourself getting stuck for the same reason on others. Get help if you need it. You may need to practice on some of the puzzles more than once to master them. Notice that word master: you may be able to solve the puzzles by trial and error or by getting the answer from someone else, but don't settle for that. Challenge yourself not just to solve the puzzles, but to master them.

We are sorry that this is so much work. It would be nice if there were a pill you could take to learn how to program. It would be nice if you could just read about it or watch a video about it and master it that way. Unfortunately, you can't—as far as we know!  We explain everything you need, of course, but most people don't get it just from reading about it.   The only way we know for you to learn this important skill is to jump right in and practice it.

The place to start is at the beginning of Lab One.  Good luck!

Table of Contents

Lab One:
    Classes
    Expressions
    Values and types
    Expressions on integers
    Pure operators
    A word about precedence
    First puzzles
    Side-effecting operators
    Contractions
    The value of an assignment expression
    Idiomatic Java

Lab Two:
    boolean constants and variables
    Ands and ors
    Flipping boolean values
    Combining boolean operations
    Comparisons
    Statements
    Expression statements
    Compound statements
    if statements

Lab Three:
    Methods
    The return statement
    Method declarations, part one
    Method declarations, part two
    Method declarations, the full picture
    Declarations
    Instance variable declarations
    Local variable declarations

Lab Four
    The char type
    The String class
    Expressions that use methods
    String operators
    Class methods
    Declaring class methods
    Calling class methods
    The Character class
    Calling another method in the same class
    Summary: how to call methods

Lab Five
    The while statement
    Counting loops
    Writing loops froms scratch
    The biggest hurdle

Lab Six
    Quick reminders
    Puzzles
    Harder puzzles

Lab Seven
    Objects and references
    Constructors
    Creating new objects
    Disposing of objects
    Arrays
    Accessing an object's variables

Lab Eight
    The for statement for counting loops
    The for statement in general
    The do loop
    Arrays of objects

Lab Nine
    Real numbers in Java
    The Math class
    Rounding errors
    The integer types
    Type conversions
    Promotions
    Using char as a type of integer
    Benediction

Java Trainer text and software, release 1.
Copyright (c) 1998 by Adam Webber.