Archive

Posts Tagged ‘variables’

Creating and using objects in Java

November 11, 2009 Leave a comment

 

Module 2: Creating and using objects.

 

Objectives:

  • Declaring object references, instantiating objects, and intializing object reference variables.
  • Compare how object reference variables are stored in relation to primitive variables.
  • Use a class (the String class) included in the Java SDK.
  • Use the J2SE class library specification to learn about other classes in this API.

 

In the previous module we discussed about primitive data types and how to use them with variables. In this module we will be focussing about objects and object reference variables. We will learn how object reference variables are stored in memory with reference to local variables. We will also take a look into the String class, as well as the class library specification to know about the other classes that we have access to.

 

1. Declaring object references, instantiating objects, and intializing object reference variables:

In the previous module we were dealing with primitive data types. And when we declared a variable of  a primitive datatype, we stored the primitive in the variable itself. But Java is object oriented language, so we really want to be dealing with objects. While dealing with objects you will also need a variable associated with it. But it works different with the objects. You dont store an object inside of a variable like you do with the primitives. What you do is, you store a reference to the object inside the variable.

Now a reference is like an address to a house. It allows you to find that object. So using that reference we can call up that object and ask it to do something. We can either access its attributes, or we can access its methods. Just like we can send a letter to a house as we have its address, we can access an object using its reference.

 

object reference

 

 

 

Example: Declaring object references:

Here we have the ShirtTest class that we used in the previous module to create a Shirt object and then access it. In the following sections we will take a detailed look at the creation of myShirt object refernce variable and the creation of the Shirt object and how these two are tied together and how the myShirt object reference variable is used to access the Shirt object.  

 

 ShirtTest class

 

 

Declaring object reference variables: Read more…

Advertisements

Analyze a problem & design a solution in Java

November 6, 2009 4 comments

  

Module 2 – Analyze a problem & design a solution.

 

Objective:

Analyzing a problem & designing a solution using object oriented concepts:

1. Analyse a problem using object oriented analysis
2. Design classes from which objects will be created

 

1. Analyze a problem using object oriented analysis:

In this process, the first step is to understand your domain & the domain will probably be the business you are trying to solve the pblm for, or the area to create new product.

 Case study:

A company called Direct Clothing  sells shirts from thier catalog.  We have to develop a product for this company for the same catalog. So initially we have to understand few points about thier shirts
ex:

  • Each shirt has an item identity(ID) – bar code
  • One or more colors – blue, green etc
  • One or more sizes
  • Have description – type of material, style etc
  • Price
  • Direct Clothing accepts cheques & credit card payments.

 

11. case study

 

 

The current system:

During analysis stage, you also have to learn about the current system if there is one. Currently, say there are 2 ways in which a customer can place thier order with Direct Clothing

  • Call customer care over phone and place the order.
  • Mail or Fax an order form to place the order.

 

12. current system

 

The proposed system: Read more…