1 / 17

MSIS 6 55 Advanced Business Applications Programming

Week 2 Intro to Java Application. MSIS 6 55 Advanced Business Applications Programming. 2. 1. Assignment 1: Addition. Addition.java. A few tips for Java programming. Comments

wilmot
Download Presentation

MSIS 6 55 Advanced Business Applications Programming

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. Week 2 Intro to Java Application MSIS 655Advanced Business Applications Programming 2.1

  2. Assignment 1: Addition • Addition.java

  3. A few tips for Java programming • Comments • Every program should begin with a comment that explains the purpose of the program, the author and the date and time the program was last modified. • Blank line • Makes program more readable • Blank lines, spaces, and tabs are white-space characters • Ignored by compiler

  4. Java Identifier • Java identifier (name for classes, variables, or methods) • Series of characters consisting of letters, digits, underscores ( _ ) and dollar signs ( $ ) • Does not begin with a digit, has no spaces • Examples: Welcome1, $value, _value, button7 • 7button is invalid • Java is case sensitive (capitalization matters) • a1 and A1 are different

  5. Modifying the first program:Another Adding Integers

  6. class Scanner (new to v. 5.0) • Imported to the package to be used with the program • Scanner variable (input) is initialized, and used to read data typed by the user at the keyboard (without converting String to integer). • Some labs are not upgraded to 5.0 (- -;)

  7. 3 import java.util.Scanner; // program uses class Scanner import • import declarations • Used by compiler to identify and locate classes used in Java programs • All import declarations must appear before the first class declaration in the file. • Tells compiler to load class Scanner from java.util package

  8. objects System.in, System.out, System.err • Included in the package java.lang. • Always imported by compiler. • System.in: enables program to input bytes from keyboard. • System.out: enables program to output data to screen • System.err: enables program to output error message to screen

  9. Method “print()” • print(argument) – print argument on a line and stop at the end of argument • println(argument) – print argument on a line and go to the beginning of next line • printf(argument with %_, reference) – formatted printing • %d: digit = short, int, long • %f: floating point = float, double • %s: String = String

  10. Escape Caracters • Escape characters • Backslash ( \) • Indicates special characters be output • Newline characters (\n) • Interpreted as “special characters” by methods System.out.print and System.out.println, etc. • Indicates cursor should be at the beginning of the next line

  11. Fig. 2.5 | Some common escape sequences.

  12. Arithmetic Operation • Addition + • Subtraction - • Multiplication * • Division / • Modulus % (r % s = r mod s)

  13. if statement • Condition • Expression can be either true or false • if statement • Simple version in this section, more detail later • If a condition is true, then the body of the if statement executed • Control always resumes after the if statement • Conditions in if statements can be formed using equality or relational operators (next slide)

  14. Equality and Relational Operators • == equal • != not equal • > • < • >= • <=

  15. Lab activities (Week 2) • Coding Assignment 2 • Exercises (pp. 79-80)2:24, 2:25, 2:27, 2:30, 2:31

More Related