The term "Sun Java Basics" refers to the fundamental concepts of the Java programming language, as it was originally developed by Sun Microsystems (before being acquired by Oracle).
Here is an overview of the core concepts that define Java's foundation:
📜 Core Principles and Structure
1. The Java Platform
The Java platform is what makes Java applications highly portable ("Write Once, Run Anywhere").
Java Virtual Machine (JVM): The abstract machine that executes Java bytecode. It's the interpreter layer that translates bytecode into the native machine code of the underlying OS (Windows, macOS, Linux).
Java Runtime Environment (JRE): The minimal software required to run a Java application. It includes the JVM, core classes, and supporting files.
Java Development Kit (JDK): The full set of tools for developing Java applications. It includes the JRE, the compiler (
javac), and other debugging/utility tools.
2. Execution Flow
You write source code in a
.javafile.The Compiler (
javac) converts the source code into bytecode in a.classfile.The JVM executes the bytecode.
💡 Syntax and Language Fundamentals
1. Basic Structure
All executable Java code must be contained within a class. Execution begins in the main method.
public class MyFirstProgram {
public static void main(String[] args) {
// Output statement
System.out.println("Hello from Java!");
}
}
2. Data Types
Java has two main categories of data types:
| Category | Type | Description | Example |
| Primitive | int, long, float, double | Numeric values (integers and decimals). | int count = 10; |
char | A single Unicode character. | char initial = 'S'; | |
boolean | Represents true or false. | boolean isComplete = true; | |
| Non-Primitive | String, Arrays, Classes | Reference types that hold memory addresses. | String name = "Sun"; |
3. Variables
Variables must be declared with their type before they can be used.
Declaration:
int speed;Initialization:
speed = 60;or combined:int speed = 60;Constants: Defined using the
finalkeyword (e.g.,final double PI = 3.14159;).
4. Operators
Arithmetic:
+,-,*,/,%(modulo/remainder).Relational:
==,!=,>,<,>=,<=.Logical:
&&(AND),||(OR),!(NOT).
🔁 Control Flow
These constructs determine the order in which statements are executed.
1. Decision Making
if-else: Executes a block if a condition is true.Javaif (score >= 90) { System.out.println("Grade A"); } else { System.out.println("Not an A"); }switch: Executes one block of code among many alternatives based on a single value.
2. Looping
forloop: Used when you know the number of iterations beforehand.Javafor (int i = 0; i < 5; i++) { System.out.println(i); // Prints 0 to 4 }whileloop: Repeats a block of code as long as a condition is true.do-whileloop: Executes the loop body at least once, then checks the condition.
⚙️ Object-Oriented Programming (OOP)
Java is an OOP language, built around the concept of objects and classes.
Class: A blueprint for an object. It defines the structure (data/variables) and behavior (methods/functions) of its objects.
Object: An instance of a class. When you create an object, memory is allocated for it.
The four pillars of OOP are:
Encapsulation: The mechanism of binding the data (variables) and the code acting on the data (methods) together into a single unit (the class), and protecting the data from outside interference.
Inheritance: The process by which one class acquires the properties and methods of another class, promoting code reuse.
Polymorphism: The ability of an object to take on many forms. This is achieved through method overriding (redefining an inherited method) and method overloading (methods with the same name but different parameters).
Abstraction: Hiding complex implementation details and showing only essential information. This is achieved using abstract classes and interfaces.
Would you like to explore more about OOP concepts or see an example of control flow?




.jpg)








