




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Hello.java:1: class, interface, or enum expected. Public class Hello {. ^. 1 error compiler output: 19. Names. You must give your program a name.
Typology: Slides
1 / 8
This page cannot be seen from the preview
Don't miss anything!





"To excel in Java, or any computer language, you want to build skill in both the "large" and "small". By "large" I mean the sweeping, strategic issues of algorithms, data structures, ... what we think of basically as a degree in Computer Science. You also need skill in the "small" -- 10 or 20 line methods built of loops, logic, strings, lists etc. to solve each piece of the larger problem. Working with students in my office hours, I see what an advantage it is for students who are practiced and quick with their method code. Skill with the method code allows you to concentrate on the larger parts of the problem. Or put another way, someone who struggles with the loops, logic, etc. does not have time for the larger issues."
2
this is done by feeding the instructions to the CPU
in this class we use Java
Computers are fast -8086K Processor on the order of 2 billion transistors (a switch that is on or off) performs tens of billions of operations per second Computers are simple They can only carry out a very limited set of instructions on the order of 100 or so depending on the computer's processor machine language instructions, aka instruction set architecture (ISA) Add, Branch, Jump, Get Data, Get Instruction, Store, (CS429) 5
"Preliminary Discussion of the Logical Design of an Electronic Computing Instrument"
program commands and data stored as sequences of bits in the computer's memory
6
mnemonics for machine language instructions .ORIG x LD R1, x AND R3, R3 # LD R4, R BRn x ADD R3, R3, R ADD R1, R1, # LD R4, R BRnzp x 7
public class Hello { public static void main(String[] args) { System.out.println("Hello, world!"); System.out.println(); System.out.println("This program produces"); System.out.println("four lines of output"); } } Its output: Hello, world! This program produces four lines of output console: Text box into which the program's output is printed. 13
public class
that contains a method named main, that contains the statements (commands) to be executed. class: a program statement: a command to be executed method: a named group of statements 14
15
Every basic Java statement ends with a semicolon ; The contents of a class or method occur between { and }
Missing semicolon Too many or too few { } braces, braces not matching Class and file names do not match ... 16
1 public class Hello { 2 pooblic static void main(String[] args) { 3 System.owt.println("Hello, world!")_ 4 } 5 }
Hello.java: 2 :
18
1 Public class Hello { 2 public static void main(String[] args) { 3 System.out.println("Hello, world!"); 4 } 5 } Hello.java:1: class, interface, or enum expected Public class Hello { ^ 1 error compiler output:
Naming convention: capitalize each word (e.g. MyClassName) Your program's file must match exactly (SubstitutionCipherDecoder.java) includes capitalization (remember, Java is "case-sensitive")
\t tab character \n new line character " quotation mark character \ backslash character Example: System.out.println("\hello\nhow\tare "you"?\\"); Output: \hello how are "you"?\ 25
26
This program prints the first lines of the song "slots". "She lives in a trailer" "On the outskirts 'a Reno" "She plays quarter slots in the local's casino."
A "quoted" String is 'much' better if you learn the rules of "escape sequences." Also, "" represents an empty String. Don't forget to use " instead of "! '' is not the same as "
System.out.println("\ta\tb\tc"); System.out.println("\\"); System.out.println("'"); System.out.println("""""); System.out.println("C:\nin\the downward spiral"); 29 29
30
System.out.println("/ \ // \\ /// \\\");