Let's Java - 3 Billion Devices!
What is Java:
Why Java?
- Remember Python is an interpreted, object-oriented, high-level programming language with dynamic semantics?
- Java implementations typically use a two-step compilation process. Java source code is compiled down to bytecode by the Java compiler. The bytecode is executed by a Java Virtual Machine (JVM). Modern JVMs use a technique called Just-in-Time (JIT) compilation to compile the bytecode to native instructions understood by hardware CPU on the fly at runtime.
- Java Development Kit (JDK) vs Java Runtime Environment (JRE) which contains the JVM
- NetBeans is an Integrated Development Environment (IDE)
- Let's install IntelliJ IDE
Main = class file or start of the application
The main() method is the first method to be called.
Java looks for this as entry point: public static void main(String[] args)
- Let's run Hello World app
- Change code to "Hello World Again!", then run again
- Let's run from command line
- End user need the JRE:
- java -version
- java Main <-- to run from java directly | Note that Main is the main entry point
- java made up statements and with ; what is Phython?
** Let's play with Java whitespace ** DIFFERENT from Python
Java comments:
// line comments
/* */ block comments
/** */ JavaDoc comments to create documentation within source code http://bit.ly/psjavadoc
1. to add human-reable notes to source code
2. "Hide" source code without deleting
Java Packages
- all lowercase
- use reversed domain name to ensure global uniqueness com.rollingcoders.example convention
- class is now com.rollingcoders.example.Main
Java requires no correlation between package names and source code file structure whereas IDE require a sub-folder for each part of package name
$ java com.rollingcoders.getorganized.Main
Hello Get Organized
/Users/htran010/Documents/Organized/out/production/Organized
==========
Let's tak variables
- Strongly typed language = must specify type (i.e. int datavariable = 100;
- Value can be modified
Rules
- letters, numbers, $ and _
- convention only letters and numbers are used
- first number NOT a number
- convention always a letter
- use Camel Case (i.e. bankAccountBallance, level2Training)
Primitive Data Type = Foundation of all other types
Four Categories of Primitive Types
- Integer
- Floating Point : stores fractions
- Character
- Boolean
Operators: