DEV Community

Hayes vincent
Hayes vincent

Posted on • Edited on

Java notes

HISTORY OF JAVA

1991: Java was initiated by James Gosling, Mike Sheridan, and Patrick Naughton at Sun Microsystems. The project was originally called Oak, designed for embedded systems in consumer electronics (like set-top boxes).

Why "Oak"? It was named after an oak tree outside Gosling’s office. Later renamed to Java, inspired by Java coffee (from Indonesia), when Oak was found to be already trademarked.

1995: Java was officially launched as a programming language with the slogan:
"Write Once, Run Anywhere" (WORA)
This was made possible by the Java Virtual Machine (JVM).

TOKENS IN JAVA

1. Keywords

These are reserved words in Java.

They have special meaning and cannot be used as variable names.

Example:int, class, if, else, while, for, return, static, public, void

2. Identifiers

Names used for classes, variables, methods, etc.

Must start with a letter, dollar sign ($), or underscore (_)

Cannot start with a digit or use a Java keyword.

Examples:myVariable, _temp, $result, StudentDetails

3. Literals

Fixed values used in the code.

Types:

Integer literals: 10, -5

Floating-point literals: 3.14, -0.01

Character literals: 'A', '9'

String literals: "Hello", "Java"

Boolean literals: true, false

4. Operators

Symbols that perform operations on variables or values.

Examples:

Arithmetic: +, -, *, /, %

Relational: ==, !=, <, >, <=, >=

Logical: &&, ||, !

Assignment: =, +=, -=

  1. 🧱 Separators / Delimiters

Symbols used to separate code components.

Examples:

Parentheses: ()

Curly Braces: {} → used for blocks

Square Brackets: [] → for arrays

Semicolon: ; → end of statement

Comma: , → separate parameters

Dot: . → access members

FEATUERS OF JAVA

1. Simple

Easy to learn if you know basic programming.

Syntax is clean and mostly based on C/C++ (but simpler and safer).

No pointers, no memory management headaches — Java handles memory automatically.

*2. Object-Oriented
*

Everything in Java is based on objects and classes.

Key principles: Encapsulation, Inheritance, Polymorphism, and Abstraction.

3. Platform-Independent

Java programs are compiled into bytecode, which runs on any machine with a Java Virtual Machine (JVM).

This is why Java follows the principle:

“Write Once, Run Anywhere” (WORA)

*4. Secure
*

Java has built-in security features like:

Bytecode verification

Sandbox for applets

No direct memory access (unlike C/C++)

Helps prevent viruses and hacking.

*5. Robust
*

Strong memory management (uses garbage collection).

Exception handling prevents crashes.

Strong type-checking at both compile-time and runtime.

*6. Multithreaded
*

Java supports multithreading (running multiple tasks at the same time).

Built-in libraries make it easy to write high-performance, responsive programs.

7. Portable

Java code can run on any OS or hardware with a JVM (Windows, Linux, Mac, etc.).

No need to rewrite code for each platform.

*8. High Performance
*

Java is not as fast as C/C++, but much faster than most interpreted languages.

Uses Just-In-Time (JIT) compiler to optimize performance during runtime.

9. Distributed

Java supports networking and distributed computing (e.g., using RMI, Sockets, and Web Services).

Helps build apps that can work across the internet or multiple machines.

10.Rich Standard Library

Java provides a vast set of built-in libraries (APIs) for:

File handling

Networking

Data structures

GUI development

*JAVA DATATPYE
*

A data type in Java defines the type of data a variable can store. It tells the compiler how much memory to allocate and what kind of operations can be performed.

Categories of Data Types in Java

Java data types are divided into two main categories:

  1. Primitive Data Types
  2. Non-Primitive Data Types (Reference Types)

CLASS AND OBJECT IN JAVA

A class is like a blueprint or template for creating objects.
It defines properties (variables) and behaviors (methods) that the object will have.

An object is a real instance of a class — the thing that actually exists in memory and can do things

NUMBER SYSTEM CONVERSION

1. Decimal (Base 10)

Standard number system (uses digits 0–9).

Default format for numbers in Java.

int decimal = 123; // Base 10
System.out.println(decimal); // Output: 123

2. Binary (Base 2)

Uses only 0 and 1.

Prefix: 0b or 0B.

int binary = 0b1010; // 10 in decimal
System.out.println(binary); // Output: 10

3. Octal (Base 8)

Uses digits 0–7.

Prefix: 0

int octal = 012; // 10 in decimal
System.out.println(octal); // Output: 10

*4. Hexadecimal (Base 16)
*

(Uses 0–9 and A–F (A=10, ..., F=15).

Prefix: 0x or 0X.

int hex = 0xA; // 10 in decimal
System.out.println(hex); // Output: 10

Declaration and Initialization

Declaration

Declaration means telling the compiler that a variable exists and specifying its type.

type variableName;

int age; // Declaring an integer variable
double salary; // Declaring a double variable
String name; // Declaring a string variable

Initialization in Java

Initialization means giving a variable its first value.

Top comments (0)