0% found this document useful (0 votes)
42 views3 pages

Java Cheat Sheet Expanded

This Java Cheat Sheet provides a quick reference to basic Java syntax, data types, operators, control statements, loops, functions, object-oriented programming, exception handling, and file handling. It also lists important packages and classes used in Java programming. The document serves as a concise guide for Java developers to understand essential concepts and code snippets.

Uploaded by

raghubirkar11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views3 pages

Java Cheat Sheet Expanded

This Java Cheat Sheet provides a quick reference to basic Java syntax, data types, operators, control statements, loops, functions, object-oriented programming, exception handling, and file handling. It also lists important packages and classes used in Java programming. The document serves as a concise guide for Java developers to understand essential concepts and code snippets.

Uploaded by

raghubirkar11
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Java Cheat Sheet

1. Basic Syntax

public class Main {


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

2. Data Types

int - Integer (e.g., 10)


float - Floating point number (e.g., 10.5f)
char - Character (e.g., 'A')
String - Sequence of characters (e.g., "Hello")
boolean - True or False

3. Operators

+ Addition
- Subtraction
* Multiplication
/ Division
% Modulus
== Equal to
!= Not equal to
>= Greater than or equal to
<= Less than or equal to

4. Control Statements

if (condition) {
// code block
} else {
// another code block
}
Java Cheat Sheet

switch(expression) {
case value1:
// code
break;
default:
// code
}

5. Loops

for (int i = 0; i < 10; i++) {


System.out.println(i);
}

while (condition) {
// loop body
}

6. Functions

public static int add(int a, int b) {


return a + b;
}

7. Object-Oriented Programming (OOP)

class Animal {
String name;
void makeSound() {
System.out.println("Sound");
}
}

public class Dog extends Animal {


void makeSound() {
System.out.println("Bark");
Java Cheat Sheet

}
}

8. Exception Handling

try {
int x = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Error: " + e.getMessage());
}

9. File Handling

import java.io.*;
try {
FileWriter writer = new FileWriter("file.txt");
writer.write("Hello, Java");
writer.close();
} catch (IOException e) {
System.out.println("An error occurred.");
}

10. Important Packages & Classes

java.lang - Core Java classes (String, Math, Integer, etc.)


java.util - Data structures & utilities (ArrayList, HashMap, etc.)
java.io - File handling (File, FileReader, FileWriter)
java.net - Networking (Socket, URL, HttpURLConnection)
java.sql - Database connectivity (Connection, Statement, ResultSet)

You might also like