1 / 18

COP 3331 Object Oriented Analysis and Design

COP 3331 Object Oriented Analysis and Design. Java Part I. Java Part I. // First Java Program // HelloWorld.java Public class HelloWorld { public static void main (String args[]) { System.out.println(“Hello World!”); } }. Java Part I.

Download Presentation

COP 3331 Object Oriented Analysis and Design

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. COP 3331Object Oriented Analysis and Design Java Part I Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  2. Java Part I // First Java Program // HelloWorld.java Public class HelloWorld { public static void main (String args[]) { System.out.println(“Hello World!”); } } Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  3. Java Part I The following compile sequence occurs in Unix on Diablo. • gaitrosd@diablo:~/java>javac HelloWorld.java • gaitrosd@diablo:~/java>java HelloWorld • Hello World! Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  4. Java Part I Primary Java Program Files Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  5. Java Part I • General Java points to remember: • Java is case sensitive. • Use ; (semicolon) to terminate lines of code. • Use { } (curly braces) to indicate blocks of code for classes, methods, if statements, and loops. • Use spaces for indentation to make your code more readable. Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  6. Java Part I Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  7. Java Part I • Memory variables: Storage space declared inside the computer on memory is allocated through memory variables and constants. • Java is strongly typed which means that memory variables can only hold their declared type of data. • There are two types of data catetories: • Simple types. • Object types. Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  8. Java Part I Simple Types Simple data types are not based on any other type. These sizes do not vary from machine to machine. All numeric types are signed except character. Java is case sensitive. Names of simple data types Are in lower case as shown. Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  9. Java Part I Declaring Variables Format: data_typevariable_name; data_type variable_name =value; Example: int j; // integer char opt; // character short I; // short integer long L; // long integer float F; // real number double D; // 64 bit real number boolean ok; // True/False int I,j,k,l; char Men = “A”; Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  10. Java Part I Arithmetic Operators Note: There is not operator for exponent. You must use the Math.pow() function for this task. Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  11. Java Part I Comparison and logical Operators On the short circuit operators, the next comparison is not accomplished if it does not affect the outcome. Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  12. Java Part I Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  13. Java Part I Conditional Execution if(condition) statement; if(condition) { statement1; statement 2; statemetn 3; etc; } Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  14. Java Part I if(condition) { statement1; statement2; } else { statement1; statement2; } Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  15. Java Part I Switch Statements switch (expression) { case value1: statements; case value2: statements; . . . default: statements; } switch (input_char) { case ‘y’: System.out.print(“Entered y”); case ‘n’: System.out.print(“Entered n”); default: System.out.print(“Don’t know”); } Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  16. Java Part I Loops for (initialize; condition; increment) { statements; statements; } example: for (i=1; i<100; i++) { System.out.print(i); } Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  17. Java Part I while (condition) { statements; statements; } while (J < 100) { { J = J + 1; System.out.print(J); } Reference Learning Java DDC publishing Herst, Yamauchi, Adler

  18. Java Part I Command Line Arguments: In all Java applications, the main() function accepts an argument, an array of strings called args[]; This array contains command line arguments. For instance, if you entered the following on the HelloWorld program: java HelloWorld Arg1 Arg2 “Hello Again” The args.length would equal three (3). and the contents would be: args[0] -> “Arg1” args[1] -> “Arg2” args[2] -> “Hello Again” Reference Learning Java DDC publishing Herst, Yamauchi, Adler

More Related