DEV Community

Varudhammal Abinaya
Varudhammal Abinaya

Posted on

Rewinding to the Basics

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

  1. Source Code
  2. Compiled into Bytecode
  3. Executed by JVM
  4. 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:

  1. Can include letters (A-Z, a-z), digits (0-9), _, $
  2. Cannot begin with a digit
  3. Case-sensitive
  4. 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

  1. ++a (pre-increment)
  2. a++ (post-increment)
  3. --a, a-- (decrement)
  4. ! (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)