Exercises, examples and other material relating to training module J706. This topic is presented on public courses Learning to Program in Java
, Java Bootcamp
, Java Programming for the Web
In Java, we place all our code in "classes". Each class contains one or more named blocks of code known as methods, and the group of methods provides all the functionality that's required to handle data (or objects) of a particular type.
|Articles and tips on this subject||updated|
|4422||Objects - from physical to virtual or abstract - Java|
A train, a person, a dog, a signpost, a meal, a station ... they're all similar objects in programming terms. We can set them up in our program, save and restore attributes - and they make an excellent teaching parallel comparing real life things ("objects") of a certain type ("class").
|4413||Binomial Coefficient (Pascal Triangle) objects in Java|
An exercise on our Java course from which our delegates gain a lot of appreciation is the one in which I ask them to set up an array of arrays containing Pascal's Triangle of Binomial Coefficients. It sounds mighty complex, but I explain it on the board and it comes down to just defining the arrays ...
|2169||When should I use OO techniques?|
We have two friends. They're married. She's a keen advocate of Object Oriented Programming and he can't stand the approach. So take them to the pub, buy them a couple of drinks each, mention OO programming and watch the feathers fly ;-)
Seriously, Object Oriented Programming has its place - and there ...
|1296||An example of Java Inheritance from scratch|
One of the most important topics for newcomers to OO (Object oriented) programming to learn is how to design their classes and make best use of inheritance, and I find myself writing new examples from first principles during our courses. That way, the delegates learn how to actually do the job - they're ...
|477||Class, static and unbound variables|
In Object Oriented programming, you'll have certain named blocks of code (usually known as methods) that you can perform on specific objects (type A), and others that you can perform on all the objects of a particular type (type B).
If I had a class called sandwich, I might have one method ...
|2651||Calculation within objects - early, last minute, or cached?|
When you create an object with the constructor, you may also set property [attribute] values within it ... or you may follow on with a series of method calls to set the initial values. Then when you pull back values / attributes / properties from your object you return those values, or the results ...
|2616||Defining a static method - Java, Python and Ruby|
Most methods in classes that your write will be run on / applied to individual objects within that class - you'll be asking for the colour of a marker pen, or setting the price of a hotel room. You will NOT - typically - have a model in which all marker pens share the same colour.
But - just occasionally ...
|2422||Looking inside Java classes - javap and javadoc|
javap is a program that looks inside a Java class and reports on all the methods and variables that are exposed by that class ... so it's looking at a Java class's object format.
javadoc is a program that analyses Java source code and reports on all the methods that are exposed by that class.
|1925||Introduction to Object Oriented Programming|
"Object Oriented Programming" is a whole new philosophy for programmers who have been writing short scripts for years, and it can be quite frightening to learn with all these new buzzwords like "overriding", "encapsulation" and "polymorphism" creeping in. It's a beautiful concept and a lovely approach, ...
|1906||Long, Longer, Longest in Java|
If you want to find out how long a Film3 is, in the class that I use on our private Java Programming courses, you can call the getminutes method. That's standard OO stuff. But what if you want to find out which is the longer of two Film3s or the longest of a whole array of them?
Don't re-write code!!!. ...
One of the vital topics on all our programming courses is that of variable scope. Variable Scope may be defined as the area of a program in which a variable is visible, and how long that variable is accessible for.
Why do I describe variable scope as a vital subject when you can write simple programs ...
|1500||First Class Java. First step and moving forward.|
Java is an Object Oriented language that's great for medium size through large to huge systems. Which means that it's not usually the best approach for short applications ... of the size that one typically uses as examples on a training course. So examples that I produce show mechanisms and extensibility ...
|1163||A better alternative to cutting and pasting code|
If you're new to coding, you'll be so concerned to be writing code that works that you may not take a look at coding technique. Your nose will be so close to the grindstone as you work that you won't take the time to look and ask "Do I need to keep grinding anyway?"
If you find yourself writing a piece ...
Examples from our training material
|Animal.java|| Sample class for use during practical|
|Eve.java|| Example class that uses the Film class |
|Eve2.java|| Example class that uses the Film2 class |
|Eve3.java|| Static methods and comparing objects - test harness|
|Film.java|| Defining a simple class of objects in Java |
|Film2.java|| A class of objects with static methods, public variables, overloaded constructors and private internal methods |
|Film3.java|| Static methods and comparing objects - class|
|Ourmenag.java|| Sample application for use during practical|
|Ourpets.java|| Our Pets - example application|
|Ourzoo.java|| Ourzoo - sample application|
PicturesOur courses are half practials and half lectures
You may download this module
as a sample of our material
Topics covered in this module
Using an instance of a class.
Some detail of using an object.
Writing your own class.
Enhancements to the basic class structure.
Class or static methods.
Direct variable access.
If you are looking for a complete course and not just a information on a single subject, visit our Listing and schedule
Well House Consultants specialise in training courses in
. We run
throughout the UK (and beyond for longer courses), and
at our training centre in Melksham, Wiltshire, England.
It's surprisingly cost effective to come on our public courses -
even if you live in a different
country or continent to us
We have a technical library of over 700 books on the subjects on which we teach.
These books are available for reference at our training centre. Also
available is the Opentalk
Forum for discussion of technical questions.