Fundamentals 18 min read

Object-Oriented vs Procedural: Core Principles, Java Tips & IO Explained

This article compares object‑oriented and procedural programming, outlines the five SOLID principles, contrasts abstract classes with interfaces, and covers Java fundamentals such as constructors, variable scopes, static members, method return values, value passing, common packages, IO stream models, BIO/NIO/AIO differences, and essential Files API methods.

Intelligent Backend & Architecture
Intelligent Backend & Architecture
Intelligent Backend & Architecture
Object-Oriented vs Procedural: Core Principles, Java Tips & IO Explained

Overview of Object‑Oriented Programming

Object‑oriented programming (OOP) emphasizes encapsulation, inheritance, and polymorphism, enabling low‑coupling, flexible, and maintainable systems.

Procedural vs. Object‑Oriented

Procedural advantages: higher performance because no object instantiation overhead, making it suitable for embedded, microcontroller, or low‑level Linux/Unix development where speed is critical.

Procedural disadvantages: harder to maintain, reuse, and extend.

Object‑Oriented advantages: easier maintenance, reuse, and extension thanks to encapsulation, inheritance, and polymorphism.

Object‑Oriented disadvantages: lower performance compared to procedural code.

Procedural programming follows a concrete, step‑by‑step process, while OOP abstracts problems into classes that bundle data and behavior, allowing direct use of functionality without worrying about implementation details.

Five SOLID Principles (optional)

Single Responsibility Principle (SRP) : a class should have only one responsibility.

Open‑Closed Principle (OCP) : software entities should be open for extension but closed for modification.

Liskov Substitution Principle (LSP) : subclasses must be substitutable for their base classes.

Dependency Inversion Principle (DIP) : high‑level modules should depend on abstractions, not concrete implementations.

Interface Segregation Principle (ISP) : prefer many client‑specific interfaces over a single general‑purpose interface.

Abstract Class vs. Interface

Both cannot be instantiated and sit at the top of the inheritance hierarchy, requiring subclasses to implement abstract methods.

Key differences:

Declaration: abstract classes use the abstract keyword; interfaces use interface.

Implementation: subclasses extend an abstract class with extends; they implement an interface with implements.

Constructors: abstract classes can have constructors; interfaces cannot.

Access modifiers: abstract class methods can have any visibility; interface methods are implicitly public and cannot be private or protected.

Multiple inheritance: a class can extend only one abstract class but can implement multiple interfaces.

Field declarations: abstract class fields can be any type; interface fields are implicitly static and final.

Since Java 8, interfaces can contain default and static methods, reducing the gap between abstract classes and interfaces.

Guideline: prefer interfaces for defining behavior models; use abstract classes when you need to provide common functionality to subclasses.

Java Constructors and Initialization

If a subclass constructor does not explicitly call super(), the no‑argument constructor of the superclass is invoked automatically. If the superclass lacks a no‑argument constructor, you must add one or explicitly call a superclass constructor with arguments.

The purpose of the superclass’s no‑argument constructor is to perform initialization for the subclass.

A class without an explicit constructor still has a default no‑argument constructor generated by the compiler.

Variables and Scope

Member variables : declared inside a class but outside methods; stored in heap with each object; have default initial values.

Local variables : declared inside methods; stored on the stack; must be initialized before use.

Static variables : belong to the class itself; a single copy exists in memory; initialized once when the class is loaded.

Scope follows the “nearest principle”: the compiler searches first in the local scope, then in the member scope.

Static vs. Instance Methods

Static methods can be called using the class name without creating an object and can only access static members. Instance methods require an object and can access both static and instance members.

Calling a non‑static member from a static method is illegal because static context lacks an instance.

Method Return Values

A method’s return value is the result produced after the method’s execution, allowing the caller to use that result for further operations.

Parameter Passing in Java

Java uses call‑by‑value. When an object reference is passed as a parameter, the value of the reference is copied; the method can modify the object’s fields but cannot reassign the caller’s reference.

Java Packages

Commonly used packages include: java.lang: core language classes. java.io: input/output classes. java.nio: non‑blocking I/O enhancements. java.net: networking classes. java.util: utility and collection classes. java.sql: database access classes.

The original distinction between java and javax was that javax represented extensions; over time it became part of the standard API, so there is effectively no functional difference.

I/O Streams

Java I/O streams are classified by direction (input vs. output), unit (byte vs. character), and role (node vs. processing streams). The main abstract base classes are: InputStream / Reader: base classes for input streams (byte and character). OutputStream / Writer: base classes for output streams (byte and character).

Typical stream hierarchy can be visualized as:

Another view groups streams by the objects they operate on:

BIO, NIO, and AIO

BIO (Blocking I/O) : synchronous, blocking I/O; simple but limited concurrency.

NIO (Non‑Blocking I/O) : introduced in Java 1.4; provides channels, selectors, and buffers for multiplexed, non‑blocking operations.

AIO (Asynchronous I/O) : Java 7’s NIO 2; asynchronous, event‑driven I/O where operations return immediately and completion is notified via callbacks.

Common Files API Methods

Files.exists()

: check if a path exists. Files.createFile(): create a new file. Files.createDirectory(): create a new directory. Files.delete(): delete a file or directory. Files.copy(): copy a file. Files.move(): move a file. Files.size(): get the size of a file. Files.readAllBytes() / Files.readAllLines(): read file contents. Files.write(): write data to a file.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaprogrammingOOPioSOLID
Intelligent Backend & Architecture
Written by

Intelligent Backend & Architecture

We share personal insights on intelligent, automated backend technologies, along with practical AI knowledge, algorithms, and architecture design, grounded in real business scenarios.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.