1.
Programming Concepts
Definitions:
• Programming: Writing instructions for a computer to perform specific tasks.
• Algorithm: A step-by-step procedure to solve a problem.
• Source Code: Human-readable code written in a programming language.
• Object Code: The output of a compiler that is in machine-readable format.
• Machine Code: Low-level code executed directly by the computer’s CPU.
• Executable: A file that can be run by a computer to perform programmed tasks.
• Compiling: The process of translating source code into machine code or bytecode.
• Debugging: The process of finding and fixing errors or bugs in a program.
Phases of Program Development:
1. Establish Program Requirements: Define what the program needs to accomplish.
2. Design a Program: Plan the structure using algorithms or flowcharts.
3. Coding: Write the program in a programming language.
4. Testing & Debugging: Run the program to find and fix issues.
5. Documentation: Write detailed explanations for future reference.
6. Maintenance: Update the program as needed over time.
2. Java Environment
Java Installation & Setup:
• JDK (Java Development Kit): Tools for developing Java programs, including a
compiler.
• Eclipse IDE: An integrated development environment (IDE) used for writing and
running Java programs.
• Environment Variables: Settings that help the computer locate Java tools during
execution.
Java Features:
• Platform Independence: "Write once, run anywhere" capability via the Java Virtual
Machine (JVM).
• Object-Oriented: Java is built on classes and objects, encouraging modular, reusable
code.
Java Syntax:
• Case Sensitivity: Java is case-sensitive (e.g., variable and Variable are different).
• Class Names: Should start with an uppercase letter (MyClass).
• Method Names: Should start with a lowercase letter (calculateSum).
• Program File Name: Must match the public class name and end with .java.
• Public static void main(String[] args): The entry point for all Java programs.
3. Data Operations
Data Types:
• Primitive Data Types:
o int: Integer values.
o float: Floating-point numbers.
o boolean: True or false values.
o char: Single characters.
• String: A sequence of characters (e.g., "Hello").
Variables:
• Local Variables: Variables declared inside methods.
• Class Variables: Declared with static in the class.
• Instance Variables: Variables unique to each object instance.
Constants:
• Final Variables: Use final to declare constants that cannot be changed (e.g., final
int MAX = 100;).
Statements:
• Expression Statements: Assignments or method calls (e.g., x = 5;).
• Declaration Statements: Declaring variables (e.g., int a;).
• Control-Flow Statements: Direct the flow of execution (e.g., if, for, while).
Java Data Operations:
• Assignment: Assign values to variables (e.g., x = 10;).
• Arithmetic Operations: Perform math operations (+, -, *, /).
• Object Instantiation: Create an object using new (e.g., Person p = new
Person();).
4. Control Structures
Control Statements:
• Decision Making:
o if-else: Executes code based on conditions.
o switch: Chooses one of many code blocks to execute.
• Loops:
o for: Repeats code a fixed number of times.
o while: Repeats code while a condition is true.
o do-while: Executes code at least once before checking the condition.
• Branching:
o break: Exits a loop or switch statement.
o continue: Skips the current iteration of a loop.
Examples:
• if-else:
java
Copy code
if (age > 18) {
System.out.println("Adult");
} else {
System.out.println("Minor");
}
• for loop:
java
Copy code
for (int i = 0; i < 5; i++) {
System.out.println(i);
}
5. Methods
Method Basics:
• Definition: A block of code that performs a specific task.
• Method Structure:
java
Copy code
returnType methodName(parameters) {
// code
}
• Void Methods: Methods that do not return a value.
• Return Methods: Methods that return a value (e.g., int, String).
• Method Overloading: Creating multiple methods with the same name but different
parameters.
• Passing Parameters: Methods can take parameters as input.
Examples:
• Method Creation:
java
Copy code
public int addNumbers(int a, int b) {
return a + b;
}
• Method Overloading:
java
Copy code
public int add(int a, int b) {
return a + b;
}
public float add(float a, float b) {
return a + b;
}
6. Object-Oriented Programming (OOP)
OOP Concepts:
• Class: A blueprint for creating objects (e.g., class Car { }).
• Object: An instance of a class.
• Inheritance: A subclass inherits properties and methods from a superclass (e.g.,
class Dog extends Animal { }).
• Encapsulation: Keeping data safe by using private variables and public methods to
access them.
• Abstraction: Hiding complex details and showing only necessary features.
• Polymorphism: One method can have different behaviors based on the object that
calls it.
Examples:
• Class and Object:
java
Copy code
class Car {
String model;
void start() {
System.out.println("Car started");
}
}
Car myCar = new Car();
myCar.start();
• Inheritance:
java
Copy code
class Animal {
void sound() {
System.out.println("Animal makes a sound");
}
}
class Dog extends Animal {
void sound() {
System.out.println("Dog barks");
}
}
Java Keywords to Remember:
• public, private, protected: Access modifiers.
• static: Allows a method or variable to belong to the class, not instances.
• final: Used to declare constants or prevent inheritance.
• abstract: Used to define abstract methods or classes.
• this: Refers to the current object instance.
• new: Used to create new objects.
Cheat Sheet Summary:
• Key Terms: Understand definitions like algorithms, source code, object code,
machine code, compiling, and debugging.
• Data Types & Variables: Remember the different types of variables and how to
declare and assign them.
• Control Structures: Know how to use decision-making (if, switch), loops (for,
while), and branching (break, continue).
• Methods: Understand how to define methods, pass parameters, and use method
overloading.
• OOP Concepts: Grasp the basics of inheritance, encapsulation, abstraction, and
polymorphism.
• Java Syntax: Be aware of case sensitivity, class names, method names, and file
naming conventions.