We've moved! — MindVault360 is now SrcForge. Better design, more content & premium notes.

Visit SrcForge →

MindVault360 has moved!

We've upgraded to SrcForge — a faster, more professional platform with better content, premium notes, and a modern design.

Visit us at SrcForge

Tuesday, December 17, 2024

Wrapper Class


(Tap the post to see more)

It provides a way to use primitive data type as a reference data type.

Sample Program of wrapper class:

public class WrapperClassExample {

public static void main(String[] args) {

// Primitive data types

int intValue = 42;

double doubleValue = 3.14;

char charValue = 'A';


// Using wrapper classes

Integer integerObject = Integer.valueOf(intValue); // Wrapping int

Double doubleObject = Double.valueOf(doubleValue); // Wrapping double

Character charObject = Character.valueOf(charValue); // Wrapping char


System.out.println("Primitive Values:");

System.out.println("int: " + intValue);

System.out.println("double: " + doubleValue);

System.out.println("char: " + charValue);


System.out.println("\nWrapper Class Values:");

System.out.println("Integer: " + integerObject);

System.out.println("Double: " + doubleObject);

System.out.println("Character: " + charObject);


// Unwrapping - getting primitive values back

int unwrappedInt = integerObject.intValue();

double unwrappedDouble = doubleObject.doubleValue();

char unwrappedChar = charObject.charValue();


System.out.println("\nUnwrapped Values:");

System.out.println("Unwrapped int: " + unwrappedInt);

System.out.println("Unwrapped double: " + unwrappedDouble);

System.out.println("Unwrapped char: " + unwrappedChar);

}

}

← Back Next →

Labels:

Database Model

Relational and object-relational models were the basis for the development of database technology. The principal Below is a list of database models: 

Hierarchical Database model:

The famous Hierarchical database model was IMS(Information Management System). IBM's initial database management system. Each entry in this model contains information on the parent-child relationship in the form of a tree. In a relational model, the collection of records is referred to as record types, which are the same as tables. Each record is equivalent to a row.


There are numerous benefits to the aforementioned paradigm, including reduced redundant data, effective search, data integrity, and security.
A few other drawbacks of this approach are its complexity in implementation and its inability to manage many-to-many interactions.

Network Model:
Honeywell's IDS (Integrated Data Store) was the first network data model to be created. The network model is comparable to the hierarchical model, with the exception that each member may have several owners. The management of many-to-many relationships is improved. The three database components—Network schema, Sub schema, and Language for data management—were identified by this paradigm.



  • Network schema – schema defines all about the structure of the database.
  • Sub schema – control on views of the database for the user
  • Language – basic process for accessing the database.
This model's main benefits are its capacity to manage a wider variety of relationship kinds, as well as its ease of access, independence, and data integrity. The network model's design and maintenance challenges are its drawback.

Relational Model:
A couple of the commercial relational models in use include Oracle and DB2. Instance and schema are the two terms used to define a relational model.



  • Instance – A table consisting of rows and columns
  • Schema – Specifies the structure including name and type of each column.
 A relation (table) consists of unique attributes (columns) and tuples (rows).

Object-oriented database model:
This paradigm combines database technologies with the ideas of object-oriented programming, or OOP. In practice, this model forms the foundation of the relational model. Objects are tiny, reusable pieces of software used in this model. An object-oriented database houses these. This model effectively handles a wide variety of data formats. Furthermore, OOP's ideas are effective in handling complicated behaviors.




← Back Next →

Labels:

Conditional Statements

Depending on whether a condition is true or false, conditional statements let you run specific code blocks. If, elif, and else are Python's main conditional statements.

if statement: When a condition is checked by the if statement and found to be True, the corresponding block of code is run.

Example:

x = 10

if x > 5:

    print("x is greater than 5")

if-else Statement: when a condition is satisfied a specific code is executed and if the condition false the else block will be executed.

Example:
x = 3
if x > 5:
    print("x is greater than 5")
else:
    print("x is less than or equal to 5")

if-elif-else Statement: when we need to check for multiple condition, we can use this elif statement.

Example:
x = 7
if x > 10:
    print("x is greater than 10")
elif x == 7:
    print("x is equal to 7")
else:
    print("x is less than 7")

Nested if Statements: If statements can also be nested inside other if or else blocks. More complicated situations are made possible by this.

Example:
x = 8
if x > 5:
    if x < 10:
        print("x is between 5 and 10")

Switch case: This is an alternate to if elif statement.

Syntax:def switch_case(option):
    match option:
        case 1:
            return "Case 1"
        case 2:
            return "Case 2"
        case 3:
            return "Case 3"
        case _:
            return "Default Case"

# Example usage
result = switch_case(2)
print(result)

def grade_switch(score):
    match score:
        case score if score >= 90:
            return "A"
        case score if score >= 80:
            return "B"
        case score if score >= 70:
            return "C"
        case score if score >= 60:
            return "D"
        case _:
            return "F"

# Example usage
score = 85
grade = grade_switch(score)
print(f"Grade for score {score}: {grade}")


← Back Next →

Labels:

Monday, December 16, 2024

Dynamic memory

The application can allocate memory at runtime instead of compile time thanks to C++'s dynamic memory allocation feature. When you don't know how much memory is required until the program is running, this is helpful.

In C++, the new and delete operators are used to control dynamic memory:

Memory is allocated on the heap using new, which also returns a pointer to the memory that has been allocated.
To deallocate memory that was previously allocated with new, use delete.

A sample program on Dynamic memory:
#include <iostream>
using namespace std;

int main() {
    // Dynamic memory allocation for an integer using 'new'
    int *ptr = new int;   // Allocate memory for an integer
    *ptr = 100;           // Assign a value to the allocated memory

    // Output the value stored in the dynamically allocated memory
    cout << "Value stored at ptr: " << *ptr << endl;

    // Dynamic memory allocation for an array of integers
    int *arr = new int[5]; // Allocate memory for an array of 5 integers

    // Assign values to the array
    for(int i = 0; i < 5; i++) {
        arr[i] = (i + 1) * 10;  // Assign multiples of 10 to the array
    }

    // Output the values stored in the array
    cout << "Values in the dynamically allocated array: ";
    for(int i = 0; i < 5; i++) {
        cout << arr[i] << " ";
    }
    cout << endl;

    // Deallocate memory using 'delete' for a single variable
    delete ptr;  // Free the memory allocated for the single integer

    // Deallocate memory using 'delete[]' for the array
    delete[] arr; // Free the memory allocated for the array

    return 0;
}

Summary:
Allocation of a single variable (new int):
We use new int to allocate memory for a single integer.
Following allocation, we give the memory a value of 100.
The value that is stored in that memory is output.

Allocating an array (new int[5]):
We use new int[5] to allocate memory for an array of five integers.
We display the values that we have assigned to the array (multiples of 10).

Deallocation
To deallocate the memory for the single integer, use delete ptr.
delete[] arr; releases all of the array's memory. Note that arrays are deleted using delete[] whereas a single variable is deleted using delete

Points to remember:
Memory allocated by new is stored on the heap until it is specifically released using delete.
Whereas delete[] is used for arrays, delete releases the memory allotted for a single object.
To avoid memory leaks, deallocate memory whenever you're finished.

← Back Next →

Labels:

Variables

A variable is a container which holds the data or the value the user gives. variables are memory locations in a computer's memory to store data. variable is varying it can take different values during times during execution. 

Every variable in C has three most fundamental attributes. They are:

  • Name

  • Value

  • Address


Guidelines for naming a variable:

  • A variable must begin with either a letter or an underscore(_).

  • C is a case sensitive, hence upper and lower case letters are treated as different. For example sum is different SUM

  • Only “ _ “ is used as a special symbol, other symbols are not permitted.

  • variable should not be a keyword.

Valid Variables:

Sum, count, area, roll_no

Invalid Variables:

  • roll no - No blank spaces are allowed

  • %marks - Special symbols are not allowed

  • int - Keyword cannot be a variable.

Declaration of variable:

A variable declaration tells the compiler where and how much storage is needed to create the variable. a variable definition specifies a data type and contains a list of one or more variables of that type.

Syntax: data_type variable1, variable2 

variable1 - name of the variable

variables are separated by comma. The statement should always end with a semicolon.

Example: int radius, count

Assignment/Initialization of variables

Values can be assigned with a value using assignment operator (=)

Syntax: varible_name = constant

Example: sum =100;

The value of a variable can be assigned during the declaration of the variable. This process is called initialization. C variables declared can be initialized with the help of assignment operator ‘=’.

syntax: data_type variable_name = constant;

Example: int roll_no = 596403


Sample program of declarations, assignment and values stored in variable.

#include <stdio>

int main() {

//Declaration

int sum1, sum_2, count;

float avg;

//Declaration and initialization

char letter = ‘A’;

//Assign values

sum1 = 200;

sum_2=30;

count = sum1+sum_2;

avg = count/2;

//Printing values

printf(“The sum of two number is: %d”, count);

printf(“The average of two number is: %f”, avg);

printf(“Character is: %c”, letter);

return 0;

}

Getting input through the user:

The data can be read from the user through the keyboard using scanf function.

syntax: scanf(“control string” ,&variable1, &variable2);

The control string represents the type of the variables specified. “&” symbol specifies the address of the variable.

Example: 

scanf(“%d%f” , &sum, &avg);

where,

%d refers to integer value

%f refers to float value

Sample program using scanf function:

#include <stdio>

int main(){

int length, breadth, area;

printf(“Enter the length and breadth of a rectangle”);

scanf(“%d%d”, &length, &breadth);

area = length*breadth;

printf(“Area of a rectangle is”, area);

return 0;

}

Constant variables:

Variables having an unchanged value during the execution of the program are referred to as constant Variables. A constant variable can be declared by using the keyword “const”.

Example: const int value = 100;

Volatile Variable:

variables which can be changed at any time by some external sources from outside or same program are called volatile variables.

Syntax: volatile datatype variable;


← Back Next →

Labels:

Information Security & Essential Terminology

Information security is the process of preventing unauthorized access, disclosures, modifications, and destructions of data and system data that use, store, and transmit data. The most important resource that enterprises must protect is information. In an effort to learn how to secure such vital information resources, the relevant business may incur significant losses in terms of money, brand reputation, customers, etc., if sensitive information ends up in the wrong hands.

Various statistics, threat forecasts, key terms related to information security, information security components, and the security, functionality, and usability triangle are covered in this part.

Since technology makes it simple to obtain information, the internet has become a crucial component of both modern business and personal life. Both consumers and businesses depend on the internet for a variety of functions, including social networking, content browsing, communication, purchasing, downloading, and conversing.

By 2024, there are 5.45 billion internet users worldwide. These days, searching the internet for a certain answer and finding satisfaction from a suitable one is standard procedure. One of the most significant and well-liked emerging issues of common interest these days is websites for frequent interaction with friends and family, in addition to the ability to locate a variety of internet services.

Essential Terminology

Hack Value is the idea that hackers use to determine whether a task is worthwhile or intriguing. Since breaking through the most difficult network security is something that not everyone can perform, hackers take immense pride in their success.

 Vulnerability: Vulnerability is the presence of a flaw, design flaw, or implementation error that, if taken advantage of, compromises the system's security by causing an unanticipated and undesirable occurrence. Vulnerability, to put it simply, is a security flaw that lets an attacker get into the system by getting past different user authentications.

Exploit: In the context of an assault on a system or network, an exploit is a breach of IT system security caused by vulnerabilities. Additionally, it refers to malicious software or commands that, when exploited by attackers, can induce unexpected behavior of legitimate software or hardware.

Payload: A malware or exploit code's payload is the portion that carries out the planned malicious actions. These actions may include gaining backdoor access to a victim's computer, erasing or corrupting files, stealing data, or taking over a computer. Hackers execute the payload in a variety of ways. They can, for instance, use an unprotected computer linked to a network, ignite a logic bomb, or run an infected program.

Zero-Day Attack: A zero-day attack occurs when an attacker takes advantage of flaws in a computer program before the creator of the program has had a chance to fix them.

Daisy Chaining: It entails getting access to a single computer or network and then utilizing that information to access other computers and networks that have information that is of interest.

Doxing: Doxing is the collection and dissemination of personally identifiable information, such as a person's name and email address, or other private data about a whole company. Malicious individuals gather this data from publicly available sources including databases, social media, and the Internet.

Bot: A software program or application that may be remotely controlled to carry out or automate predetermined tasks is called a "bot" (a contraction of the word "robot"). Bots are agents used by hackers to perform destructive actions via the Internet. Distributed denial-of-service (DDoS) attacks, keylogging, eavesdropping, and other tactics are carried out by attackers using compromised computers.


← Back Next →

Labels: