i.
Java,
Machine Code, Byte Code, JVM
i. Portability - -trade off!
ii. Ease of programming
iii. Important/useful language
iv. Java class library
v. Error Reporting
i. Source.java
ii. Source.class
i. Semi colons – statements
ii. Curly brackets – blocks of code. More later
i. Strings – made of characters
ii. Numbers – math operations
i. Java is case sensitive – HelloWorld is not the same as helloworld
i. Syntax error – cannot compile due to misspelling etc.
1. System.ou.println(“Hello World”);
ii. Compiler error – cannot compile because compiler is confused
1. System.out.println(1,2,3); Can’t find method
a. We’ll examine this one more later
2. System.out.printLn(“Hello World”);
3. System.out.println(Hello World!);
i. Logical error
1. System.out.println(“Hello Word!”);
ii. Run-time exception
1. System.out.println(1/0);
i. Not ok:
System.out.println(“Hello World”)
ii. Ok:
System.out
.println(1+2+"3"+
4+5);
iii. Exception :
System.out.print
ln(1+2+"3"+
4+5);
import javax.swing.JOptionPane;
public class NameAndAge
{
public static void main(String[] args)
{
String name=JOptionPane.showInputDialog("What is your name?");
int age=Integer.parseInt(JOptionPane.showInputDialog("What is your age?"));
System.out.println("Hello " + name);
System.out.println("You are " + age + " years old");
System.exit(0);
}
}
i.
Declaration
1.
int number;
2. Sets aside a spot in memory for a variable
3.
Type
a.
int, double,
etc…
ii. Initialization
1. number=10;
2. Assigns a value to a variable
3. Don’t need to declare value first, though
i. Variables for team score, point values for different ways to score, etc