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

OOP, Java Basics, and Coding Concepts

Uploaded by

Rishabh Gupta
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)
7 views4 pages

OOP, Java Basics, and Coding Concepts

Uploaded by

Rishabh Gupta
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

1.

OOP & UML

OOP: Programming using objects; procedural focuses on functions and flow.


Encapsulation: Binding data+methods; achieved using private fields + getters/setters.
Inheritance: One class acquires another’s properties; e.g., Car extends Vehicle.
Polymorphism: One interface many forms; compile-time (overload), runtime (override).
Abstraction: Hide implementation; abstract class can have methods+state, interface only contracts.
Information hiding vs Encapsulation: Hiding is design principle, encapsulation is implementation.
Inheritance types: Single(A→B), Multilevel(A→B→C), Hierarchical(A→B, A→C).
Is-a vs Has-a: Inheritance vs Composition.
Overloading vs Overriding: Same name diff params vs same signature diff impl.
SOLID: S-single responsibility, O-open/closed, L-substitutable.
Multiple inheritance issue: Diamond problem; Java avoids via interfaces.
LSP: Child must replace parent without breaking behavior.
ISP: Many small interfaces better than one fat.
DIP: Depend on abstractions not concrete classes.
UML: Use case shows behavior, class shows structure.
Class relations: Association, Aggregation(weak), Composition(strong).
Aggregation vs Composition: Team-player vs House-room.
Static override: Not overridden, method hiding occurs.

2. Java Basics

Features: OOP, platform independent, secure, robust.


JDK vs JRE vs JVM: Dev kit vs runtime vs execution engine.
main signature: public static void main(String[] args).
Primitives: byte, short, int, long, float, double, char, boolean.
== vs equals: reference vs content.
final: variable constant, method no override, class no inherit.
Pre/Post increment: ++i then use, i++ use then increment.
Loops: for-known count, while-condition, do-while runs once.
break vs continue: exit loop vs skip iteration.
WORA: Bytecode runs on any JVM.
Naming: Class PascalCase, variable/method camelCase.
switch vs if: fixed values vs conditions.
10+20+"Java"+30+40 = 30Java3040.
Input: Scanner, BufferedReader.
Short-circuit: && stops if first false.
Infinite loops: for(;;), while(true).
JVM memory: Heap(objects), Stack(method frames).

3. Classes, Objects & Core APIs

Class blueprint, object instance.


Constructors: default, parameterized.
this: current object reference.
Static vs instance: class-level vs object-level.
Wrappers: Integer, Double, Boolean.
Scanner for input.
Constructor chaining: this(), super().
Copy constructor: pass object to constructor.
Autoboxing/unboxing: int↔Integer.
Packages organize classes; import access.
Date: SimpleDateFormat.
Integer cache: -128 to 127.
Static cannot use this.
[Link]().plusDays(7).
LocalDate(date), LocalTime(time), LocalDateTime(both).
TimeZone: ZonedDateTime.
Object methods: equals, hashCode, toString.
GC: auto memory cleanup.

4. Arrays & Strings

Array declaration: int[] a = new int[5].


1D vs 2D arrays.
String pool stores literals.
String methods: length, charAt, substring.
StringBuilder faster, Buffer synchronized.
Iteration: for, for-each.
[Link], [Link].
Reverse string via loop/StringBuilder.
Vowel count using loop.
Varargs: method(int... a).
IndexOutOfBounds when invalid index.
String == compares ref; new creates new object.
Immutability: security, caching.
First non-repeat via map.
Palindrome ignore case/spaces.
Anagram by sorting or frequency.

5. Regular Expressions

Digits only: \d+.


Pattern/Matcher for regex.
Email regex basic validation.
matches checks full, find partial.
Remove spaces: \s+.
Pattern compile → matcher → match.

6. Inheritance & Advanced OOP

Overriding rules: same signature, covariant return.


super: parent access.
Dynamic dispatch at runtime.
Parent ref child object allowed.
Abstract constructor allowed.
Lambda: () -> {}.
Default method conflict resolved by override.
Diamond solved via interfaces.
Functional interface: Runnable.
Lambda cleaner than anonymous class.

7. Exception Handling

Exception recoverable, Error not.


Checked vs unchecked.
finally always runs.
Catch order: child first.
throw creates, throws declares.
finally overrides return.
finally can throw exception.
Custom exception extends Exception.
Propagation: up call stack.

8. Logical & Coding Problems

Largest of 3 via comparisons.


Sum array loop.
Even/odd using %.
Calculator via switch.
Factorial loop.
Prime check till sqrt.
Fibonacci iterative.
Largest/second largest tracking.
FizzBuzz rules.
Palindrome number reverse.
GCD Euclid.
Two sum via hashmap.
Missing number sum formula.
Duplicates via sign marking.

You might also like