javabasic
javabasic
1. Introduction to Java
What is Java?
Java is a high-level, object-oriented programming language developed by Sun
Microsystems in 1995, now owned by Oracle.
Platform-independent: Java code is compiled into bytecode, which can run on any
platform with a Java Virtual Machine (JVM).
JVM (Java Virtual Machine):
Responsible for running Java programs and converting bytecode into machine code
specific to the platform.
2. Basic Syntax and Structure
Java Program Structure:
java
Copy
public class Main {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Class Declaration: Every Java program must have at least one class.
Main Method: Entry point of a Java application. The main method is where the
execution starts.
Statements and Expressions: Java uses statements to perform actions (e.g.,
System.out.println()).
Comments:
Single-line: // This is a comment
Multi-line: /* This is a multi-line comment */
3. Variables and Data Types
Primitive Data Types:
int: Integer values.
double: Floating-point values.
char: Single characters.
boolean: True or false.
byte, short, long, float: Other numerical types with varying ranges.
Declaration:
java
Copy
int num = 10;
double price = 20.99;
char grade = 'A';
boolean isJavaFun = true;