1 / 12

Creating Java Applications

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 -

adamdaniel
Download Presentation

Creating Java Applications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 class name class header public class PieceOfFabric extends Simple GUI{ data declaration private double sqMeter; public double toSqYards() { …} public void readSqMeters() { …} public void displayFabric() { …} } method definition Is this a client or support class? (Support - there is no main() method.

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

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

  6. name of identifier scope type private double sqMeters; • private - identifier is only accessible by methods in the class 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.

  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. (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.) 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 • 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

  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 object class definition Shoe class {…}

  12. Creating An Object data type identifier reserve word constructor PieceOfFabric aPiece = new PieceOfFabric(); • 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

More Related