compappln
compappln
Principles of OOP:
Short Note: OOP helps in better code organization, reusability, and security. It makes software
development more efficient and maintainable.
2. Java Basics
Example:
class Car {
String model;
void display() {
}
}
Definition: A class is a template for creating objects, which contain both data members (variables) and
methods (functions).
Short Note: A class is like a template, while objects are real-world entities created from that template.
Definition: A data type defines the kind of data a variable can store, such as integers, floating-point
numbers, or characters.
Short Note: Primitive data types store simple values, while non-primitive types store complex data
structures.
import java.util.Scanner;
double d = sc.nextDouble();
String s = sc.next();
Printing Output:
System.out.println("Hello World");
Definition: The Scanner class in Java is used to take input from the user during program execution.
Short Note: Scanner class is used for user input, while System.out.println() is used for displaying
output.
4. Control Structures
Conditional Statements
if Statement:
if (x > 0) {
System.out.println("Positive");
switch-case:
switch (day) {
default: System.out.println("Invalid");
Definition: Control structures allow a program to make decisions and execute different code based on
conditions.
5. Loops in Java
for Loop:
System.out.println(i);
while Loop:
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
Definition: A loop is a control structure that repeats a block of code until a specified condition is met.
Definition:
return a + b;
Method Overloading:
return a * b;
}
return a * b;
Definition: A method in Java is a block of code that performs a specific task and can be called multiple
times in a program.
7. Arrays
Single-Dimensional Array:
arr[j] = arr[j+1];
arr[j+1] = temp;
Definition: An array is a collection of elements of the same data type stored in contiguous memory
locations.
Short Note: Arrays store multiple values in a single variable and help in organizing data efficiently.
class Example {
Definition: Encapsulation is the process of wrapping data (variables) and methods into a single unit
called a class.
Short Note: Encapsulation hides data within a class, improving security and modularity.
Definition: Cyber Security refers to the protection of internet-connected systems, including hardware,
software, and data, from cyber threats.
Short Note: Ethical computing ensures responsible and legal use of technology.