Organized by Java: How to Program chapter.
Java Byte Code (JBC) is interpreted/translated by the Java Virtual Machine (JVM).
Design patterns are "proven architectures for constructing flexible and maintainable object-oriented software". They:
Similar to JHTP p 34 without comments
public class Welcome1 {
public static void main(String[] args) {
System.out.println("Welcome Earthlings");
}
}
// Similar to JHTP p 43 without comments. import javax.swing.JOptionPane; public class Welcome2 { public static void main(String[] args) { JOptionPane.showMessageDialog(null, "Welcome Earthlings"); System.exit(0); } }
I don't expect you to know the answers to these - this time!
import.System.exit(0) necessary here, but not in previous example?System.exit(0)?null in this example?JOptionPane a class or an object?
// Similar to JHTP p 47 without comments.
import javax.swing.JOptionPane;
public class Add2 {
public static void main(String[] args) {
String s1, s2;
int n1, n2;
s1 = JOptionPane.showInputDialog(null, "Enter 1st number");
n1 = Integer.parseInt(s1);
s2 = JOptionPane.showInputDialog(null, "Enter 2nd number");
n2 = Integer.parseInt(s2);
JOptionPane.showMessageDialog(null, "Sum is " + (n1 + n2));
System.exit(0);
}
}
(n1 + n2) necessary?Basic arithmetic operators: +, -, *, /, %
Precedence: *, /, and % are done before + or -.
If either operand of + is a string, the other operand is converted to string and the two strings are concatenated.
Comparison operators: <, <=, ==, !=, >=, >
Precedence: All are lower precedence than the arithmetic operators.
<, <=, >=, > are higher than ==, !=,
but there is no apparent reason for this except compatibility with C and C++.
The result of any comparison is boolean true or false.
&&, ||): They do not
need to evaluate both operands when result is known.
Best choice most of the time.
&&, & - true only if both operands are true.||, | - true if either of the operands is true.! - true if operand is false, false if operand is true.^ - true if the operands are different, false if they are the same.