Unit 1: Introduction to Java
Lesson 1: What is Java?
It's a FREE programming language based on C and C++. It can run as an application on a computer or as an applet in a browser. You cannot make a java program into a .exe file.
Special features:
- object oriented (OOP = object oriented programming)
(everything is an object)
OOP is not the solution for everything. It is a useful way to program in many situations, but not everything can be easily represented as an object. There may be better ways to program something.
- platform independent (a platform is a type of computer / operating system)
- automatic memory management (unlike C and C++) with garbage collection
- type checking (unlike Javascript)
- exception handling to take care of errors properly (this is becoming more widely used)
Why study Java?
1. Look at these three websites. What do you notice?
- http://redmonk.com/sogrady/2012/09/12/language-rankings-9-12/
- https://sites.google.com/site/pydatalog/pypl/PyPL-PopularitY-of-Programming-Language
- http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html
2. Android uses Java
How does Java work?
There are always two steps: COMPILE, then RUN:
source code | ——► compile |
bytecode | ——► run |
machine code running on CPU |
|
written using an IDE | compiler (in JDK) |
JVM (interpreter) (in JRE) |
|||
Filenames: | Program.java | javac.exe | Program.class | java.exe |
- You can write the source code in any editor (as long as it is saved in plain text format) or IDE.
- Source code must have the same name as the main class
- Source code must end in .java
- It is compiled to bytecode by the java compiler (javac.exe)
- Bytecode is saved with the extension .class
- The bytecode can be put on any operating system and will be run by the Java Virtual Machine for that OS and CPU.
Your first program
Have a look at this set of templates and then write a program to print "Hello World".