What is Java?
A popular programming language created in 1995. - Owned by Oracle; used by over 3 billion devices. - Applications include: - Mobile applications (Android apps) - Desktop applications - Web applications - Web servers and application servers - Games - Database connections
Why Use Java? - Cross-platform capability (Windows, Mac, Linux, etc.). - High popularity and job market demand. - Easy to learn and use. - Open-source and free. - Secure, fast, and powerful. - Large community support (tens of millions of developers). - Object-oriented, promoting code reuse.
Components of Java
JDK, JRE, and JVM -
JDK (Java Development Kit): Environment for developing Java applications.
Includes JRE, compiler (javac), and other tools.
JRE (Java Runtime Environment): Provides the required environment to run Java applications. Includes JVM.
JVM (Java Virtual Machine): Executes Java programs by interpreting bytecode.
Java Control Flow Statements - Types of control flow statements include: 1. Decision-making statements (if, switch) 2. Loop statements (for, while, do-while) 3. Jump statements (break, continue)
If-Else Statements
Simple if statement: Executes code block if condition is true.
If-else statement: Executes one block if condition is true, another if false.
If-else-if ladder: Chain of multiple conditions.
Nested if: If statements within if blocks.
Switch Statement - Similar to if-else statements with multiple cases. - Executes code based on the variable's value. - Break statements terminate cases. - Uses int, char, byte, short, and string variables starting from Java 7.
Loop Statements -
For loop: Executes instructions repeatedly based on condition.
While loop: Repeats code block as long as the condition is true.
Do-while loop: Executes block at least once before checking condition.
For-each loop: Simplifies iteration over arrays or collections.
Java Operators -
Arithmetic Operators: Perform arithmetic operations (+, -, *, /, %). -
Unary Operators: Require one operand (++, --, +, -). -
Assignment Operators: Assign values (+=, -=, *=, /=). -
Relational Operators: Compare values (==, !=, >, <). -
Logical Operators: Perform logical operations (&&, ||, !). -
Bitwise Operators: Operate on individual bits (&, |, ^, ~). -
Shift Operators: Manipulate bit positions (<<, >>, >>>).
Java Continue Statement - Skips to next iteration without breaking the loop.