0% found this document useful (0 votes)
2 views5 pages

Java Concepts Notes

The document covers key concepts in Java programming, including exception handling with user-defined exceptions, threading with concurrent and parallel tasks, and basic file I/O operations. It also discusses Java Swing for GUI creation, generics for type safety, collections for data storage, and wrapper classes for primitive types. Additionally, it outlines fundamental features of object-oriented programming such as encapsulation, inheritance, and polymorphism.

Uploaded by

jaspinder1805
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)
2 views5 pages

Java Concepts Notes

The document covers key concepts in Java programming, including exception handling with user-defined exceptions, threading with concurrent and parallel tasks, and basic file I/O operations. It also discusses Java Swing for GUI creation, generics for type safety, collections for data storage, and wrapper classes for primitive types. Additionally, it outlines fundamental features of object-oriented programming such as encapsulation, inheritance, and polymorphism.

Uploaded by

jaspinder1805
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/ 5

1.

Exception Handling in Java

User-Defined Exceptions:

------------------------

You can create your own exception by extending the Exception class.

Example:

class MyException extends Exception {

public MyException(String message) {

super(message);

throw vs throws:

----------------

- throw: Used to actually throw an exception.

Example: throw new ArithmeticException("Divide by zero");

- throws: Declares that a method might throw an exception.

Example: void method() throws IOException

Numerical Exception:

--------------------

try {

int a = 10 / 0; // ArithmeticException

} catch (ArithmeticException e) {

System.out.println("Divide by zero error");

}
2. Threading

Concurrent vs Parallel:

------------------------

- Concurrent: Tasks appear to run simultaneously.

- Parallel: Tasks truly run at the same time on multiple cores.

Runnable Interface:

-------------------

class MyRunnable implements Runnable {

public void run() {

System.out.println("Runnable thread");

Thread Class:

-------------

class MyThread extends Thread {

public void run() {

System.out.println("Thread class");

3. Java IO

File Reading:
-------------

FileReader fr = new FileReader("test.txt");

File Writing:

-------------

FileWriter fw = new FileWriter("output.txt");

4. Java Swing

Example:

--------

JFrame f = new JFrame("Demo");

JButton b = new JButton("Click");

f.add(b);

5. Generics

Generic Class:

--------------

class Box<T> {

T value;

void set(T v) { value = v; }

T get() { return value; }

Generic Method:

---------------
<T> void display(T value) {

System.out.println(value);

6. Collections

List:

-----

List<String> list = new ArrayList<>();

Set:

----

Set<Integer> set = new HashSet<>();

Map:

----

Map<Integer, String> map = new HashMap<>();

7. Wrapper Class

Wrapper Example:

----------------

int a = 10;

Integer obj = a; // Autoboxing

Wrapped Collection:

-------------------
Collections.unmodifiableList(original);

8. Features of OOP

- Encapsulation

- Abstraction

- Inheritance

- Polymorphism

- Class & Object

- Modularity

- Message Passing

You might also like