This command-line application demonstrates all basic Java concepts in a clear example.
The program shows the following Java basics:
- boolean: Truth values (true/false), 1 bit
- char: A single Unicode character, 16 bit
- byte: Signed integer, 8 bit (-128 to 127)
- short: Signed integer, 16 bit (-32,768 to 32,767)
- int: Signed integer, 32 bit (-2^31 to 2^31-1)
- long: Signed integer, 64 bit (-2^63 to 2^63-1)
- float: Single-precision floating-point, 32 bit
- double: Double-precision floating-point, 64 bit
- var: Automatic type inference by the compiler (introduced in Java 10)
- Arithmetic Operators: +, -, *, /, % (addition, subtraction, multiplication, division, modulo)
- Relational Operators: ==, !=, >, <, >=, <= (equality, inequality, greater than, less than, etc.)
- Logical Operators: &&, ||, ! (logical AND, OR, NOT)
- Bit Operators: &, |, ^, ~, <<, >>, >>> (bitwise AND, OR, XOR, complement, shifts)
- Assignment Operators: =, +=, -=, *=, /=, %=, &=, |=, ^=, <<=, >>=, >>>=
- Increment/Decrement: ++, -- (pre- and post-increment/decrement)
- Conditional Operator: ? : (ternary operator)
- Cast Operator: (type) variable (explicit type conversion)
- if-else: Conditional execution
- switch: Multiple branches
- while: Loop with condition check before execution
- do...while: Loop with condition check after execution
- for: Counting loop
- foreach (enhanced for): Simplified iteration over arrays and collections
- break: Premature termination of a loop or switch block
- continue: Skipping the current loop iteration
- Labels: Marking loops for targeted break/continue
# Compile
javac src/JavaBasicsDemo.java
# Run
java -cp src JavaBasicsDemoThe program displays examples for each area and their output to illustrate the concept.
The src/aufgaben directory contains various exercises that demonstrate Java basics:
- Temperature Conversion
- Leap Year Verification
- ISBN Validator
- Prime Number Test
- Interest Calculator
- Palindrome Checker
- Array Sorting
- Word Counter
- Number System Converter
- Format Console Output
Each exercise includes a corresponding test in the src/tests directory.