170 likes | 182 Views
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
E N D
Week 2 Intro to Java Application MSIS 655Advanced Business Applications Programming 2.1
Assignment 1: Addition • Addition.java
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
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
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 (- -;)
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
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
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
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
Arithmetic Operation • Addition + • Subtraction - • Multiplication * • Division / • Modulus % (r % s = r mod s)
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)
Equality and Relational Operators • == equal • != not equal • > • < • >= • <=
Lab activities (Week 2) • Coding Assignment 2 • Exercises (pp. 79-80)2:24, 2:25, 2:27, 2:30, 2:31