0% found this document useful (0 votes)
11 views4 pages

Beginner Java Cheat Sheet Guide

This document is a beginner-friendly Java cheat sheet covering essential topics such as setup, structure, variables, data types, strings, arrays, type casting, constants, operators, input, conditional statements, loops, exception handling, and functions. It also includes a mini project example for a number guessing game. The cheat sheet provides code snippets and explanations for each topic to aid learning.

Uploaded by

Akshansh Sharma
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)
11 views4 pages

Beginner Java Cheat Sheet Guide

This document is a beginner-friendly Java cheat sheet covering essential topics such as setup, structure, variables, data types, strings, arrays, type casting, constants, operators, input, conditional statements, loops, exception handling, and functions. It also includes a mini project example for a number guessing game. The cheat sheet provides code snippets and explanations for each topic to aid learning.

Uploaded by

Akshansh Sharma
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

JAVA CHEAT SHEET (Beginner Friendly)

Setup

- Install JDK: [Link]

- IDE: IntelliJ IDEA - [Link]

Structure

package [Link];

public class Main {

public static void main(String[] args) {

[Link]("Hello World");

Variables & Data Types

Primitive Data Types:

byte, short, int, long, float, double, char, boolean

Non-Primitive:

String name = new String("Aman");

int[] marks = new int[3];

Strings

[Link](0);

[Link]();

[Link]('a','b');
[Link](0, 4);

String full = name1 + description;

Arrays

int[] marks = new int[3];

int[] marks = {97, 98, 95};

Type Casting

Implicit: float finalPrice = price + gst;

Explicit: int finalPrice = price + (int)gst;

Constants

final float PI = 3.14F;

Operators

Arithmetic: + - * / %

Unary: a++, ++a

Assignment: = += -= *= /=

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

Logical: && || !

Math Class

[Link](a, b);

[Link](a, b);

(int)([Link]() * 100);

Input
Scanner sc = new Scanner([Link]);

int n = [Link]();

String line = [Link]();

Conditional Statements

if-else, switch-case

Loops

for, while, do-while

Break & Continue

if (i % 3 == 0) continue;

if (i == 11) break;

Exception Handling

try {

[Link](marks[4]);

} catch (Exception e) {

[Link]("Error occurred!");

Functions

public static void sum(int a, int b) {

[Link](a + b);

Mini Project: Number Guessing Game


Scanner sc = new Scanner([Link]);

int myNumber = (int)([Link]() * 100);

do {

userNumber = [Link]();

if (userNumber == myNumber) break;

else if (userNumber > myNumber) print "Too large";

else print "Too small";

} while(userNumber >= 0);

You might also like