Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

Python Cheat Sheet

Uploaded by

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

Python Cheat Sheet

Uploaded by

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

**Java Cheat Sheet**

Data Types:
- int: 42
- double: 3.14
- char: 'A'
- boolean: true or false
- String: "Hello, World!"
- Arrays: int[] numbers = {1, 2, 3};

Basic Operations:
- Arithmetic: +, -, *, /, %
- Comparison: ==, !=, <, >, <=, >=
- Logical: &&, ||, !
Control Flow:
- if (condition) {
statement;
} else if (condition) {
statement;
} else {
statement;
}
- switch (variable) {
case value:
statement;
break;
default:
statement;
}
- while (condition) {
statement;
}
- for (int i = 0; i < n; i++) {
statement;
}
- break: Exit loop prematurely
- continue: Skip current iteration

Methods:
public returnType methodName(parameters) {
statement(s);
return value;
}
Classes and Objects:
class ClassName {
dataType attributeName;

ClassName(dataType parameter) {
attributeName = parameter;
}

returnType methodName(parameters) {
statement(s);
}
}

Inheritance and Polymorphism:


class ChildClass extends ParentClass {
@Override
returnType methodName(parameters) {
statement(s);
}
}

Interfaces and Abstract Classes:


interface InterfaceName {
returnType methodName(parameters);
}

abstract class AbstractClassName {


abstract returnType methodName(parameters);
}
Exception Handling:
try {
statement;
} catch (ExceptionType e) {
statement;
} finally {
statement;
}

Arrays and Collections:


- Arrays: dataType[] arrayName = new dataType[size];
- ArrayList: ArrayList<dataType> listName = new
ArrayList<>();
- HashMap: HashMap<keyType, valueType> mapName
= new HashMap<>();
File Handling:
- FileReader and BufferedReader
- FileWriter and BufferedWriter

Packages and Imports:


package packageName;
import packageName.className;

Multithreading:
- Extending Thread class
- Implementing Runnable interface
Modifiers:
- public, private, protected
- static, final, abstract
- synchronized, volatile

Best Practices and Tips:


- Naming Conventions
- Avoid Magic Numbers
- Documentation (Javadoc)
- Code Formatting (indentation)

You might also like