13
CSE 1341 Honors Note Set 02 Professor Mark Fontenot Southern Methodist University

CSE 1341 Honors

Embed Size (px)

DESCRIPTION

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) - PowerPoint PPT Presentation

Citation preview

Page 1: CSE 1341 Honors

CSE 1341 HonorsNote Set 02

Professor Mark FontenotSouthern Methodist University

Page 2: CSE 1341 Honors

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 modificationThink: 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.

Page 3: CSE 1341 Honors

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)

Compiler/Interprete

r

Object Code

(What the Computer

understands)

Page 4: CSE 1341 Honors

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 Compil

er

Java Byte Code

Interpreter

Running Progra

m

Page 5: CSE 1341 Honors

What’s a program?A sequence of instructions to solve a problem.

Usually have the following components: Input

From the user, From another programFrom a sensor…

Processing Does something useful with the data

OutputDisplays something, sends commands to

somewhere else (like a robot), etc…

Page 6: CSE 1341 Honors

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

Page 7: CSE 1341 Honors

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 ErrorsErrors 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

Page 8: CSE 1341 Honors

DebuggingYou’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

Page 9: CSE 1341 Honors

Breakout 1

Page 10: CSE 1341 Honors

Looking at Java

public class Hello {

//Say Hello To The World

public static void main (String [] args) {

System.out.println(“Hello World”);

}

}

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

Method

Output Statement/Print Statement

Page 11: CSE 1341 Honors

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 line character 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”);

Page 12: CSE 1341 Honors

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”);

Page 13: CSE 1341 Honors

Breakout 2