1/51
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Platform
Basic hardware + operating system environment where applications run.
Portability (definition)
Ability to run a program on different machines; truly portable means no recompiling or code changes needed.
Why portability matters
Supports more platforms → more potential customers.
Java introduced
Public release by Sun Microsystems in 1995.
Java slogan
“Write Once, Run Anywhere.”
Oracle + Java Sun Microsystems
acquired by Oracle in 2010, bringing Java under Oracle.
Java’s 3 portability types Source code portability;
CPU architecture portability; OS/GUI portability.
Source code portability (C/C++)
C/C++ syntax is defined but semantics are loose → same code may behave differently across CPUs/OS/compilers/settings.
Source code portability (Java)
Java defines more behavior (semantics) than C/C++ → less variation across platforms.
Garbage collection (Java) Memory isn’t freed until
it can no longer be accessed (handled by garbage collector).
Uninitialized variables in Java
Java doesn’t have ANY uninitialized variables.
Java integer size Integers are
32bit
Java floating point standard Uses
IEEE754 floating-point math.
Object code portability
Object code is NOT portable; it’s binary instructions tied to a specific CPU/ISA.
ISA meaning
Instruction Set Architecture; the instruction design a CPU uses.
Why object code is CPU-specific
Binary instructions are tied to a processor’s ISA; code built for CPU type X runs only on type X.
RISC vs CISC
RISC: simple uniform instructions, often fixed length, often 1 clock cycle; CISC: complex instructions, variable length, can do multi-step operations.
JVM (definition)
Software-based virtual machine that runs Java bytecode; abstracts hardware/OS so Java runs on any platform with a compatible JVM.
How JVM enables platform independence
JVM interprets/compiles bytecode into machine-specific instructions at runtime so the same bytecode runs on different platforms.
JVM responsibilities
Manages memory, executes code, handles security and garbage collection.
Key JVM components
Class Loader; Execution Engine; Memory Manager; Bytecode Verifier; JVM ISA (bytecode instruction set).
Class Loader
Loads classes into memory.
Execution Engine
Interprets or compiles bytecode into native machine code.
Memory Manager
Handles heap/stack allocation and garbage collection.
Bytecode Verifier
Ensures bytecode integrity and security.
JVM ISA
JVM has its own abstract platform-independent instruction set (bytecode instructions).
Platform independence slogan
meaning Write once; compile to bytecode; run on any OS/CPU with a JVM.
Java compilation phase 1
Compile .java using javac → produces bytecode (.class).
Java execution phase 2
Run .class using java (JVM interpreter) → translates to native machine code in memory for the target platform.
Is bytecode an executable?
No. Java bytecode is NOT an executable; it requires the JVM to run.
JRE (definition) Java Runtime Environment;
used to run Java programs.
JRE includes
JVM + core Java class libraries (e.g., java.util, java.io).
JDK (definition) Java Development Kit;
used to develop Java applications.
JDK includes
JRE + tools to compile/debug/package Java (e.g., javac).
JDK platform-specific?
Yes; separate installers needed for each OS (Mac/Unix/Windows)
JAR file
A packaged archive for Java apps; can contain multiple files/folders; similar to ZIP with extra distribution features (e.g., signing).
NetBeans JAR location
PROJECT_HOME/dist (created every time you compile).
Production requirement for running a JAR
You should have the JRE installed.
OS/GUI portability challenge
Different OS/GUI APIs for file IO, windows, networking, sound, memory, etc.
Java OS/GUI portability solution
Java libraries provide a virtual OS/GUI (like JVM provides a virtual CPU).
AWT (java.awt)
Thin layer on top of OS; uses native heavyweight components; platform dependent (less portable).
Swing (javax.swing)
Pure Java lightweight components; platform independent (more portable); larger bytecode; richer functionality.
Swing vs AWT portability
Swing is more portable (platform independent); AWT is platform dependent.
Why Swing is in javax
javax originally meant extensions; Swing began as extension; later became standard but kept package name to avoid breaking existing software.
Downside of Java portability
Java assumes 32-bit machine + IEEE754 floats; some machines (e.g., 8-bit microcontrollers) can’t run Java.
C/C++ vs Java portability across devices
C/C++ expected to run on more platforms than Java (especially small/embedded devices).
Java performance criticism
Bytecode execution can be slower than fully compiled native code.
JIT compilation
Just-in-time compilation compiles bytecode into native code, stores it in memory, and reuses it when needed.
HotSpot JVM performance engine
Optimizes frequently used code with a compiler.
Inlining optimization
Replaces method calls with method body to reduce call overhead.
Loop unrolling optimization
Expands loop iterations to reduce loop control overhead.
Dead code elimination
Removes code that will never execute.