130 likes | 212 Views
CSE 1341 Honors. Note Set 02 Professor Mark Fontenot Southern Methodist University. What is Java?. “High-Level Programming Language” Allows the programmer to write instructions in something similar to English (loosely speaking) Portable (sometimes)
E N D
CSE 1341 Honors Note Set 02 Professor Mark Fontenot Southern Methodist University
What is Java? • “High-Level Programming Language” • Allows the programmer to write instructions in something similar to English (loosely speaking) • Portable (sometimes) • Can take code and move from one machine type to another with little or no modification • Think: Linux to PC • Opposite of HL Language = Low Level Language • Commands are specific to the hardware/processor • Hard to read/Hard to write • The only thing a computer can really execute, though.
Getting from HL to LL… • Compiling and Interpreting • Both are means for turning HL instructions into LL instructions • Compiler and Interpreter are pieces of software that translate HL code to LL code Source Code (What the human writes) Object Code (What the Computer understands) Compiler/Interpreter
Java is (a little) special • Java uses both compiling and interpreting • Java compiler (command: javac) compiles Java source code to generic Byte Code • Java runtime/interpreter (command: java) translates byte code to machine code “on the fly” • New Acronym: JVM • Stands for Java Virtual Machine • Able to execute Java Byte Code Java Source Code Java Byte Code Running Program Java Compiler Interpreter
What’s a program? • A sequence of instructions to solve a problem. • Usually have the following components: • Input • From the user, • From another program • From a sensor… • Processing • Does something useful with the data • Output • Displays something, sends commands to somewhere else (like a robot), etc…
What’s a Program? • More Components of a Program • The ability to test conditions • if (x < 10) System.out.println(“X is too small”); • The ability to perform actions repeatedly • while (x < 20) {System.out.println(x);x++;} • That’s pretty much it….. All programs you use can be broken down to those 5 fundamental components
When Things Go Wrong… • Things will go wrong • Syntax Error • There are rules about Java (we’ll be learning them) • You must follow the rules or the compiler complains • Run-Time Errors • Errors that only come to light while running a program • i.e. user enters something wrong and the program doesn’t know how to respond • Logic Errors/Semantic Error • Compile, run, no error message, but produces wrong output. • Example: Adding 2 numbers when you intended to multiply
Debugging • You’re like a Java Detective • Look for clues about what the problem might be • Make inferences based on the way the program is improperly executing
Looking at Java Class Name: Name of file has to be name of class with extension .java Comment – note to others that read this code about what it does public class Hello { //Say Hello To The World public static void main (String [] args) { System.out.println(“Hello World”); } } Method Output Statement/ Print Statement
System.out.println() • println() is a function • It provides the functionality to print whatever is inside the () to the terminal (if possible). • Prints what is in the parentheses, then prints a new linecharacter so that the next thing that is printed will be on the next line. • Examples: • System.out.println(“Mark Fontenot”); • System.out.println(“3 + 4 = 7”);
System.out.print() • print() is a function (as well)… • like println(), but doesn’t go down to the next line after it prints • System.out.print(“hello “); • System.out.println(“world”); • System.out.println(”hello world”);