0% found this document useful (0 votes)
56 views2 pages

Java Modularization: Notes & Examples

Uploaded by

chandrakant More
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)
56 views2 pages

Java Modularization: Notes & Examples

Uploaded by

chandrakant More
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

Modularization in Java – Complete Notes (Short + Detailed + Examples)

SECTION 1: Short 4–6 Marks Notes


• Modularization means dividing program into small modules.
• Package = group of related classes ([Link], [Link]).
• import keyword used to access classes from packages.
• static methods/fields belong to class, shared across objects.
• Scope: local, instance, static, parameter.
• Method overloading: same name, different parameters.
• Java API packages: [Link], [Link], [Link], [Link].

SECTION 2: Detailed 8–10 Marks Notes


1. Java Package
A package groups related classes to provide modularity, reusability, and to avoid naming conflicts.
Types:
- Built■in Packages: [Link], [Link], [Link], [Link]
- User■Defined Packages: created by the programmer.

2. Importing Packages
To use classes from other packages:
import [Link];
import [Link].*;

3. Methods: Static Methods


Static methods belong to the class, not objects, and can be called without creating an object.
Example: [Link](), [Link]()

4. Static Fields
Static fields are shared by all objects of a class.

5. Scope of Declaration
- Local: inside method
- Instance: inside class, outside method
- Static: declared with static keyword
- Parameter: in method signature

6. Method Overloading
Same method name with different parameters (type, number, order). Increases readability and
flexibility.

SECTION 3: Examples and Diagrams

Example – Package & Import:


package mypack;
public class A { public void show() { [Link]("Hello"); }}

import mypack.A;
class Demo {
public static void main(String[] args) {
A obj = new A();
[Link]();
}
}

Example – Static Methods & Fields:


class Counter {
static int count = 0;
Counter() { count++; }
}

Example – Method Overloading:


class Add {
int add(int a, int b){ return a+b; }
double add(double a, double b){ return a+b; }
}

Java API Packages:


• [Link] – String, Math, System
• [Link] – Scanner, ArrayList
• [Link] – File handling
• [Link] – GUI
• [Link] – networking

You might also like