Chapter 7: Java Basics ☕¶
This cheat sheet covers Java syntax and core features for Chapter 7 of the GSEB Std 12 Computer Studies syllabus.
🎯 Key Concepts¶
- Java: High-level, object-oriented language developed by James Gosling (Sun Microsystems).
- Bytecode: The platform-independent format (saved as
.class) that runs on the JVM. - WORA: "Write Once, Run Anywhere."
🛠️ JDK Development Tools¶
| Tool | Full Name | Description |
|---|---|---|
javac |
Java Compiler | Converts source code (.java) to bytecode (.class). |
java |
Java Interpreter | Executes the bytecode on the JVM. |
jdb |
Java Debugger | Helps find and fix errors in the code. |
javadoc |
Doc Generator | Automatically generates documentation from comments. |
appletviewer |
Applet Viewer | Used to view and test Java applets (older tech). |
⚙️ Java Tokens & Data Types¶
1. Java Tokens¶
- Keywords: Reserved words like
class,public,int,static(50+ words). - Identifiers: Names for variables, classes, and methods. Must not start with a digit.
- Literals: Constant values (e.g.,
100,"hello",true). - Operators: Symbols like
+,-,*,/. - Separators: Characters like
( ),{ },[ ],;,,.
2. Primitive Data Types & Sizes¶
- Boolean: 1 bit (
trueorfalse). - Character: 2 bytes (uses Unicode character set).
- Integer Types:
byte(1),short(2),int(4),long(8). - Floating Types:
float(4),double(8).
🔒 Control Structures & Loops¶
1. Selection (Decision)¶
ifStatement: Checks a condition.switch: Multi-way branching based on a variable's value.
2. Iteration (Loops)¶
- Entry Controlled Loops: Condition checked before execution (
for,while). - Exit Controlled Loops: Condition checked after execution (
do-while). break: Exits the loop immediately.continue: Skips the rest of the current iteration and goes to the next.
💡 Board Focus: High-Weightage Points 👔¶
- MCQ Alert: Java uses Unicode (16-bit) characters, unlike C/C++ which use ASCII.
- MCQ Alert: The
javaccommand compiles;javacommand runs. - MCQ Alert:
main()is the entry point and must returnvoid. - MCQ Alert: Single quotes are for
char('A'), double quotes forString("ABC"). - MCQ Alert: Java is case-sensitive.
Board Exam Secret
GSEB frequently asks about "Exit Controlled" loops. Remember: do-while will execute at least once even if the condition is false!