Introduction Correct program design makes the complexity of today's program requirements possible. The average student thinks that any program over 1000.

Slides:



Advertisements
Similar presentations
Introduction to Eclipse. Start Eclipse Click and then click Eclipse from the menu: Or open a shell and type eclipse after the prompt.
Advertisements

Programmer-defined classes Part 2. Topics Returning objects from methods The this keyword Overloading methods Class methods Packaging classes Javadoc.
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
1 eclipse Tips. 2 What is eclipse? Eclipse is a popular IDE (Integrated Development Environment) that we will use to create, compile, execute, and test.
Chapter 10—Creating Presentations
 2005 Pearson Education, Inc. All rights reserved Introduction.
 It is possible to declare names for object references and not assign object references to them.  Such names literally refer to nothing at all.  It.
Georgia Institute of Technology DrJava Appendix A Barb Ericson Georgia Institute of Technology May 2006.
Chapter 1 These slides for CSE 110 Sections are based in part on the textbook-authors’ slides, which are copyright by the authors. The authors state that.
SUNY Morrisville-Norwich Campus- Week 7 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
How to Create a Java program CS115 Fall George Koutsogiannakis.
XP New Perspectives on Microsoft Office Excel 2003, Second Edition- Tutorial 11 1 Microsoft Office Excel 2003 Tutorial 11 – Importing Data Into Excel.
Computer Science A 1: 3/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
With Alex Conger – President of Webmajik.com FrontPage 2002 Level I (Intro & Training) FrontPage 2002 Level I (Intro & Training)
Working with SharePoint Document Libraries. What are document libraries? Document libraries are collections of files that you can share with team members.
Editing Java programs with the BlueJ IDE. Working environments to develop (= write) programs There are 2 ways to develop (write) computer programs: 1.Using.
Java: Chapter 1 Computer Systems Computer Programming II Aug
HBar OR Reader Documentation A copy of the PowerPoint Viewer is shipped with the HBar OR Reader on the HBar Official Records [OR] CD. The PowerPoint Viewer.
1 eclipse Tips. 2 What is eclipse? Eclipse is a popular IDE (Integrated Development Environment) that we will use to create, compile, execute, and test.
Prepared by Uzma Hashmi Instructor Information Uzma Hashmi Office: B# 7/ R# address: Group Addresses Post message:
11 Getting Started with C# Chapter Objectives You will be able to: 1. Say in general terms how C# differs from C. 2. Create, compile, and run a.
Database Applications – Microsoft Access Lesson 9 Designing Special Queries.
Create Database Tables
Using Eclipse. What is Eclipse? The Eclipse Platform is an open source IDE (Integrated Development Environment), created by IBM for developing Java programs.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
When you start Photo Story the title screen gives you three options. The following slides will illustrate the directions when “Begin a new story” has been.
Mail merge I: Use mail merge for mass mailings Perform a complete mail merge Now you’ll walk through the process of performing a mail merge by using the.
ACM/JETT Workshop - August 4-5, Guidelines For Using BlueJ.
1 Chapter 1 Introduction to Java. 2 History of Java Java Originally for _________________________ devices Then used for creating Web pages with __________________________.
JCreator CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University.
Intro and Review Welcome to Java. Introduction Java application programming Use tools from the JDK to compile and run programs. Videos at
CPSC1301 Computer Science 1 Overview of Dr. Java.
Program Design and Coding
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Microsoft Visual Basic 2010 CHAPTER THREE Program Design and Coding.
First Data Structure Definition A data structure is a data type whose components are smaller data structures and/or simple data types.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files.
CHAPTER 1 INTRODUCTION. CHAPTER GOALS To understand the activity of programming To understand the activity of programming To learn about the architecture.
Hello World in the Forte IDE An introduction to the Forte IDE (integrated development environment) writing the classic “Hello World” program in Java.
Working with arrays (we will use an array of double as example)
Using Microsoft Visual Studio 2005 Original by Suma Rao Revised by John G. McMahon ( 9/6/2008 )
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
11/25/2015Slide 1 Scripts are short programs that repeat sequences of SPSS commands. SPSS includes a computer language called Sax Basic for the creation.
An Introduction to Designing, Executing and Sharing Workflows with Taverna Katy Wolstencroft myGrid University of Manchester IMPACT/Taverna Hackathon 2011.
Using This PowerPoint This PowerPoint presentation assumes your Computer Science teacher has provided you with the InstallingJava folder, which contains.
Chapter 1 Introduction. Chapter Goals To understand the activity of programming To learn about the architecture of computers To learn about machine code.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
Chapter 9 Separate Compilation and Namespaces. Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 2 Overview Separate Compilation (9.1)
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation and Namespaces.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Separate Compilation and Namespaces.
Introduction to Eclipse Programming with an Integrated Development Environment.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Lecture Set 2 Part A: Creating an Application with Visual Studio – Solutions, Projects, Files 8/10/ :35 PM.
Access Module Implementing a Database with Microsoft Access A Great Module on Your CD.
1 Development Environments AUBG, COS dept Lecture Title: Dev Env: NetBeans (Extract from Syllabus) Reference:
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
1 Using an Integrated Development Environment. Integrated Development Environments An Integrated Development Environment, or IDE, permits you to edit,
Perform a complete mail merge Lesson 14 By the end of this lesson you will be able to complete the following: Use the Mail Merge Wizard to perform a basic.
June 17, 2009 Office 2007 Tips & Tricks.
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Exposure Java 2013 APCS Edition
Appendix A Barb Ericson Georgia Institute of Technology May 2006
Tutorial for using Case It for bioinformatics analyses
Exploring Microsoft® Access® 2016 Series Editor Mary Anne Poatsy
Section 8.7 The Consequences of Scope.
Introduction to javadoc
Running a Java Program using Blue Jay.
Workshop for Programming And Systems Management Teachers
How to Run a Java Program
Presentation transcript:

Introduction Correct program design makes the complexity of today's program requirements possible. The average student thinks that any program over 1000 lines in length is a large program. Yet a typical video game created in the late Nineties had programs that exceed 500,000 lines of programming. These video games are quite small compared to application programs like CAD and many other popular application programs.

Chapter 15 Programs The organization of the program examples is a little different in this chapter than it has been in previous chapters. Each program example has its own folder. The main driver program still follows the established convention by naming the programs Java1501.java, Java1502.java, etc., but folders are used to keep multiple files contained in the same location. This is especially important, because there will frequently be subtle differences introduced in files that are almost identical.

Modular Programming Program development requires that large programs are divided into smaller program modules to be manageable. This is the principle of divide and conquer.

// Java1501A.java // This program places all 10 required task into a single program module. public class Java1501A { public static void main(String args[]) { System.out.println("Java1501A.java\n"); System.out.println("Task 1\n"); System.out.println("Task 2\n"); System.out.println("Task 3\n"); System.out.println("Task 4\n"); System.out.println("Task 5\n"); System.out.println("Task 6\n"); System.out.println("Task 7\n"); System.out.println("Task 8\n"); System.out.println("Task 9\n"); System.out.println("Task 10\n"); System.out.println(); } Java1501A.java Output Java1501A.java Task 1 Task 2 Task 3 Task 4 Task 5 Task 6 Task 7 Task 8 Task 9 Task 10

// Java1501B.java // This program creates ten separate modules for each required task. public class Java1501B { public static void main(String args[]) { System.out.println("Java1501B.java\n"); Task1 t1 = new Task1(); Task2 t2 = new Task2(); Task3 t3 = new Task3(); Task4 t4 = new Task4(); Task5 t5 = new Task5(); Task6 t6 = new Task6(); Task7 t7 = new Task7(); Task8 t8 = new Task8(); Task9 t9 = new Task9(); Task10 t10 = new Task10(); System.out.println(); } class Task1 { public Task1() { System.out.println("Task 1\n"); } Java1501B.java Output Java1501B.java Task 1 Task 2 Task 3 Task 4 Task 5 Task 6 Task 7 Task 8 Task 9 Task 10 The other 9 tasks don’t fit here, but you should get the idea.

Simple Projects Many program languages, or rather the Integrated Development Environment (IDE) of many program languages require the creation of a project to compile any program. JCreator gives the programmer the option to work with or without a project. Keep in mind that the use of projects are IDE dependent. Why do we need projects? Imagine an Air-Traffic-Control Program. The program is 4,000,000 lines in length. Suppose just one module, which might be 1000 lines long needs to be edited. Now the entire 4,000,000 line long program must be compiled before it can be executed. This can take hours (even days!) With projects each separate module is compiled independently. If one module is changed, only that module needs to be recompiled. The project manager keeps track of all of the modules and determines which need recompiling, and which do not.

// Java1502.java // This program is a classic example of a program that does not require // the creation of a project. It is still possible to create a project if it is // desirable or your IDE requires the creation of a project for every // program. public class Java1502 { public static void main(String args[]) { System.out.println("Hi, I am a one-line program"); System.out.println(); } Java1502.java Output Hi, I am a one-line program

Multiple Class Warning Each class should have its own file. It is possible to compile multiple classes that are placed into a single file, but it is not very good program design.

// Java1503.java // This program uses multiple classes, all inside one file. This is not // considered good program design. There should be one file for each class. public class Java1503 { public static void main(String args[]) { System.out.println("\nJava1503.java\n"); Widget w = new Widget(10); System.out.println("Starting with " + w.getWidgets() + " widgets"); w.setWidgets(30); System.out.println("Ending with " + w.getWidgets() + " widgets"); System.out.println(); Aardvark a = new Aardvark(20); System.out.println("Starting with " + a.getAardvarks() + " aardvarks"); a.setAardvarks(50); System.out.println("Ending with " + a.getAardvarks() + " aardvarks"); System.out.println(); Mango m = new Mango(25); System.out.println("Starting with " + m.getMangos() + " mangos"); m.setMangos(75); System.out.println("Ending with " + m.getMangos() + " mangos"); System.out.println(); } // The other classes are shown on the next slide.

// Java1503.java continued class Widget { private int numWidgets; public Widget(int w){ numWidgets = w; } public int getWidgets() { return numWidgets; } public void setWidgets(int w) { numWidgets = w; } } class Aardvark { private int numAardvarks; public Aardvark(int a) { numAardvarks = a; } public int getAardvarks() { return numAardvarks; } public void setAardvarks(int a) { numAardvarks = a; } } class Mango { private int numMangos; public Mango(int m) { numMangos = m; } public int getMangos() { return numMangos; } public void setMangos(int m) { numMangos = m; } } Java1503.java Output Java1503.java Starting with 10 widgets Ending with 30 widgets Starting with 20 aardvarks Ending with 50 aardvarks Starting with 25 mangos Ending with 75 mangos

// Java1504.java // This program is now divided up into four separate files for four separate classes. Provided all // necessary files are placed in the same directory, the "file-compile" method can still work. public class Java1504 { public static void main(String args[]) { System.out.println("\nJava1504.java\n"); Widget w = new Widget(10); System.out.println("Starting with " + w.getWidgets() + " widgets"); w.setWidgets(30); System.out.println("Ending with " + w.getWidgets() + " widgets"); System.out.println(); Aardvark a = new Aardvark(20); System.out.println("Starting with " + a.getAardvarks() + " aardvarks"); a.setAardvarks(50); System.out.println("Ending with " + a.getAardvarks() + " aardvarks"); System.out.println(); Mango m = new Mango(25); System.out.println("Starting with " + m.getMangos() + " mangos"); m.setMangos(75); System.out.println("Ending with " + m.getMangos() + " mangos"); System.out.println(); } Java1504.java Output Java1504.java Starting with 10 widgets Ending with 30 widgets Starting with 20 aardvarks Ending with 50 aardvarks Starting with 25 mangos Ending with 75 mangos

// Widget.java // Goes with Java1504.java public class Widget { private int numWidgets; public Widget(int w) { numWidgets = w; } public int getWidgets() { return numWidgets; } public void setWidgets(int w) { numWidgets = w; } Java1504.java Output Java1504.java Starting with 10 widgets Ending with 30 widgets Starting with 20 aardvarks Ending with 50 aardvarks Starting with 25 mangos Ending with 75 mangos

// Aardvark.java // Goes with Java1504.java public class Aardvark { private int numAardvarks; public Aardvark(int a) { numAardvarks = a; } public int getAardvarks() { return numAardvarks; } public void setAardvarks(int a) { numAardvarks = a; } Java1504.java Output Java1504.java Starting with 10 widgets Ending with 30 widgets Starting with 20 aardvarks Ending with 50 aardvarks Starting with 25 mangos Ending with 75 mangos

// Mango.java // Goes with Java1504.java public class Mango { private int numMangos; public Mango(int m) { numMangos = m; } public int getMangos() { return numMangos; } public void setMangos(int m) { numMangos = m; } Java1504.java Output Java1504.java Starting with 10 widgets Ending with 30 widgets Starting with 20 aardvarks Ending with 50 aardvarks Starting with 25 mangos Ending with 75 mangos

Creating a Project – Step 1 Click Project followed by New Project.

Creating a Project – Step 2 Click on the Projects tab, if it is not already selected. Click Empty Project. In the Project name: window, type Project1505.

Creating a Project – Step 3 Click the... browse button next to the Location window. Click on the Java1505 folder. Click the OK button twice.

Creating a Project – Step 4 Click Project and Add Files.

Creating a Project – Step 5 Move up one folder by clicking the Up arrow. all four of the.java files. Click the Open button.

Creating a Project – Step 6 Notice the Project1505 in the Workspace window. Click the [+] in front of Project1505 to view the included files. Double-Click on any file to make it appear in the edit window.

Creating a Project – Step 7 Click on the Compile Project (not Compile File) button or F7. If all the files are correct, you will see Process completed.

Creating a Project – Step 8 Click the Execute Project (not Execute File) button or F5. The output window is identical to compiling/executing files.

Creating a Project – Step 9 Click File. Click Save Workspace, if you want to save this project. Click Close Workspace, if you want to close the project. NOTE: Not closing your project will mess up the student in the next class!

// Java1506.java // This program is once again identical to programs Java1504 and Java1505. // This time the class files are placed in different folders. // You cannot compile the program now without a project. public class Java1506 { public static void main(String args[]) { System.out.println("\nJava1506.java\n"); Widget w = new Widget(10); System.out.println("Starting with " + w.getWidgets() + " widgets"); w.setWidgets(30); System.out.println("Ending with " + w.getWidgets() + " widgets"); System.out.println(); Aardvark a = new Aardvark(20); System.out.println("Starting with " + a.getAardvarks() + " aardvarks"); a.setAardvarks(50); System.out.println("Ending with " + a.getAardvarks() + " aardvarks"); System.out.println(); Mango m = new Mango(25); System.out.println("Starting with " + m.getMangos() + " mangos"); m.setMangos(75); System.out.println("Ending with " + m.getMangos() + " mangos"); System.out.println(); }

Java1506.java:13: cannot resolve symbol symbol : class Widget location: class Java1506 Widget w = new Widget(10); ^ Java1506.java:13: cannot resolve symbol symbol : class Widget location: class Java1506 Widget w = new Widget(10); ^ Java1506.java:19: cannot resolve symbol symbol : class Aardvark location: class Java1506 Aardvark a = new Aardvark(20); ^ Java1506.java:19: cannot resolve symbol symbol : class Aardvark location: class Java1506 Aardvark a = new Aardvark(20); ^ Java1506.java:25: cannot resolve symbol symbol : class Mango location: class Java1506 Mango m = new Mango(25); ^ Java1506.java:25: cannot resolve symbol symbol : class Mango location: class Java1506 Mango m = new Mango(25); ^ 6 errors Java1506.java Output when trying to compile the file Java1506.java. Since these files are all in different folders, this cannot work without projects.

Java1506.java Output #2 This is the output you get when you create a project. You will need to browse to different folders to find all of the files.

Creating Simple Projects 1.Start a new project 2.Give the project a name. 3.Specify the location where all project information is stored. 4.Add all the files that will be used with the project. 5.Compile the project. 6.Execute the project. 7.Save the project.

Projects With jar Files Some clever programmers manage to compress a bunch of their classes into special Java Archive Files, or JAR files. Such files contain multiple classes and these files all end with.jar. Additional steps will be necessary to create projects that use.jar files. Once again realize that these steps are IDE dependent. The steps that follow will be those that are required for JCreator.

AP Exam Alert The Marine Biology Case Study (MBCS) will be tested on the AP Computer Science Examination. The MBCS is copyrighted by the College Board and Educational Testing Service. A wealth of information about the MBCS is available on AP Central, the official website of the College Board for AP Computer Science teachers.

Files Used by the MBCS BoundedEnv.java DarterFish.java Environment.java Fish.java mbsbb.jar mbsgui.jar MBSGUI1.java MBSGUI2.java MBSGUI3.java Simulation.java SlowFish.java UnboundedEnv.java

Compiling MBCS – Step 1 Click File. Click New. Click the Workspaces tab.

Compiling MBCS – Step 2 Type MBCS in the Workspace name window. Click the location browse button... and select Java1507.

Compiling MBCS – Step 3 Click Project, New Project and click Empty Project. Type MBCS1 in the Project name window. Repeat this process 2 more times using names MBCS2 & MBCS3.

New Project Alert A new projects defaults to Basic Java Application, which includes a main method that you did not create. Failure to select Empty Project results in executing a program with two different main methods, and potentially bizarre execution consequences.

Compiling MBCS – Step 4 Click Project, and Set Active Project. Select MBCS1. Click Project and Add Files. Navigate up two folder levels. Select all.java files, except MBSGUI2.java and MBSGUI3.java. Click the Open button. Click the + in front of MBCS1

Compiling MBCS – Step 5 Repeat Step 4 two more times. First, change the active project to MBCS2 and then add all the files except MBSGUI1.java and MBSGUI3.java. Second, change the active project to MBCS3 and then add all the files except MBSGUI1.java and MBSGUI2.java.

Compiling MBCS – Step 6 Try to compile the project. This should be possible based on your experience with projects performed by the previous exercise. You will find that Java is unhappy with an error window output shown below.

Compiling MBCS – Step 7 You must add the.jar files to the project before compiling is possible. Click Project and Project Settings. Click the Required Libraries tab. Click the New... button.

Compiling MBCS – Step 8 You must add the.jar files to the project before compiling is possible. Click Project and Project Settings. Click the Required Libraries tab. Click the New... button.

Compiling MBCS – Step 9 Navigate to the Java1507 folder. the two.jar files. Click the Open button and the OK button.

Compiling MBCS – Step 10 Place a Check mark in the box next to MBCSJars. You have created the library. The check associated it with your project.

Compiling MBCS – Step 11 Click the Compile button three times for each one of the three projects. Make sure to use Set Active Project to change between projects. All three projects should compile.

Compiling MBCS – Step 12 Make MBCS1 the active project and execute the project. Be prepared to wait a while for the execution. This a very large program and the computer needs to do lots of processing to get to this stage.

Compiling MBCS – Step 13 Your first reaction to the MBCS execution may be Now what? Click File followed by Create new environment...

Compiling MBCS – Step 14 The default fish environment is 10 rows by 10 columns. Keep the default environment by clicking the Create button.

Compiling MBCS – Step 15 Place 9 fish at the indicated locations Click on the cell and fish of random color will appear. If a specific fish color is desired you can click the Color button. Click the Run button to see the fish move. Executing the MBCS2 and MBCS3 projects are very similar. The difference is that MBCS2 has 2 types of fish and MBCS3 has 3.

Another Look at Comments You have also seen comments, which are statements that do not compile. One- line comments are created with // and multiple lines can be created with /* */. Folder 1508 contains three classes that use a combination of self-commenting identifiers and non-compiling comments.

Using Javadoc Javadoc is a special program that creates webpage-based documentation of your classes and their components along with your provided comments. There is a twist though; the comments need to be placed prior to the method or item being commented and you need to use double asterisks for your comments. In folder 1509 you will find the same Aardvark, Mango and Widget classes with the same comments using a slightly different format. It is a third style of commenting that is picked up by Javadoc. /** * This third style of comments uses a slash * and a double asterisk. **/

/** * Aardvark2.java * The Aardvark2 class stores the total number of aardvarks in any Aardvark2 object. * There is one constructor, one get method and one set method. * Goes with Java1509 folder **/ public class Aardvark2 { /** * numAardvark attribute store the total number of aardvarks. **/ private int numAardvarks; /** * Aardvark2 one-parameter constructor, which constructs an object and * initializes the numAardvarks attribute. **/ public Aardvark2(int a) { numAardvarks = a; } The other classes and methods use the new comments in the same way and will not be shown.

Using Javadoc – Step 1 Get to the Command or DOS prompt. Type CD C:\Java\ChapterProgs\Progs15\Java1509 (This may be different depending on the Java1509 folder location) You are now located at the 3 classes with special Javadoc comments.

Using Javadoc – Step 2 You need to create access to the Javadoc program with a path command. Type path C:\Java\bin

Using Javadoc – Step 3 Now you can use the Javadoc program to create the web page documents. Type Javadoc *.* You will see many.html created.