Java and Object-Oriented Design - Study Notes
1. Variables and Assignments
- Variables store data that can be used and manipulated in a program.
- Assignment assigns a value to a variable using =.
Example: int x = 10; assigns 10 to the variable x.
2. Internet
- A global network that connects computers, allowing them to share data and resources.
- Protocols like HTTP and TCP/IP define the communication between systems on the internet.
3. Java as a Tool for Internet Applications
- Java is widely used for web-based applications due to its portability (can run on any platform with a
JVM).
- Java provides built-in support for internet protocols (HTTP, FTP).
- Java Applets (now deprecated) were once used to run small programs within browsers.
4. Byte Code and Its Advantages
- Byte Code: Intermediate code generated by the Java compiler.
- Advantages:
- Platform independence (runs on any system with JVM).
- Security (runs in a controlled environment).
- Portability (no need to recompile for different platforms).
5. Input and Output
- Input: Reading data from the user, typically using Scanner class (Scanner sc = new
Scanner(System.in);).
- Output: Displaying data to the user, using System.out.println() for console output.
6. Data Types and Expressions
- Primitive data types: int, char, float, boolean, etc.
- Expressions: Combinations of variables, operators, and values that evaluate to a single value.
Example: int result = 5 + 3; (expression 5 + 3 evaluates to 8).
7. Flow of Control
- Conditional Statements: if, else, switch.
- Loops: for, while, do-while loops control the repeated execution of code.
Example: for (int i = 0; i < 10; i++) {}
8. Local Variables
- Variables declared within a method and accessible only within that method.
9. Overloading
- Defining multiple methods with the same name but different parameter lists.
Example:
void add(int a, int b) { }
void add(float a, float b) { }
10. Parameter Passing
- Pass by Value: Java passes parameters by value, meaning it passes a copy of the variable to the
method.
11. this Pointer
- Refers to the current object instance. It helps to distinguish between instance variables and local
variables when they have the same name.
Example:
class Test { int x; Test(int x) { this.x = x; } }
12. Abstraction
- Hiding the implementation details and showing only the functionality.
Example: Using a Car object without knowing the details of its internal engine mechanics.
13. Objects and Basics
- Object: Instance of a class.
- Class: Blueprint for creating objects, defining properties (fields) and methods (functions).
14. Encapsulation
- Wrapping data (variables) and methods into a single unit (class) and restricting access using
access modifiers (like private).
15. Information Hiding
- Keeping details of an object's implementation hidden from the user to reduce complexity.
16. Method Signature
- The combination of the method's name and the parameter list.
Example: void add(int a, int b) is a method signature.
17. Classes and Instances
- Class: Defines the structure and behavior of objects.
- Instance: A specific object created from a class.
18. Polymorphism
- The ability of a method to do different things based on the object that it is acting upon.
- Method Overriding: Subclass provides a specific implementation of a method already defined in its
superclass.
19. Inheritance
- A class (subclass) inherits properties and behaviors (methods) from another class (superclass).
Example: class Animal { } class Dog extends Animal { }
20. Exceptions and Exception Handling
- Exceptions: Errors that occur during the execution of a program.
- Handling: Using try, catch, finally blocks to handle exceptions and prevent the program from
crashing.
Example: try { int x = 1/0; } catch (Exception e) { System.out.println(e); }
21. Coupling and Cohesion in Object-Oriented Software
- Coupling: Degree of dependency between classes. Aim for low coupling.
- Cohesion: How well the elements within a module/class belong together. Aim for high cohesion.
22. Object-Oriented Design - Process, Exploration, and Analysis
- Involves identifying the objects and defining their relationships and interactions.
- Process: Analyze the requirements, explore the design options, and create a solution.
- Exploration: Experiment with different ways to model the system.
- Analysis: Understand how the design meets the requirements and what needs refinement.