Notes, summaries, assignments, exams, and problems for Computers

Sort by
Subject
Level

Java AWT GUI Development and OOP Inheritance

Posted by Anonymous and classified in Computers

Written on in English with a size of 7.41 KB

Building Java GUI Applications with AWT

Creating GUI applications using Abstract Window Toolkit (AWT) involves setting up a top-level container, adding components, arranging them with a Layout Manager, and making the container visible.

Steps to Create an AWT Application

1. Choose a Top-Level Container

The application needs a primary window to hold all components. The most common choice is the Frame class, which provides a title bar, borders, and window controls.

import java.awt.*;

// Class extends Frame to be the application window itself
public class AWTExample extends Frame {
    // Constructor and other methods
}

2. Initialize the Container (The Frame)

Inside the constructor, you set up the basic properties of the window:

  • Title: Set the window
... Continue reading "Java AWT GUI Development and OOP Inheritance" »

Database Fundamentals: SQL Queries and Relational Concepts

Posted by Anonymous and classified in Computers

Written on in English with a size of 99.31 KB

Core Database Concepts and Relational Algebra

Question 1: Cartesian Product Size

Question 1: S is a relation instance. If S has 6 tuples, how many tuples are there in the result of the following SQL query?

SELECT * FROM S S1, S S2;

Answer: 36 (Calculated as 6 * 6, representing the Cartesian product of S with itself.)

Question 2: Maximum Tuples and Primary Keys

Question 2: Let R(A, B, C, D) be a relation, where (A, B, C) is the Primary Key (PK) of R, and attribute D cannot be NULL. Assume A's domain has 5 different values, B's domain has 2, C has 4, and D has 3. What is the maximum number of tuples that can be in an instance of R?

Answer: 40 (Calculated as 5 * 2 * 4. The maximum number of tuples is determined by the product of the domain sizes of the... Continue reading "Database Fundamentals: SQL Queries and Relational Concepts" »

C++ & C Programming Solutions: Algorithms & Patterns

Classified in Computers

Written on in English with a size of 5.13 KB

1. Anagram Detection: C++ String Comparison

This C++ program determines if two input strings are anagrams of each other. It achieves this by converting both strings to lowercase, sorting their characters alphabetically, and then comparing the sorted strings. If they are identical, the original strings are considered anagrams.


#include<bits/stdc++.h>
using namespace std;

int main(){
    string s2,s1;
    cin>>s1>>s2;
    transform(s1.begin(),s1.end(),s1.begin(),::tolower);
    transform(s2.begin(),s2.end(),s2.begin(),::tolower);
    sort(s1.begin(),s1.end());
    sort(s2.begin(),s2.end());
    cout<< (s2==s1);
}

2. Array Subarray: C++ Sliding Window Minimum

This C++ program attempts to find the maximum of minimums within... Continue reading "C++ & C Programming Solutions: Algorithms & Patterns" »

Essential Linux Commands & System Administration Toolkit

Classified in Computers

Written on in English with a size of 7.26 KB

File Operations

  • ls — List files and directories (-a for hidden, -l for detailed)
  • cd [directory] — Change directory
  • mkdir [directory] — Create directory
  • cp [source] [destination] — Copy files/directories (-r for recursive)
  • mv [source] [destination] — Move or rename files/directories
  • rm [file] — Remove files (-r for recursive)
  • chmod [permissions] [file] — Change file permissions
  • chown [user]:[group] [file] — Change file ownership

System Monitoring

  • top / htop — Monitor system processes
  • ps — List running processes
  • df -h — Display disk space usage
  • free -m — Show memory usage

Networking Commands

  • ifconfig / ip a — Display network interfaces
  • ping [host] — Test network connectivity
  • netstat -tuln — List network connections
  • nmap [IP] — Scan
... Continue reading "Essential Linux Commands & System Administration Toolkit" »

Java Programming Essentials: Exceptions, Threads, Events, and Adapters

Posted by Anonymous and classified in Computers

Written on in English with a size of 7 KB

Core Java Programming Concepts Explained

Key Java Definitions

  • Exception: An event that disrupts the normal flow of a program's instructions.
  • Thread: A lightweight subprocess enabling multitasking within a program.
  • Event Handling: Implemented using listeners and event classes that respond to user actions.
  • Applet: A small Java program embedded in a web page for interactive content.
  • Remote Applets: Used to download and execute applets from a web server over the internet.
  • Applet Parameters: Passed to applets using <PARAM> tags in HTML, accessed via the getParameter() method.
  • Daemon Thread: Runs in the background for services like garbage collection and ends when main threads finish.
  • Thread Synchronization Advantages:
    • Prevents thread interference.
    • Ensures
... Continue reading "Java Programming Essentials: Exceptions, Threads, Events, and Adapters" »

Digital Hardware Design Reference: SystemVerilog and Architecture Fundamentals

Posted by Anonymous and classified in Computers

Written on in English with a size of 11.13 KB

SystemVerilog Fundamentals

  • logic Data Type: Supports 4 states (0, 1, X, Z).
  • Legacy Types: Replace old Verilog reg/wire with logic in SystemVerilog (SV).
  • Always Blocks

    • Combinational Logic: always_comb begin ... end
    • Sequential Logic: always_ff @(posedge clk or posedge rst) begin ... end
  • Assignments

    • Blocking Assignment (=): Sequential execution. Use in combinational logic (always_comb).
    • Non-blocking Assignment (<=): Parallel execution. Essential for sequential logic (always_ff).
  • Module Definition Example

    module m(input logic a, b, output logic y);
    assign y = a & b;
    endmodule
  • Concatenation: {a, b, c}
  • Replication: {8{in[7]}} (Repeats the specified bit 8 times, often used for sign extension).

Testbench Development

  • Instantiate the Device Under Test (DUT) inside
... Continue reading "Digital Hardware Design Reference: SystemVerilog and Architecture Fundamentals" »

Understanding Servlet Architecture for Java Web Apps

Posted by Anonymous and classified in Computers

Written on in English with a size of 3.4 KB

Understanding Servlet Architecture for Java Web Applications

Servlet architecture is a core component of Java EE (Enterprise Edition) used for building dynamic web applications. A Servlet is a Java class that runs on a web server and acts as a middle layer between client requests (typically from a browser) and server responses (usually from a database or application logic).

What is a Servlet?

A Servlet is a Java class used to handle HTTP requests and responses in web applications. It runs on a server, receives requests from a client (usually a browser), processes them (e.g., reads form data, interacts with a database), and sends back a dynamic response (like HTML or JSON).

Key Components of Servlet Architecture

  • Client (Browser): Sends an HTTP request
... Continue reading "Understanding Servlet Architecture for Java Web Apps" »

C# Design Patterns: Essential Reference for Developers

Posted by Anonymous and classified in Computers

Written on in English with a size of 12.41 KB

C# Design Patterns: Essential Reference

Creational Design Patterns

PatternWhen to UseKey Implementation
SingletonNeed exactly one instance globally accessible.private static Singleton _instance;
public static Singleton Instance => _instance ??= new Singleton();
FactoryCreate objects without specifying concrete classes.public static IProduct Create(string type) => type switch { "A" => new ProductA(), ... }
BuilderConstruct complex objects step-by-step.public class CarBuilder { ... public CarBuilder WithEngine(...) { ... } }
PrototypeClone existing objects instead of creating new ones.public interface IPrototype { IPrototype Clone(); }

Structural Design Patterns

PatternWhen to UseKey Implementation
AdapterMake incompatible interfaces work together.
... Continue reading "C# Design Patterns: Essential Reference for Developers" »

Array and String Algorithms: Core Problem Solutions

Classified in Computers

Written on in English with a size of 6.48 KB


Longest Substring Without Repeating Characters

This problem involves finding the length of the longest substring in a given string that does not contain any repeating characters. A common approach uses a sliding window technique with a Set to efficiently track unique characters.

Strategy:

  • Utilize a Set to store characters within the current window.
  • Iterate through the string with a right pointer, adding characters to the Set.
  • If a duplicate character is encountered, move the left pointer forward, removing characters from the Set, until the duplicate is no longer present.
  • At each step, update the maximum length found.

Java Implementation Snippet

class Solution {
    public int findLongestSubstringWithoutRepeatingCharacter(String str) {
        Set&
... Continue reading "Array and String Algorithms: Core Problem Solutions" »

Tensors and Variables in PyTorch and TensorFlow

Classified in Computers

Written on in English with a size of 2.4 KB

Tensors and Variables in PyTorch and TensorFlow

Here's a brief explanation of tensors and variables in the context of deep learning frameworks like PyTorch and TensorFlow:

Tensors

  • Definition: A tensor is a multi-dimensional array used to represent data (such as scalars, vectors, matrices, or higher-dimensional data).
  • Common Operations: Tensors can be manipulated with mathematical operations (addition, multiplication, etc.), reshaped, sliced, etc.

In PyTorch, tensors are the core data structure:

import torch
# Create a tensor
a = torch.tensor([[1, 2], [3, 4]])
# Basic operations
b = a + 2         # Adds 2 to each element
c = a * a         # Element-wise multiplication
d = a @ a         # Matrix multiplication

Output:

Tensor `b`: [[3, 4], [5, 6]]
Tensor
... Continue reading "Tensors and Variables in PyTorch and TensorFlow" »