120 likes | 137 Views
Learn about the two types of Java programs - Application and Applet, and why Java is a cross-platform language that offers enhanced security. Discover the Java compiler, JVM, and the program development process.
E N D
Java some slides from Gaddis’ book (our textbook) supplemented/modified by Kaminski
2 types of Java programs Application Stand-alone program (no web browser) Relaxed security since user runs program locally Applet Small app embedded in a webpage - needs a Java enabled web browser to run app Enhanced security since user goes to a web page & applet runs itself
Why Java (vs. other languages)? Java is “cross platform” So portable Program written for 1 type of device/HW/OS runs on ANY OTHER device/HW/OS without rewriting/recompiling program
Normal Compiler Programmer writes program in high-level lang. (C, C#, COBOL,…) using text editor or IDE (Integrated Development Environment) saves it as a source code file = set of programming language statements Compiler translates source code into machine language = executable code (SomeProgram.exe) for a specific CPU / OS [simplistically]
Compiler = a program IPO (Input / Processing / Output) translates: Input data: source code file Output data: machine language file also finds syntax errors spelling, grammar, structure errors that violate rules of that language .
the Java “compiler” (& the JVM) Java compiler translates Java source file into a file containing byte code instructions Byte code instructions are the “machine language” of the Java Virtual Machine (JVM) & can NOT be executed directly by a CPU
Java Virtual Machine (JVM) JVM = a program that emulates a HW CPU JVM executes each byte code instruction, as it’s read (unlike a compiler) an interpreter (vs. a true compiler) Java = an interpreted language
Program Development Process Source code (.java) Saves Java statements Is read by Byte code(.class) Java compiler (javac) Produces Is interpreted by Program Execution Java Virtual Machine (java) Results in Text editor (or IDE)
So Java programs are Portable Portable = program written for 1 type of computer runs on a wide variety of computers (with little/no modification) (e.g., applets) Java byte code runs on the JVM (on a computer), NOT on any particular CPU So “compiled” Java .class programs highly portable Specific JVM’s exist for many platforms: • Windows • Mac • Linux • Unix • etc.
Portability Programs in other languages portable by: re-compiling program for each different platform / CPU so, many different .exe files required (what about applets for web?) Java provides a JVM for each platform so only 1 .class (byte code) file works everywhere Byte code program runs on ANY JVM
You need JDK on your laptop JDK (Java Development Kit) software used to write Java programs different editions of JDK: Java SE - Standard Edition Java EE - Enterprise Edition Java ME - Micro Edition free download from Oracle
2 ways to compile Java program command-prompt (B&W) window javac is Java compiler (for specific JVM) to compile: javac SomeProgram.java IDE automates (& hides) this icon to build (instead of compile) automatic build when program is run