Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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 Applications require everything emanate from a CLASS. zWe will code examine several Java applications. We will also discuss appropriate coding style and naming conventions

2 2 zGOALS... zTo identify ALL of the main parts of a Java Application, Syntax Errors zTo code simple applications using the proper Syntax, Style and naming Conventions zTo get comfortable with Code Warrior, Java API Document

3 3 zBreakdown of the Java Application: zUse our HelloWorld and other applications handed out as a reference zHINT: write comments on these handouts !!!

4 4 zComments // for a line of comment /* for multiple lines */

5 5 Java Documentation Comments: zDoc comment --- special type of JAVA comment zA multi line comment starts with /** (insead of /*) & Ends with */

6 6 Java Documentation Comments: zThese comments can be turned into online HTML documentation by the javadoc program EXAMPLE: /** * @ author David Farrell * @version 1.0

7 7 Public Static Void Main: zThe main entry point in a Java Application zThe first code to execute zActually, it is a wrapper for the Java Class that is to execute first zThe classname that has PSVM MUST match the filename

8 8 Standard Output Stream: zUsed to send output to the console System.out.println(“Hello World”); zStandard Java API method from the Java.Lang.System class

9 9 Standard Output Stream: zStatic 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

10 10 Class: The initial class as a wrapper for the entry point to the java application (SPVM) public class HelloWorld {

11 11 Class Constructor: The method that gets executed when an instance of a class is created Public class Addition { public Addition( ) // empty constructor { } static public void main (String args[ ] ) { new Addition( ) ; // calls the class constructor }

12 12 Import: zBrings in the prewritten classes for us to use / leverage in our application xvital OO benefit provides conformity & reusability Like Adding a component in Visual Basic

13 13 Import: import javax.swing.JOptionPane; zWe now have Access to all the methods of JOptionPane

14 14 Import: zOPEN UP JAVA DOC & GO TO javax swing JOptionPane & look at the showInputDialog method

15 15 Semi-Colon: zEnd of Code segment identified by a semi-colon ;

16 16 CW debugger (again): zOpen up the various projects created and use the debugger and zMake changes to cause syntax / compile errors zLook at how these messages are displayed zSystem or Exception Errors ( try & catch )

17 17 Syntax and Style: zJava is case sensitive zRedundant whitespace is ignored zUse blank lines, indenting for better reading of the code

18 18 Syntax and Style: zCompiler catches most syntax errors, but not logic errors “bugs” zJava statements and declarations usually end in a semi-colon

19 19 Syntax and Style: zAll Java reserved words are in Lower Case (see handout) booleancharintnull newtruefalse publicprivateprotected staticclass import iftrycatch zReserved words must be spelled exactly.

20 20 Syntax and Style: zStart ALL class names with a capitol letter (use names that are nouns) String StringBuffer JOptionPane System

21 21 Syntax and Style: zInstances of objects start in Lower Case String myString String firstNumber

22 22 Syntax and Style: zStart all method names with Lower Case, then Upper Case remaining words (first word as a verb – action) println( ) parseInt( ) insert( ) insertObject( )

23 23 Syntax and Style: zStart all names of variables with a Lower Case letter and subsequent words start w/ Upper Case int number; zCan’t start with a digit. zUse self-explanatory names and follow a naming convention

24 24 Syntax and Style: zUse all Upper Case for constants final int MAXPOINTS = 200;

25 25 Syntax and Style: zLine up the brackets { } zBrackets identify the beginning of A class A method A code block (like if and endif)

26 26 zIndent 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 ); }

27 27 zIndent 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 ); } } zWhich one is easier to debug !!!

28 28 zProject: zCode the 4 projects directly from the handouts zBe able to identify all of the parts of the program that we covered

29 29 zProject: zUse the debugger and make coding changes, once the program works as intended, see and fix the compile errors zImplement the System methods exit gc & sleep in one or more of these programs

30 30 zProject: zView the JAVA Doc and look at some of the methods and classes we used

31 31 TEST IS THE DAY AFTER THE PROJECT IS DUE !!!


Download ppt "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."

Similar presentations


Ads by Google