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

MIT CS 101 Java Basics and OOP Concepts Review Notes

This document provides a comprehensive overview of Java programming basics and object-oriented programming (OOP) concepts, covering topics such as syntax, data types, control flow, methods, and exception handling. It includes sample code snippets, concept diagrams, and review questions to reinforce learning. Key OOP principles like encapsulation, inheritance, and polymorphism are also discussed.
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)
14 views5 pages

MIT CS 101 Java Basics and OOP Concepts Review Notes

This document provides a comprehensive overview of Java programming basics and object-oriented programming (OOP) concepts, covering topics such as syntax, data types, control flow, methods, and exception handling. It includes sample code snippets, concept diagrams, and review questions to reinforce learning. Key OOP principles like encapsulation, inheritance, and polymorphism are also discussed.
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

MIT CS 101: Java Programming Basics and

OOP Concepts - Review Notes


Table of Contents
1. Introduction to Java Programming
2. Java Syntax and Structure
3. Variables and Data Types
4. Operators and Control Flow
5. Methods and Parameters
6. Arrays and Collections
7. Object-Oriented Programming (OOP) Concepts
8. Java Classes and Objects
9. Inheritance and Polymorphism
10.Encapsulation and Abstraction
11.Exception Handling Basics
12.Sample Programs and Code Snippets
13.Concept Summary Diagrams
14.Review Questions and Exercises

1. Introduction to Java Programming


Java is a high-level, class-based, object-oriented programming language. It is designed to have as few
implementation dependencies as possible. It is widely used for building enterprise-scale applications,
Android apps, and web applications.

Key Features:
• Platform-independent (Write Once, Run Anywhere)
• Strongly typed
• Automatic memory management (Garbage Collection)
• Rich standard library
2. Java Syntax and Structure
A basic Java program structure includes:
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
}

Rules:
• Every application must have a main method.

• Class names must match the filename.


• Statements end with a semicolon.

3. Variables and Data Types


Java has two data types: primitive and reference.

Primitive Types:
• int, byte, short, long, float, double, char, boolean

Variable Declaration:
int age = 25;
float pi = 3.14f;
boolean isJavaFun = true;

4. Operators and Control Flow


Common Operators:
• Arithmetic: +, -, *, /, %

• Relational: ==, !=, >, <, >=, <=

• Logical: &&, ||, !

Control Flow Statements:


• if, else, switch

• for, while, do-while


if (age > 18) {
System.out.println("Adult");
}

5. Methods and Parameters


public int add(int a, int b) {
return a + b;
}

• Methods promote code reuse.


• Use return to send values back.

• Parameters can be primitive or reference types.

6. Arrays and Collections


Arrays:
int[] numbers = {1, 2, 3};

ArrayList (from java.util):


ArrayList<String> list = new ArrayList<>();
list.add("Java");

7. Object-Oriented Programming (OOP) Concepts


• Encapsulation: Wrapping data and code into a single unit.
• Abstraction: Hiding implementation details.
• Inheritance: Acquiring properties from a parent class.
• Polymorphism: One interface, multiple implementations.

8. Java Classes and Objects


public class Car {
String color;
int speed;

void drive() {
System.out.println("Driving at " + speed);
}
}

• Create object: Car myCar = new Car();

9. Inheritance and Polymorphism


Inheritance:
public class Animal {
void makeSound() {
System.out.println("Sound");
}
}
public class Dog extends Animal {
void makeSound() {
System.out.println("Bark");
}
}

• Dog overrides makeSound() method from Animal.

10. Encapsulation and Abstraction


Encapsulation:
public class Account {
private double balance;

public void deposit(double amount) {


balance += amount;
}
}

Abstraction:
abstract class Shape {
abstract void draw();
}

11. Exception Handling Basics


try {
int a = 10 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero");
} finally {
System.out.println("End of try block");
}

12. Sample Programs and Code Snippets


• Calculator program
• Sorting an array
• Student grade tracker

13. Concept Summary Diagrams


• Class hierarchy diagram
• Object interaction flow
• Encapsulation/Abstraction illustrated

14. Review Questions and Exercises


1. Define OOP and explain its principles.
2. Write a Java program to check if a number is prime.
3. Implement a class hierarchy for Employee, Manager, and Developer.

4. Practice polymorphism using method overriding.

You might also like