Java Programming CSC 321
Java Programming CSC 321
Core Components
1. Java Development Kit (JDK): Includes the tools needed to write and
test Java programs.
2. Java Runtime Environment (JRE): Provides the libraries, JVM, and
other components to run Java applications.
3. Java Virtual Machine (JVM): Executes Java bytecode on any device or
operating system.
Basic Concepts
Example Code
Here's a simple Java program that prints "Hello, World!" to the console:
java
A Java program typically consists of classes and methods. Each Java application
must have at least one class and one main method, which serves as the entry
point of the program.
Syntax in Java
Syntax in Java refers to the set of rules that defines the structure and
composition of valid statements and expressions in the language. It dictates how
various programming constructs should be arranged to form a correctly
structured Java program.
1. Encapsulation
2. Inheritance
3. Polymorphism
Polymorphism allows methods to do different things based on the object it is
acting upon, even though they share the same name. It can be achieved in two
ways: method overriding (runtime polymorphism) and method overloading
(compile-time polymorphism).
4. Abstraction
Key Concepts:
1. Classes and Objects: Programs are structured around objects, which are
instances of classes.
2. Encapsulation: Data and methods are bundled into classes, with access
control mechanisms.
3. Inheritance: Classes can inherit properties and behaviors from other
classes.
4. Polymorphism: Methods can behave differently based on the objects
they act upon.
5. Abstraction: Complex details are hidden, exposing only the necessary
parts.
Benefits:
Procedural Programming
Key Concepts:
Benefits:
Contrasts:
1. Approach to Design:
o OOP: Focuses on modeling real-world entities as objects,
promoting a more intuitive mapping between real-world concepts
and program structures.
o Procedural: Focuses on a sequence of tasks or operations,
emphasizing the flow of control and sequence of function calls.
2. Data and Behavior:
o OOP: Data and behavior are bundled together within objects. The
state of an object is modified through its methods.
o Procedural: Data and functions are separate. Functions operate on
data, and the data state is managed globally or passed around.
3. Complexity Management:
o OOP: Better suited for managing complexity in large systems
through abstraction, encapsulation, and modularity.
o Procedural: Can lead to "spaghetti code" in large systems due to
less emphasis on modularity and data encapsulation.
4. Reusability and Extensibility:
o OOP: High, due to inheritance and polymorphism. New features
can be added with minimal changes to existing code.
o Procedural: Lower, as code reuse is limited to function calls and
often requires significant changes for new features.