Notes, summaries, assignments, exams, and problems for Computer science

Java Arrays and ArrayLists: Essential Concepts and Fixes

Computer science3.32 KB

Section 1: Java Array Fundamentals

  1. An array is a collection of elements of the same data type stored in one variable.
  2. The index of the first element is 0.
  3. The correct declaration is: int[] arr = new int[5];
  4. The size of the array is 10.
  5. The best loop for arrays is a for loop.
  6. A 2D array represents a table.
  7. ArrayList belongs to java.util.
  8. ArrayList can store objects.
  9. The method used to add an element is add().
  10. arr.length gives the size of the array.

Section 2: Array Properties

  1. Arrays store elements of the same type.
  2. The last index of an array of size n is n - 1.
  3. A 2D array is also called a two-dimensional array.
  4. ArrayList size can grow dynamically.
  5. The loop used to traverse arrays is usually a for loop.

Section 3: Advanced Array Concepts

  1. A 1D array is a list of
...
Continue reading "Java Arrays and ArrayLists: Essential Concepts and Fixes" »

Class 11 Computer Science: JavaScript and HTML5 Essentials

Computer science2.76 KB

Class 11 Computer Science: Exam-Ready JavaScript and HTML5

Here are concise, exam-ready answers for your Class 11 Computer Science Question Bank:

1. What is Client-Side Scripting?

Client-side scripting refers to programs executed on the user's browser (the client) rather than the server. JavaScript is the most common example. It is used to create interactive web pages, validate forms, and reduce server load.

2. How to Declare a Variable in JavaScript

Variables are containers for storing data. In JavaScript, they are declared using three keywords:

  • var: Used in older versions (function-scoped).
  • let: Used for block-scoped variables (recommended).
  • const: Used for variables whose values remain constant.

Example: let name = "Arsh";

3. JavaScript Data Types

JavaScript...

Continue reading "Class 11 Computer Science: JavaScript and HTML5 Essentials" »

JDBC Drivers, JSP Tags, and ResultSet Implementation

Computer science2.86 KB

JDBC Driver Types

Type 1: JDBC-ODBC Bridge

  • Converts JDBC calls to ODBC
  • ❌ Slow, platform dependent, and obsolete

Type 2: Native API Driver

  • Uses database-specific native libraries
  • ⚠️ Faster than Type 1 but platform dependent

Type 3: Network Protocol Driver

  • Uses middleware server to connect
  • 🌐 Platform independent but slower due to network

Type 4: Thin Driver

  • Directly connects to database using pure Java
  • ✅ Fast, platform independent, and most used

Tags in JSP

1. Directive Tags

  • Provide instructions to the JSP container
  • Syntax: <%@ ... %>
  • Example: page, include, taglib

2. Scripting Tags

  • Scriptlet Tag: Write Java code <% ... %>
  • Expression Tag: Display output <%= ... %>
  • Declaration Tag: Declare variables or methods <%! ... %>

3. Action

...
Continue reading "JDBC Drivers, JSP Tags, and ResultSet Implementation" »

Essential Java Programming Concepts and Design Patterns

Computer science237.87 KB

Java File Copy Program

This simple Java program demonstrates how to read data from one file and write it to another.

import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class FileCopy {
    public static void main(String[] args) {
        String sourceFile = "input.txt";
        String destinationFile = "output.txt";
        try {
            FileReader fr = new FileReader(sourceFile);
            FileWriter fw = new FileWriter(destinationFile);
            int character;
            while ((character = fr.read()) != -1) {
                fw.write(character);
            }
            fr.close();
            fw.close();
            System.out.println("File copied successfully.");
        } catch (IOException
...
Continue reading "Essential Java Programming Concepts and Design Patterns" »

Key C++ Programming Principles and Comparisons

Computer science2.99 KB

1) What is C++? Advantages of C++

C++ is an object-oriented programming language developed by Bjarne Stroustrup. It is an extension of the C language.

Advantages:

  • Supports Object-Oriented Programming.
  • Code reuse using inheritance.
  • Fast execution.
  • Data security through encapsulation.
  • Portable language.
  • Supports function and operator overloading.

2) Difference Between Procedural and Object-Oriented Programming

Procedural ProgrammingObject-Oriented Programming
Program divided into functionsProgram divided into objects
Top-down approachBottom-up approach
Less data securityMore data security
Example: CExample: C++

3) Six Advantages of OOP

  1. Data hiding provides security.
  2. Code reusability using inheritance.
  3. Easy program maintenance.
  4. Reduces program complexity.
  5. Easy debugging.
...
Continue reading "Key C++ Programming Principles and Comparisons" »

Sorting Algorithms and Hashing Techniques

Computer science1.17 MB

Sorting

Stable vs In-Place

Stable: The relative order of elements with the same key value is preserved by the algorithm.

If after the first sort, an element is at its final position and subsequent iterations do not change its position, it is considered stable.

In-Place: Requires only a constant amount, i.e., O(1), of extra space during the sorting process.

Assigning a temporary variable takes up a small amount of constant space but is still counted as in-place.

sy6xAAAAABJRU5ErkJggg==

tjMaqeYQAAAABJRU5ErkJggg==

Sorting Explanations

Merge Sort: For arrays, it requires significant space, but for Linked Lists, due to pointer manipulations, it does not require extra space.

Selection Sort: In each iteration, find the smallest element and swap it with the first index. Subsequent iterations process n-1 elements...

Continue reading "Sorting Algorithms and Hashing Techniques" »

Essential C++ Programming Examples and Database Concepts

Computer science78.88 KB

1. C++ Pointer Declaration and Initialization

Ans:

#include <iostream>
using namespace std;

int main() {
    int num = 10;
    int *ptr = &num;
    cout << "Value of num: " << num << endl;
    cout << "Address of num: " << &num << endl;
    cout << "Pointer ptr stores: " << ptr << endl;
    cout << "Value pointed by ptr: " << *ptr << endl;
    return 0;
}

2. C++ Program to Add Two 4x4 Matrices

Ans:

#include <iostream>
using namespace std;

int main() {
    int A[4][4], B[4][4], C[4][4];
    cout << "Enter elements of first 4x4 matrix:\n";
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 4; j++) {
            cin >> A[i][j];
...
Continue reading "Essential C++ Programming Examples and Database Concepts" »

C Program for Cinema Hash File Management with Overflow Handling

Computer science6.67 KB

C Program for Hash-Based Cinema File Management

The following C program implements a hash file with buckets and an overflow area for managing cinema screening records.

Source Code

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define B 7
#define B_SIZE 5
#define F_NAME "bioskop.dat"
#define O_NAME "prekoracenje.dat"

typedef struct{int idp;char naz[65],ozs[4],dvp[20];int brk,tra;char akt;}Slog;
typedef struct{Slog slogovi[B_SIZE];}Baket;

int hash(int idp){return idp%B;}

File Initialization

void inicijalizuj(){
FILE *f=fopen(F_NAME,"wb"); Baket prazan; memset(&prazan,0,sizeof(Baket));
for(int i=0;i<B;i++) fwrite(&prazan,sizeof(Baket),1,f);
fclose(f); f=fopen(O_NAME,"wb"); if(f) fclose(f);
}

Forming the File

...
Continue reading "C Program for Cinema Hash File Management with Overflow Handling" »

Essential C Programming Examples and Algorithms

Computer science72.94 KB

wfSCE5je3rPDgAAAABJRU5ErkJggg==

Leap Year

#include <stdio.h>
int main() {
    int y;
    scanf("%d", &y);
    if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
        printf("Leap Year");
    else
        printf("Not Leap Year");
    return 0;
}

Simple Calculator Using Switch

#include <stdio.h>
int main() {
    char op;
    float a, b;
    scanf(" %c %f %f", &op, &a, &b);
    switch (op) {
        case '+': printf("%.2f", a + b); break;
        case '-': printf("%.2f", a - b); break;
        case '*': printf("%.2f", a * b); break;
        case '/':
            if (b != 0)
                printf("%.2f", a / b);
            else
                printf("Error");
            break;
        default: printf("Invalid Operator");
    }
    return
...
Continue reading "Essential C Programming Examples and Algorithms" »

Computer Architecture and Organization Fundamentals

Computer science94.38 KB

Computer Architecture vs. Computer Organization

Computer ArchitectureComputer Organization
Deals with functional behaviorDeals with structural relationships
Visible to programmer (instruction set, addressing modes)Invisible to programmer (control signals, memory technology)
Describes WHAT the system doesDescribes HOW it is implemented
Example: x86 architectureExample: Intel Core i7 vs. Pentium

IEEE 754 Floating Point Bias

  • Single Precision (32-bit): Bias = 127 (27 - 1)
  • Double Precision (64-bit): Bias = 1023 (210 - 1)

Why Bias is Used

Bias allows storing both positive and negative exponents using only unsigned integers. Instead of storing the actual exponent, we store (exponent + bias), which is always positive. This simplifies the comparison of floating-...

Continue reading "Computer Architecture and Organization Fundamentals" »