Server Side Programming Articles

Page 1963 of 2109

HashSet in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 03-Apr-2021 715 Views

Rust also provides us with a HashSet data structure that is mainly used when we want to make sure that no duplicate values are present in our data structure.If we try to insert a new value into a HashSet that is already present in it, then the previous value gets overwritten by the new value that we insertedBesides the key features, a HashSet is also used to do the following operations −union − Extract all the unique elements in both sets.difference −G ets all the elements that are present in the first set, but not in the second.intersection − Gets ...

Read More

File Operations in Rust Programming

Mukul Latiyan
Mukul Latiyan
Updated on 03-Apr-2021 358 Views

File operations normally include I/O operations. Rust provides us with different methods to handle all these operations.OpenRust provides an open static method that we can use to open a file in read-only mode.ExampleConsider the code shown below:use std::fs::File; use std::io::prelude::*; use std::path::Path; fn main() {    // Create a path to the desired file    let path = Path::new("out.txt");    let display = path.display();    let mut file = match File::open(&path) {       Err(why) => panic!("unable to open {}: {}", display, why),       Ok(file) => file,    };    let mut s = String::new();    match ...

Read More

Difference Between Inline and Macro in C++

AmitDiwan
AmitDiwan
Updated on 24-Mar-2021 1K+ Views

In this post, we will understand the difference between inline and macro in C++.InlineIt is a function in C++.It is parsed by the compiler.It can be defined inside or outside the class.It evaluates the argument only once.The compiler may not convert all functions to ‘inline’ function and expand them all.The short functions that are defined inside the class are automatically made as inline functions.An inline function inside a class can access the data members of the class.Inline function can be terminated using curly brackets.It is easy to debug.This is because error checking is done during compilation.It binds all statements in ...

Read More

Difference Between Checked and Unchecked Exception in Java

AmitDiwan
AmitDiwan
Updated on 24-Mar-2021 14K+ Views

In this post, we will understand the difference between checked and unchecked exceptions in Java.Checked ExceptionsThey occur at compile time.The compiler checks for a checked exception.These exceptions can be handled at the compilation time.It is a sub-class of the exception class.The JVM requires that the exception be caught and handled.Example of Checked exception- ‘File Not Found Exception’Unchecked ExceptionsThese exceptions occur at runtime.The compiler doesn’t check for these kinds of exceptions.These kinds of exceptions can’t be caught or handled during compilation time.This is because the exceptions are generated due to the mistakes in the program.These are not a part of the ...

Read More

Difference Between Packages and Interfaces in Java

AmitDiwan
AmitDiwan
Updated on 24-Mar-2021 5K+ Views

In this post, we will understand the difference between packages and interfaces in Java.PackagesIt is a group of classes and/or interfaces that are together.It can be created using the "Package" keyword.It can be imported.It can be done using the "import" keyword.Examplepackage package_name; public class class_name {    .    (body of class)    . }InterfacesIt is a group of abstract methods and constants.It can be created using the "Interface" keyword.It can be extended by another interface.It can also be implemented by a class.It can be implemented using the ‘implement’ keyword.Exampleinterface interface_name { variable declaration; ...

Read More

Difference Between extends and implements keywords in Java

AmitDiwan
AmitDiwan
Updated on 24-Mar-2021 2K+ Views

In this post, we will understand the differences between ‘Extends’ and ‘Implements’ keyword.ExtendsUsing this, a class can be used as a base class, and another class inherits this base class.An interface can also inherit other interfaces using this keyword.Only one superclass can be extended by a class.Any number of interfaces can be extended by an interface.It is not required for the subclass (that extends a superclass) to override all the methods in the superclass.Following is an example of the extends keyword −Exampleclass Super { ..... ..... } class Sub extends Super { ...

Read More

Difference Between HashMap and LinkedHashMap in Java

AmitDiwan
AmitDiwan
Updated on 24-Mar-2021 1K+ Views

In this post, we will understand the difference between HashMap and LinkedHashMap in Java.HashMapIn this structure, the order of insertion is not preserved.It uses the HashTable to store maps.It extends the ‘AbstractMap’.It implements the ‘Map’ interface.This was introduced in JDK 2.0.It has a relatively low overhead.LinkedHashMapIn this structure, the order of insertion is not preserved.It uses the HashTable and Linked List to store maps.It extends the ‘Hashmap’.It implements the ‘Map’ interface.This was introduced in JDK 4.0.It has a relatively higher overhead.This is because it has to maintain the order of entries in the map structure.

Read More

Golang Program to find the position of the rightmost set bit

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Mar-2021 376 Views

ExamplesConsider n = 20(00010100)Now return log2(20 & -20) => 2+1 => 3Approach to solve this problemStep 1 − Define a method, where n and is an argument, return type is int.Step 2 − Return log2(n & -n)+1.Examplepackage main import (    "fmt"    "math"    "strconv" ) func FindRightMostSetBit(n int) int {    if (n & 1) != 0{       return 1    }    return int(math.Log2(float64(n & -n))) + 1 } func main(){    var n = 20    fmt.Printf("Binary of %d is: %s.", n, strconv.FormatInt(int64(n), 2))    fmt.Printf("Position of the rightmost set bit of the given number %d is %d.", n, FindRightMostSetBit(n)) }OutputBinary of 20 is: 10100. Position of the rightmost set bit of the given number 20 is 3.

Read More

Golang Program to toggle the Kth of the given number n.

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Mar-2021 199 Views

ExamplesConsider n = 20(00010100), k = 3.After toggling the kth bit of the given number: 00010000 => 16.Approach to solve this problemStep 1 − Define a method, where n and k would be the arguments, returns type is int.Step 2 − Perform AND operation with n ^ (1

Read More

Golang program to check if k'th bit is set for a given number or not.

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 17-Mar-2021 2K+ Views

ExamplesConsider n = 20(00010100), k = 3So, the result after turning off the 3rd bit => 00010000 & (1

Read More
Showing 19621–19630 of 21,090 articles
Advertisements