Archive

Archive for the ‘Module 3’ Category

Exercise 1 – Writing compiling and testing a program in Java

November 7, 2009 1 comment

 

 

Exercise for Introduction To Java Programming language:

 

This post has the exercise  for module 3 of  Introduction To Java Programming language. Let’s practice what we have learnt. Before practicing the exercise, follow the instructions below which will give you a step-by-step instruction: 

 

 

 

 

You can download the source code (WJ-1101A-exercise.zip) for this exercise from the Box widget in the sidebar. Follow the video tutorial below if you ever get stuck while executing the programs: Read more…

Advertisements

Developing & Testing a program in Java

November 6, 2009 Leave a comment

 

 

Module 3: Developing & Testing a Java Technology program.

 

Objectives:

1. Identify  4 components of class.
2. Use main method in a test class to run a java program from command line.
3. Compile & execute a java program.

 

1. Identify  4 components of class:

Going back to what we discussed before about classes, to construct a house you will first need a blueprint. Same thing applies for classes & objects. Similarly once you have a class blueprint, you  can have as many objects of that class as u like. These objects are called instances of a class. i.e., a shirt object is an instance of a shirt class.

 

27. class and its objs

 

Lets take a look at our first class:

Class is a blueprint that tells the computer how to make objects. This class blueprint – Shirt, tells the computer how to make Shirt objects.

 

28. 1st class

 

 

Structuring classes:

There are 4 major components of class that you will find more often:

  • class declaration – required
  • attribute variable declaration & initialization – optional
  • methods – optional
  • comments – optional

1. Class declaration is required, and this is all that you need to make a class valid. If all you had was this, then the class and its objects would be uninteresting serving no purpose. You will be needing some attributes and operations to jazz up the object.

2. Variables are characterstics of your objects. As we discussed in previous posts, these are characterstics /  properties and they are also data holders. They hold the data for the object.

3. In this Shirt class, only one method is defined. Methods are operations. They tell the class what to do.  Its what the class can do.  This method is printing all its information to the command window.

4. Comments are for developers to understand what the code is doing, they dont influence the execution in anyway.

 

Class declaration: Read more…