Java_OOPs_Notes
Java_OOPs_Notes
---
int x = 10;
double a = 9.7;
---
System.out.println("Hello, World!");
String[] args:
---
String Allocation
- String Pool: Saves memory by storing one copy of identical string literals.
Example:
String a = "Hello";
String b = "Hello";
String s = "Hello";
s.length(); // 5
s.charAt(1); // 'e'
s.contains("ell"); // true
s.indexOf("l"); // 2
---
Bitwise Operators
| | OR |5|3=7
^ | XOR |5^3=6
~ | NOT | ~5 = -6
---
Conditional Statements
if (condition) {
// code
} else if (otherCondition) {
// code
} else {
// code
// switch
switch (value) {
case 1: break;
case 2: break;
default: break;
// ternary
---
Arrays in Java
arr[0] = 10;
Example:
for (int i = 0; i < arr2.length; i++) {
System.out.println(arr2[i]);
---
Encapsulation
- Achieved by:
Example:
class Person {
return name;
this.name = name;
---
Access Modifiers
Modifier | Class | Package | Subclass | World
private | Yes | No | No | No
---
Polymorphism
class Calculator {
class Animal {
---
Abstraction
1. Abstract Class:
2. Interface:
interface Drawable {
void draw();
interface Paintable {
void paint();
---