How to Add and Subtract Unlike Denominators Part 1: Addition with Unlike Denominators.
1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN...
-
Upload
andrew-stanley -
Category
Documents
-
view
219 -
download
0
description
Transcript of 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN...
![Page 1: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/1.jpg)
1
The JAVA ApplicationJava Applications are similar to C++
programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java Applications require everything emanate from a CLASS.
We will code examine several Java applications. We will also discuss appropriate coding style and naming conventions
![Page 2: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/2.jpg)
2
GOALS...
To identify ALL of the main parts of a Java Application, Syntax Errors
To code simple applications using the proper Syntax, Style and naming Conventions
To get comfortable with Code Warrior, Java API Document
![Page 3: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/3.jpg)
3
Breakdown of the Java Application:
Use our HelloWorld and other applications handed out as a reference
HINT: write comments on these handouts !!!
![Page 4: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/4.jpg)
4
Comments
// for a line of comment
/* for multiple lines */
![Page 5: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/5.jpg)
5
Java Documentation Comments:
Doc comment --- special type of JAVA comment
A multi line comment starts with /** (insead of /*) & Ends with */
![Page 6: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/6.jpg)
6
Java Documentation Comments:
These comments can be turned into online HTML documentation by the javadoc program
EXAMPLE:/**
* @ author David Farrell* @version 1.0
![Page 7: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/7.jpg)
7
Public Static Void Main:
The main entry point in a Java Application
The first code to execute
Actually, it is a wrapper for the Java Class that is to execute first
The classname that has PSVM MUST match the filename
![Page 8: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/8.jpg)
8
Standard Output Stream:
Used to send output to the console
System.out.println(“Hello World”);
Standard Java API method from the Java.Lang.System class
![Page 9: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/9.jpg)
9
Standard Output Stream:
Static Method (does not require instance of System class)
OPEN UP JAVA DOC AND GO TO java Lang System and look at the out exit gc & sleep methods
![Page 10: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/10.jpg)
10
Class:
The initial class as a wrapper for the entry point to the java application (SPVM)
public class HelloWorld{
![Page 11: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/11.jpg)
11
Class Constructor: The method that gets executed when an instance of a class is createdPublic class Addition{ public Addition( ) // empty constructor { }
static public void main (String args[ ] ) { new Addition( ) ; // calls the class constructor }
}
![Page 12: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/12.jpg)
12
Import:
Brings in the prewritten classes for us to use / leverage in our application
vital OO benefit•provides conformity & reusability
•Like Adding a component in Visual Basic
![Page 13: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/13.jpg)
13
Import:
import javax.swing.JOptionPane;
We now have Access to all the methods of JOptionPane
![Page 14: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/14.jpg)
14
Import:
OPEN UP JAVA DOC & GO TO javax swing JOptionPane
& look at the showInputDialog
method
![Page 15: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/15.jpg)
15
Semi-Colon:
End of Code segment identified by a semi-colon ;
![Page 16: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/16.jpg)
16
CW debugger (again):
Open up the various projects created and use the debugger and
Make changes to cause syntax / compile errors
Look at how these messages are displayed
System or Exception Errors ( try & catch )
![Page 17: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/17.jpg)
17
Syntax and Style:
Java is case sensitive
Redundant whitespace is ignored
Use blank lines, indenting for better reading of the code
![Page 18: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/18.jpg)
18
Syntax and Style:
Compiler catches most syntax errors, but not logic errors “bugs”
Java statements and declarations usually end in a semi-colon
![Page 19: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/19.jpg)
19
Syntax and Style:All Java reserved words are in Lower
Case (see handout)
boolean charint nullnew true falsepublic private protectedstatic class importif try catch
Reserved words must be spelled exactly.
![Page 20: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/20.jpg)
20
Syntax and Style:
Start ALL class names with a capitol letter (use names that are nouns)
StringStringBufferJOptionPaneSystem
![Page 21: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/21.jpg)
21
Syntax and Style:
Instances of objects start in Lower Case
String myStringString firstNumber
![Page 22: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/22.jpg)
22
Syntax and Style:
Start all method names with Lower Case, then Upper Case remaining words (first word as a verb – action)println( )parseInt( )insert( )insertObject( )
![Page 23: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/23.jpg)
23
Syntax and Style:
Start all names of variables with a Lower Case letter and subsequent words start w/ Upper Case
int number;Can’t start with a digit. Use self-explanatory names and
follow a naming convention
![Page 24: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/24.jpg)
24
Syntax and Style:
Use all Upper Case for constants
final int MAXPOINTS = 200;
![Page 25: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/25.jpg)
25
Syntax and Style:
Line up the brackets { }
Brackets identify the beginning of A classA methodA code block (like if and endif)
![Page 26: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/26.jpg)
26
Indent the Correct way:public class Sample{ public static void main(String[] args) { int anumber = 23; for(int x=0; x < 10; x++)
{ anumber += x;}
System.out.println( anumber ); }}
![Page 27: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/27.jpg)
27
Indent the Wrong way:
public class Sample {public static void main(String[] args) {int anumber = 23; for(int x=0; x < 10; x++){ anumber += x; } System.out.println( anumber ); } }
Which one is easier to debug !!!
![Page 28: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/28.jpg)
28
Project:
Code the 4 projects directly from the handouts
Be able to identify all of the parts of the program that we covered
![Page 29: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/29.jpg)
29
Project:
Use the debugger and make coding changes , once the program works as intended, see and fix the compile errors
Implement the System methods exit gc & sleep in one or more of these programs
![Page 30: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/30.jpg)
30
Project:
View the JAVA Doc and look at some of the methods and classes we used
![Page 31: 1 The JAVA Application zJava Applications are similar to C++ programs in that they require a MAIN entry point. However, unlike C++ or Visual Basic, Java.](https://reader035.fdocuments.net/reader035/viewer/2022062905/5a4d1acc7f8b9ab05996fb82/html5/thumbnails/31.jpg)
31
TEST IS THE DAY AFTER THE PROJECT IS
DUE !!!