Java Programming
Last modified Sunday, 07-Jul-2024 16:06:39 UTC.
- Programming Languages
- Machine code, aka Binary
- What computers understand
- Written in 1s and 0s, and not easy for humans to understand
- HelloWorld in machine code
- High-level languages
- A compiler translates high-level programs into machine code, assembly code, or byte code.
Compilers are provided as machine code programs (magic).
- Interpreted languages
- Some languages, e.g., byte code and perl, are interpreted to machine code by an
interpreter.
- An interpreter reads a file of instructions, and makes the computer do what the
instructions say.
For example, a Java byte-code interpreter reads a file of byte-code instructions,
and makes the computer do what the byte-code instructions say.
Interpreters are provided as machine code programs (magic).
- HelloWorld.class
- Java is typically compiled to byte-code and interpreted
- Just In Time (JIT) compilation
- Bytecode (or even source code) is compiled to machine language on demand, when it's
about to be executed.
- Some delays, but generally better performance overall.
- See, e.g., Oracle's
HotSpot
virtual machine.
- Concrete Process
- Programming in Java - that's what we'll be doing!
- Creating and executing a Java program
- Find a problem
- Devise an algorithmic solution (pen, paper, head)
- Write code, compile, and run in a terminal window
- Compile and run in IntelliJ
- Use IntelliJ to type in the Java program.
- The first time, use Run->Run... to compile and run.
Subsequently you can use Run->Run (^R) to compile and run.
- The output will be shown in a subwindow.
- Some samples of Java ... a trailer
- Error messages
- If there are errors in a program submitted to javac then error messages will
be spat out
- Error messages in IntelliJ
- Errors are highlighted in the editor window.
- Hover over each to get information about the error.
- Example: BuggyHelloWorld.java
- Compilation is done in multiple phases, so javac finds all the obvious errors
first, and when you've got them all fixed javac will only then look for subtle
errors.
- Generally, fixing one error does not mean less errors the next time you compile.
Exercises
- What company developed Java?
Exam Style Questions
- Explain the differences between high-level, byte-code, and machine-code languages.