Presentation is loading. Please wait.

Presentation is loading. Please wait.

Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.

Similar presentations


Presentation on theme: "Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output."— Presentation transcript:

1 Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output expected? 3. design the classes - top down: What are the major subtasks for which - Classes exist that are appropriate? Classes exist that can be modified? New classes must be written? (Write algorithms where needed.) 4. implement the classes - write Java code from design 5. test and verify the program - desk check with examples from all cases of data, then run program to verify. 6. maintain / update the program

2 A Java application is a collection of classes. 1. An application (or client) class containing main() is required. This tells the reader and the JVM where to start execution. (The order in which all other classes and the methods in them are stored doesn’t matter.) 2. All other classes are supporting classes which do all the work. 3. Each class contains two types of members: data fields and methods. (methods contain the instructions to process the data as needed)

3 Overview Of A Class Definition private double sqMeter; public double toSqYards() { …} public void readSqMeters() { …} public void displayFabric() { …} } class header public class PieceOfFabric extends Simple GUI{ class name data declaration method definition Is this a client or support class? (Support - there is no main() method.

4 Sample Java Application public class HelloWorld { public static void main (String args[]){ System.out.println(“Hello World …”); } HelloWorld.java class namerequired for applications predefined methodpredefined class

5 Method Body {...}{...} public void readSquareMeters() name of method return typescope start of block end of block body / block Instructions to access, modify and/or return data.

6 Two types of Statements: 1.Declaration - tells the compiler the name (or identifier) of a variable ( a storage location ) the scope (private, protected or public) and the type of data it is permitted to store. private double sqMeters; scopetype name of identifier private - identifier is only accessible by methods in the class

7 Scope (Visibility Modifiers) Public - accessible to all clients desiring access. Classes are usually public and methods are often public, but not always, but data fields are usually not public. Private - prevents class’s clients from accessing variables directly, thus preventing data fields from being processed in any unpredictable way.

8 package is a group of related classes stored in directory of same name. if public, private, or protected is omitted, the variable (data field, methods, or class) is accessible ONLY by classes within the same package public class SomeClass {long x, y=10, z; //declare three longs at once } variables x, y, and z are accessible ONLY by classes within the same package because public, private, or protected is omitted (If no package is declared for a class, the Java compiler will put it in the default package - just keep all classes in the same folder.)

9 Importing a Package An import statement must appear at the top of a file to allow a package of classes defined elsewhere in storage to be used by the program. (If this is not done, each class used must be referenced by the long name: packageName.className) Example: import javax.swing.* ; (this allows use of classes in that package including, JOptionPane which has methods that create windows for user interface)

10 Extending a class A hierarchy of classes is created by this process, by which code can be reused easily. When a class is extended it is called the superclass (or parent) and the subclass in which the word extend appears in the heading has direct access to its members, while being able to declare its own.

11 Creating An Object / Instantiation instantiation - creating an object from a class objects are created from classes Shoe class {…} Shoe object class definition

12 Creating An Object PieceOfFabric aPiece = new PieceOfFabric(); reserve word new allocates memory for the object (aPiece) aPiece - has the address of the object created on the right hand side of the assignment statement memory allocated has the values of the object’s instance variables data typeidentifierconstructor


Download ppt "Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output."

Similar presentations


Ads by Google