"Java Quick Reference Cheat Sheet: Master the Language Instantly"

Java Quick Reference Cheat Sheet

Java Cheat Sheet: Operators, Scanner & User Input ☕
Java Cheat Sheet: Operators, Scanner & User Input ☕

Java, a popular object-oriented programming language, is widely used for building enterprise-scale applications. Whether you're a seasoned developer or just starting out, this quick reference cheat sheet will help you brush up on essential Java concepts and syntax.

Java Cheat Sheet for GTU Students | Quick Revision Notes & OOP Concepts
Java Cheat Sheet for GTU Students | Quick Revision Notes & OOP Concepts

Java Basics

Java is a statically-typed, object-oriented language that follows the "write once, run anywhere" (WORA) principle. It's known for its rich API and extensive libraries like Java Collections Framework and Java I/O.

Java Cheatsheet for Beginners | Learn Java Basics in One Page
Java Cheatsheet for Beginners | Learn Java Basics in One Page

Hello World in Java

Here's the classic "Hello, World!" program in Java:

☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀
☕ Java Basics Cheat Sheet for Beginners | Learn Java in One Page 🚀

public class Main {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Variables and Data Types

Java is a strongly-typed language, meaning you must declare the type of a variable before you can use it. Here are the eight primitive data types in Java:

  • byte
  • short
  • int
  • long
  • float
  • double
  • boolean
  • char
Master Java 🚀 Advanced Cheat Sheet for Real Developers
Master Java 🚀 Advanced Cheat Sheet for Real Developers

You can also use reference types to create objects and arrays.

Variable Declaration and Initialization

Here's how to declare and initialize variables in Java:

Java Basics Cheat Sheet | Core Java Programming Notes for Beginners | AKTU Notes
Java Basics Cheat Sheet | Core Java Programming Notes for Beginners | AKTU Notes

int x = 10; // declaration and initialization
int y; // declaration only
y = 20; // initialization

Operators

Java supports various operators for performing operations on variables and values. Here are some common ones:

Java Programming Cheat Sheet | Data Types, Variables & Java Fundamentals
Java Programming Cheat Sheet | Data Types, Variables & Java Fundamentals
Complete Java Cheat Sheet for Beginners to Advanced Developers
Complete Java Cheat Sheet for Beginners to Advanced Developers
a white and yellow poster with some words on the bottom right hand corner, which is also
a white and yellow poster with some words on the bottom right hand corner, which is also
THE ULTIMATE JAVA CHEATSHEET
THE ULTIMATE JAVA CHEATSHEET
Java Exception Handling Cheat Sheet
Java Exception Handling Cheat Sheet
Java Cheat Sheet Every Developer Should Save!
Java Cheat Sheet Every Developer Should Save!
the back side of a black poster with orange, blue and white text on it
the back side of a black poster with orange, blue and white text on it
Java programming cheat sheet
Java programming cheat sheet
an image of a table with some text on it
an image of a table with some text on it
an array sheet with the names and numbers for different types of programming languages on it
an array sheet with the names and numbers for different types of programming languages on it
Learn Java Collections Fast 🚀 | ArrayList HashMap Set Queue Explained
Learn Java Collections Fast 🚀 | ArrayList HashMap Set Queue Explained
Java interviews chaet sheet
Java interviews chaet sheet
Java Basics Cheat Sheet 📘⚡ | Learn Coding Faster & Smarter
Java Basics Cheat Sheet 📘⚡ | Learn Coding Faster & Smarter
Java Programming Cheatsheet
Java Programming Cheatsheet
an orange and white poster with words on it that describe the different types of characters
an orange and white poster with words on it that describe the different types of characters
Java OOP Cheat Sheet: Object Oriented Programming Concept Codes
Java OOP Cheat Sheet: Object Oriented Programming Concept Codes
Client Challenge
Client Challenge
Java Basics Cheat Sheet for Beginners | Syntax, Loops, OOP, Arrays
Java Basics Cheat Sheet for Beginners | Syntax, Loops, OOP, Arrays
Java Strings Cheat Sheet  | Complete String Methods Guide for Beginners
Java Strings Cheat Sheet | Complete String Methods Guide for Beginners
Java Basics Cheat Sheet for Beginners
Java Basics Cheat Sheet for Beginners
Operator Description Example
+ Addition x + y
- Subtraction x - y
* Multiplication x * y
/ Division x / y
% Modulus (remainder) x % y

Control Structures

Java provides several control structures for making decisions and looping through code. Here are a few examples:

if-else Statement

Here's a simple if-else statement that checks if a number is even or odd:

int num = 7;
if (num % 2 == 0) {
    System.out.println("Even");
} else {
    System.out.println("Odd");
}

for Loop

Here's a for loop that prints numbers from 1 to 5:

for (int i = 1; i <= 5; i++) {
    System.out.println(i);
}

Classes and Objects

In Java, everything is an object or a class. Here's a simple class declaration and how to create an object from it:

public class Person {
    String name;
    int age;

    public void sayHello() {
        System.out.println("Hello, I'm " + name + " and I'm " + age + " years old.");
    }
}

// Creating an object of Person class
Person person1 = new Person();
person1.name = "John Doe";
person1.age = 30;
person1.sayHello(); // Output: Hello, I'm John Doe and I'm 30 years old.

Important Java Keywords

Here are some important Java keywords that you should know:

  • abstract
  • continue
  • for
  • new
  • switch
  • break
  • goto
  • package
  • synchronized
  • case
  • if
  • private
  • this
  • catch
  • implements
  • protected
  • throw
  • class
  • import
  • public
  • throws
  • const
  • instanceof
  • return
  • transient
  • default
  • int
  • short
  • try
  • do
  • interface
  • static
  • true
  • while
  • false
  • long
  • strictfp
  • void

This quick reference cheat sheet covers the basics of Java, from variables and data types to control structures and important keywords. Keep it handy for a quick refresher, and happy coding!