Hey everyone! ๐
This blog post is a summary of what I learned in my very first Java class. Whether you're starting Java or need a quick refresher, this post will walk you through the key concepts in a beginner-friendly way.
๐ง Evolution of Java
- Java was conceived by James Gosling and a team at Sun Microsystems in 1991.
- Initially named "OAK", it was later renamed to Java.
- Java was designed with the principle of Write Once, Run Anywhere, making it a platform-independent language.
โ๏ธ How Java Works
๐ Compiler
- Converts high-level source code into bytecode.
- Unlike C/C++, Java doesn't compile to machine-specific code.
- The bytecode is portable and can run on any machine with a Java Virtual Machine (JVM).
๐ก Platform Independence
- Source Code
- Compiled into Bytecode
- Executed by JVM
- Runs on any machine
๐งฐ Java Ecosystem
- JDK (Java Development Kit): Includes compiler + JRE + tools
- JRE (Java Runtime Environment): Includes JVM + libraries to run Java apps
- JVM (Java Virtual Machine): Executes bytecode
- JavaFX: A library to build rich user interfaces
Structure of a Java Program
Coding:x
class First {
public static void main(String[] args) {
// Code here
}
}
- First is the class name.
- public static void main(String[] args) is the main method โ the entry point of every Java program.
- If a class is marked public, your file name must match the class name (e.g., First.java).
Types of Errors
Type Description
Compilation Error Happens during compilation (syntax/structure issues)
Runtime Error Occurs while running (e.g., int num = 10/0;)
Logical Error Produces incorrect results due to wrong logic
Comments in java
// Single-line comment
/*
Multi-line comment
*/
Variables & Naming Conventions
Rules:
- Can include letters (A-Z, a-z), digits (0-9), _, $
- Cannot begin with a digit
- Case-sensitive
- Cannot use Java reserved keyword ๐ Data Types in Java
๐งฉ Primitive Data Types
Type Size Example
byte 1 byte byte a = 127;
short 2 bytes short s = 32000;
int 4 bytes int i = 1000;
long 8 bytes long l = 100000L;
float 4 bytes float f = 10.5f;
double 8 bytes double d = 10.5;
char 2 bytes 'A'
boolean 1 bit true/false
โ๏ธ Note:
Use L or l for long, f or F for float.
๐งฎ Operators
โ Arithmetic Operators
Operator Description
- Addition
- Subtraction
- Multiplication / Division % Modulus
โ Augmented Assignment
int num = 3;
num += 3; // same as num = num + 3;
๐ Type Casting
Implicit (Widening)
int x = 10;
double y = x; // Automatic
Explicit (Narrowing)
double d = 9.85;
int i = (int) d; // Output: 9
โ๏ธ Unary Operators
- ++a (pre-increment)
- a++ (post-increment)
- --a, a-- (decrement)
- ! (logical NOT)
โ
Relational & Logical Operators
Relational
- ==, !=, <, <=, >, >=
Logical
Expression Result
true && true true
true && false false
true
false
๐งช Literal Representations
- Decimal โ int a = 10;
- Binary โ int b = 0b1010;
- Octal โ int o = 012;
- Hexadecimal โ int h = 0xA;
Bitwise Operator
Operator---Description
(<<)-------left shift
(>>)-------signed right shift
(>>>)------unsigned right shift
Wrapper Classes & Methods
Every primitive data type has a wrapper class: int โ Integer, char โ Character, etc.
Example:
String myName = "Abi";
System.out.print(myName); // Abi
Finally
This was a quick walkthrough of everything I learned in my first Java class โ from how Java works under the hood to basic building blocks like data types and operators. These fundamentals are the stepping stones for deeper concepts ahead. Iโll continue sharing what I learn, one topic at a time, so stay tuned! ๐
Are you also learning Java? Share your favorite learning tip or resource in the comments โ letโs grow together! ๐ฌ๐ฉโ๐ป
Top comments (0)