code-rag-bench/online-tutorials huggingface dataset:
Write an JDBC example for inserting value for Blob datatype into a table?

Assume we already have a table named MyTable in the database with the following description.
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| Name  | varchar(255) | YES  |     | NULL    |       |
| image | blob         | YES  |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
If you need to insert a value int to the blob data type using a JDBC program you need to use the methods which sets binary stream data. PreparedStatement interface provides the following methods to insert image into a table.
The void setBinaryStream(int parameterIndex, InputStream x) method sets the data in the given input stream (till the end of the file) as a value to the parameter at the given index.
void setBinaryStream(int parameterIndex, InputStream x, int length)
void setBinaryStream(int parameterIndex, InputStream x, int length)
void setBinaryStream(int parameterIndex, InputStream x, long length)
void setBinaryStream(int parameterIndex, InputStream x, long length)
The void setBlob(int parameterIndex, Blob x) method sets the given blob object as a value to the parameter at the given index.
void setBlob(int parameterIndex, InputStream inputStream)
void setBlob(int parameterIndex, InputStream inputStream)
void setBlob(int parameterIndex, InputStream inputStream, long length)
void setBlob(int parameterIndex, InputStream inputStream, long length)
You can set value to the Blob data type using either of these methods.
Following example sets value to a Blob datatype using the setBinaryStream() method.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class IndertingValueForBlob {
   public static void main(String args[]) throws Exception{
      //Registering the Driver
      DriverManager.registerDriver(new com.mysql.jdbc.Driver());
      //Getting the connection
      String mysqlUrl = "jdbc:mysql://localhost/sampleDB";
      Connection con = DriverManager.getConnection(mysqlUrl, "root", "password");
      System.out.println("Connection established......");

      //Inserting values
      String query = "INSERT INTO MyTable(Name,image) VALUES (?, ?)";
      PreparedStatement pstmt = con.prepareStatement(query);
      pstmt.setString(1, "sample_image");
      FileInputStream fin = new FileInputStream("E:\\images\\cat.jpg");
      pstmt.setBinaryStream(2, fin);
      pstmt.execute();
      System.out.println("Record inserted .....");
   }
}
Connection established......
Record inserted ......
If you try to view the blob value in the record using the MySQL work bench you can see the image inserted as shown below:
C++ Program to Implement the Rabin-Miller Primality Test to Check if a Given Number is Prime

Rabin-Miller Primality Test is used to check if a given Number is Prime or not. It is similar to the format primality and the Solovay-Stressen test. this test first was discovered by Russian Mathematician M. M. Artjuhov.
Begin
   ll mulmod(ll a, ll b, ll m)
   ll x = 0,y = a mod m
   while (b > 0)
      if (b mod 2 == 1)
         compute x = (x + y) mod m
         y = (y * 2) mod m
         b = b/ 2
   return x mod m.
End

Begin
   ll modulo(ll base, ll e, ll m)
   Initialize:
   ll x = 1
   ll y = base
   while (e > 0)
      if (e mod 2 == 1)
         x = (x * y) mod m
         y = (y * y) mod m
         e = e / 2;
   return x mod m
End

Begin
   bool Miller(ll p, int iteration)
   if (p < 2)
      return false
   if (p != 2 and p mod 2==0)
      return false;
      Compute: ll s = p - 1
   while (s mod 2 == 0)
      s = s/ 2;
      for i = 0 to iteration - 1
         Do
            ll a = rand() mod (p - 1) + 1, temp = s
            ll mod = modulo(a, temp, p)
            while (temp != p - 1 and mod != 1 and mod != p - 1)
               mod = mulmod(mod, mod, p);
               temp *= 2;
            if (mod != p - 1 && temp % 2 == 0)
               return false
            else
               return true
End
#include <iostream>
#include<stdlib.h>
#define ll long long
using namespace std;
ll mulmod(ll a, ll b, ll m)//It returns true if number is prime otherwise false {
   ll x = 0,y = a % m;
   while (b > 0) {
      if (b % 2 == 1) {
         x = (x + y) % m;
      }
      y = (y * 2) % m;
      b /= 2;
   }
   return x % m;
}

ll modulo(ll base, ll e, ll m) {
   ll x = 1;
   ll y = base;
   while (e > 0) {
      if (e % 2 == 1)
         x = (x * y) % m;
         y = (y * y) % m;
         e = e / 2;
   }
   return x % m;
}

bool Miller(ll p, int iteration) {
   if (p < 2) {
      return false;
   }
   if (p != 2 && p % 2==0) {
      return false;
   }
   ll s = p - 1;
   while (s % 2 == 0) {
      s /= 2;
   }
   for (int i = 0; i < iteration; i++) {
      ll a = rand() % (p - 1) + 1, temp = s;
      ll mod = modulo(a, temp, p);
      while (temp != p - 1 && mod != 1 && mod != p - 1) {
         mod = mulmod(mod, mod, p);
         temp *= 2;
      }
      if (mod != p - 1 && temp % 2 == 0) {
         return false;
      }
   }
   return true;
}

int main() {
   int iteration = 10;
   ll num;
   cout<<"Enter integer to test primality: ";
   cin>>num;
   if (Miller(num, iteration))
      cout<<num<<" is prime"<<endl;
   else
      cout<<num<<" is not prime"<<endl;
   return 0;
}
Enter integer to test primality: 26
26 is not prime
How to remove an element from an array in JavaScript? - GeeksforGeeks

14 Mar, 2019
Array splice() method can be used to remove any particular element from an array in JavaScript. Moreover, this function can be used to add/remove more than one element from an array.
Syntax:
array.splice(index, howmany, item1, ....., itemX)
Parameters: This method requires 3 parameters :-
index: Required. It specifies the position to remove/add the elements.
howmany: Optional. It specifies how many elements to be removed.
item: Optional. It specifies new elements to be added.
Return Value: A new Array, containing the removed items (if any).
Example: This example uses splice() method to remove particular element from an array.
<!DOCTYPE html><html>    <body>        <h1>Welcome to GeeksforGeeks</h1>        <p>Click the button to remove 3rd element from the array.</p>        <button onclick="remove_ele()">Try it</button>        <p id="display"></p>        <p id="demo"></p>          <!--Script to remove an element from an             array using spice method-->        <script>            var Lang = ["C++ ", " Java ", " Python ", " Go ", " Prolog"];             document.getElementById("display").innerHTML = Lang;             function remove_ele() {               Lang.splice(2, 1);               document.getElementById("display").innerHTML = Lang;             }        </script>    </body></html>
Output:Before clicking try it button:After clicking try it button:Supported Browsers: The browser supported by Array splice() Method are listed below:
Google Chrome
Apple Safari
Firefox
Opera
Edge
javascript-array
Picked
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Difference between var, let and const keywords in JavaScript
How to create a link in JavaScript ?
How to Show Images on Click using HTML ?
Remove elements from a JavaScript Array
How to remove an HTML element using JavaScript ?
Express.js express.Router() Function
Installation of Node.js on Linux
How to set input type date in dd-mm-yyyy format using HTML ?
How to create footer to stay at the bottom of a Web page?
How to float three div side by side using CSS?
Kotlin | apply vs with

09 Aug, 2019
In Kotlin, apply is an extension function on a particular type and sets its scope to object on which apply is invoked. Apply runs on the object reference into the expression and also returns the object reference on completion. It does not simply setting properties of course but do much more functionalities and capable of evaluating complex logic before returning. In the end, it returns the same object, with some modified changes.
apply is an extension function on a type.
It requires an object reference to run into an expression.
It also return an object reference on completion.
Definition of apply :
inline fun  T.apply(block: T.() -> Unit): T 
{
    block()
    return this
}

Example of apply
fun main(args: Array<String>){    data class GFG(var name1 : String, var name2 : String,var name3 : String)    // instantiating object of class    var gfg = GFG("Geeks","for","hi")    // apply function invoked to change the name3 value    gfg.apply { this.name3 = "Geeks" }    println(gfg)}
Output :
GFG(name1=Geeks, name2=for, name3=Geeks)

Here the 3rd member of class GFG is changed from “hi” to “Geeks”.
Like apply, with is also used to change properties of an instance. But here we don’t require a object reference to run, i.e. : we don’t need a dot operator for reference.
Definition of with
inline fun  with(receiver: T, block: T.() -> R): R 
{
    return receiver.block()
}

Example of with
fun main(args: Array<String>){    data class GFG(var name1: String, var name2 : String,var name3 : String)    var gfg = GFG("hello", "for","hi")    // applying with function    with(gfg)    {        name1 = "Geeks"        name3 = "Geeks"    }    println(gfg)}
Output :
GFG(name1=Geeks, name2=for, name3=Geeks)

Here we don’t require any dot operator, and we changed the values of first and third variables of an object of class GFG using with extension function.
with runs without an object whereas apply needs one object to run
apply runs on the object reference, but with simply passes it as the argument
Picked
Kotlin
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Add Views Dynamically and Store Data in Arraylist in Android?
How to Communicate Between Fragments in Android?
Retrofit with Kotlin Coroutine in Android
Suspend Function In Kotlin Coroutines
How to Get Current Location in Android?
Kotlin extension function
Dagger Hilt in Android with Example
Scopes in Kotlin Coroutines
Kotlin Sealed Classes
Singleton Class in Kotlin
Python program to find the gcd of two numbers

26 Nov, 2020
Given two numbers. The task is to find the GCD of the two numbers.
Using STL :
In Python, the math module contains a number of mathematical operations, which can be performed with ease using the module. math.gcd() function compute the greatest common divisor of 2 numbers mentioned in its arguments.
Syntax: math.gcd(x, y)
Parameter:
x : Non-negative integer whose gcd has to be computed.
y : Non-negative integer whose gcd has to be computed.
Returns: An absolute/positive integer value after calculating the GCD of given parameters x and y.
Exceptions: When Both x and y are 0, function returns 0, If any number is a character, Type error is raised.
Python3
# Python code to demonstrate the working of gcd()# importing "math" for mathematical operationsimport math  # prints 12print("The gcd of 60 and 48 is : ", end="")print(math.gcd(60, 48))
The gcd of 60 and 48 is : 12

Using Recursion :
Python3
# Python code to demonstrate naive# method to compute gcd ( recursion )    def hcf(a, b):    if(b == 0):        return a    else:        return hcf(b, a % b)  a = 60b = 48  # prints 12print("The gcd of 60 and 48 is : ", end="")print(hcf(60, 48))
The gcd of 60 and 48 is : 12

Using Euclidean Algorithm :
The Euclid’s algorithm (or Euclidean Algorithm) is a method for efficiently finding the greatest common divisor (GCD) of two numbers. The GCD of two integers X and Y is the largest number that divides both of X and Y (without leaving a remainder).
Pseudo Code of the Algorithm-
Let  a, b  be the two numbersa mod b = RLet  a = b  and  b = RRepeat Steps 2 and 3 until  a mod b  is greater than 0GCD = b Finish
Let  a, b  be the two numbers
a mod b = R
Let  a = b  and  b = R
Repeat Steps 2 and 3 until  a mod b  is greater than 0
GCD = b
 Finish
Python3
# Recursive function to return gcd of a and bdef gcd(a, b):      # Everything divides 0    if (a == 0):        return b    if (b == 0):        return a      # base case    if (a == b):        return a      # a is greater    if (a > b):        return gcd(a-b, b)    return gcd(a, b-a)  # Driver program to test above functiona = 98b = 56if(gcd(a, b)):    print('GCD of', a, 'and', b, 'is', gcd(a, b))else:    print('not found')
GCD of 98 and 56 is 14

GCD-LCM
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Perl | abs() function

25 Jun, 2019
This function returns the absolute value of its argument. If a pure integer value is passed then it will return it as it is, but if a string is passed then it will return zero. If VALUE is omitted then it uses $_
Syntax: abs(VALUE)
Parameter:VALUE: It is a required number which can be either positive or negative or a string.
Returns: Function returns the absolute value of the arguments passed.
Example 1:
#!/usr/bin/perl  # Defining decimal value$var1 = 15.8;  # Defining integer value$var2 = 7;  # Defining negative value$var3 = "-15.2";  # Calling abs() function$res1 = abs($var1);$res2 = abs($var2);$res3 = abs($var3);  # Printing these valuesprint "Abs value of var1 is $res1\n";print "Abs value of var2 is $res2\n";print "Abs value of var3 is $res3";
Output:
Abs value of var1 is 15.8
Abs value of var2 is 7
Abs value of var3 is 15.2
Example 2:
#!/usr/bin/perl  # Defining string value$var1 = "Geeks";  # Defining Fractional value$var2 = 7/2;  # Calling abs() function$res1 = abs($var1);$res2 = abs($var2);  # Print these valuesprint "Abs value of var1 is $res1\n";print "Abs value of var2 is $res2";
Output:
Abs value of var1 is 0
Abs value of var2 is 3.5
Perl-function
Perl-Math-Functions
Perl
Perl
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Perl Tutorial - Learn Perl With Examples
Perl | Basic Syntax of a Perl Program
Perl | ne operator
Perl | Opening and Reading a File
Perl | Writing to a File
Perl | File Handling Introduction
Perl | Decision Making (if, if-else, Nested–if, if-elsif ladder, unless, unless-else, unless-elsif)
Perl | Multidimensional Hashes
Perl | Data Types
Perl | qw Operator
How to parse a JSON File in PHP ?

26 May, 2021
In this article, we are going to parse the JSON file by displaying JSON data using PHP. PHP is a server-side scripting language used to process the data. JSON stands for JavaScript object notation. JSON data is written as name/value pairs.
Syntax:
{“Data”:[{“key”:”value”,“key”:value,“key n “:”value”},. . .. . .{“key”:”value”,“key”:value,“key n “:”value”}]}
Example: The JSON notation for student details is as follows.
{“Student”:[{“Name”:”Sravan”,“Roll”:7058,“subject”:”java”},{“Name”:”Jyothika”,“Roll”:7059,“subject”:”SAP”}]}
Advantages:
JSON does not use an end tag.
JSON is a shorter format.
JSON is quicker to read and write.
JSON can use arrays.
Approach: Create a JSON file and save it as my_data.json. We have taken student data in the file. The contents are as follows.
{“Student”:[{“Name”:”Sravan”,“Roll”:7058,“subject”:”java”},{“Name”:”Jyothika”,“Roll”:7059,“subject”:”SAP”}]}
Use file_get_contents() function to read JSON file into PHP. This function is used to read the file into PHP code.
Syntax:
file_get_contents(path, file_name)
file_name is the name of the file and path is the location to be checked.
Use json_decode() function to decode to JSON file into array to display it.
It is used to convert the JSON into an array.
Syntax:
json_decode($json_object, true)
$json_object is the file object to be read.
PHP code: The following is the PHP code to parse JSON file.
PHP
<?php  // Read the JSON file $json = file_get_contents('my_data.json');  // Decode the JSON file$json_data = json_decode($json,true);  // Display dataprint_r($json_data);  ?>
Output:
Array ( 
    [Student] => Array ( 
        [0] => Array ( 
            [Name] => Sravan 
            [Roll] => 7058 
            [subject] => java 
        ) 
        [1] => Array ( 
            [Name] => Jyothika 
            [Roll] => 7059 
            [subject] => SAP 
        ) 
    ) 
)

PHP-function
PHP-Questions
Picked
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python – Group similar elements into Matrix

30 Dec, 2020
Sometimes, while working with Python Matrix, we can have a problem in which we need to perform grouping of all the elements with are same. This kind of problem can have application in data domains. Let’s discuss certain ways in which this task can be performed.
Input : test_list = [1, 3, 4, 4, 2, 3]Output : [[1], [2], [3, 3], [4, 4]]
Input : test_list = [1, 3, 4, 2]Output : [[1], [2], [3], [4]]
Method #1 : Using list comprehension + groupby()The combination of above functions provide possible solution to this problem. In this, we perform task of grouping using groupby() and list comprehension assists in iteration.
# Python3 code to demonstrate working of # Group similar elements into Matrix# Using list comprehension + groupby()from itertools import groupby  # initializing listtest_list = [1, 3, 5, 1, 3, 2, 5, 4, 2]  # printing original list print("The original list : " + str(test_list))  # Group similar elements into Matrix# Using list comprehension + groupby()res = [list(val) for key, val in groupby(sorted(test_list))]            # printing result print("Matrix after grouping : " + str(res))
The original list : [1, 3, 5, 1, 3, 2, 5, 4, 2]
Matrix after grouping : [[1, 1], [2, 2], [3, 3], [4], [5, 5]]

 
Method #2 : Using list comprehension + Counter()This is yet another approach to this problem. In this, we get the values along with it’s frequency using Counter() and then employ list comprehension to multiply each element with frequency to get duplicates
# Python3 code to demonstrate working of # Group similar elements into Matrix# Using list comprehension + Counter()from collections import Counter  # initializing listtest_list = [1, 3, 5, 1, 3, 2, 5, 4, 2]  # printing original list print("The original list : " + str(test_list))  # Group similar elements into Matrix# Using list comprehension + Counter()temp = Counter(test_list)res = [[key] * val for key, val in temp.items()]  # printing result print("Matrix after grouping : " + str(res))
The original list : [1, 3, 5, 1, 3, 2, 5, 4, 2]
Matrix after grouping : [[1, 1], [2, 2], [3, 3], [4], [5, 5]]

Python list-programs
Python matrix-program
Python-list-of-lists
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
Python program to convert a list to string
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python | Convert string dictionary to dictionary
How to Filter a Vector in R

03 Sep, 2021
In this article, we are going to discuss how to filter a vector in the R programming language.
Filtering a vector means getting the values from the vector by removing the others, we can also say that getting the required elements is known as filtering.
Here we can filter the elements in a vector by using the %in% operator
Syntax:
 vec[vec %in% c(elements)]
where
vec is the input vector
elements are the vector elements that we want to get
Example:  R program to filter the vector by getting only some values
R
# create a vector with id and namesvector=c(1,2,3,4,5,"sravan","boby","ojaswi","gnanesh","rohith") # display vectorprint(vector) print("=======") # get the data  - "sravan","rohith",3 from# the vectorprint(vector[vector %in% c("sravan","rohith",3)]) print("=======") # get the data  - "sravan","ojaswi",3,1,2 from# the vectorprint(vector[vector %in% c("sravan","ojaswi",3,1,2)]) print("=======") # get the data  - 1,2,3,4,5 from the vectorprint(vector[vector %in% c(1,2,3,4,5)])
Output:
[1] “1”       “2”       “3”       “4”       “5”       “sravan”  “boby”    
[8] “ojaswi”  “gnanesh” “rohith”  
[1] “=======”
[1] “3”      “sravan” “rohith”
[1] “=======”
[1] “1”      “2”      “3”      “sravan” “ojaswi”
[1] “=======”
[1] “1” “2” “3” “4” “5”
We can also specify the condition from the index operator. 
Syntax:
vector[condition(s)]
where the vector is the input vector and condition defines the condition to follow for filtering. 
Example: R program to filter vector using the conditions
R
# create a vector with id and namesvector=c(1,2,3,4,5,"sravan","boby","ojaswi","gnanesh","rohith") # display vectorprint(vector) print("=======") # get the data where element not equal to 1print(vector[vector != 1]) print("=======") # get the data where element  equal to 1print(vector[vector == 1])
Output:
[1] “1”       “2”       “3”       “4”       “5”       “sravan”  “boby”    
[8] “ojaswi”  “gnanesh” “rohith”  
[1] “=======”
[1] “2”       “3”       “4”       “5”       “sravan”  “boby”    “ojaswi”  
[8] “gnanesh” “rohith”  
[1] “=======”
[1] “1”
surinderdawra388
Picked
R Vector-Programs
R-Vectors
R Language
R Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Change Color of Bars in Barchart using ggplot2 in R
How to Split Column Into Multiple Columns in R DataFrame?
Group by function in R using Dplyr
How to Change Axis Scales in R Plots?
R - if statement
How to Split Column Into Multiple Columns in R DataFrame?
How to filter R DataFrame by values in a column?
Replace Specific Characters in String in R
Merge DataFrames by Column Names in R
How to Sort a DataFrame in R ?
Python program to count positive and negative numbers in a list

26 Oct, 2018
Given a list of numbers, write a Python program to count positive and negative numbers in a List.
Example:
Input: list1 = [2, -7, 5, -64, -14]
Output: pos = 2, neg = 3

Input: list2 = [-12, 14, 95, 3]
Output: pos = 3, neg = 1
Example #1: Count positive and negative numbers from given list using for loop
Iterate each element in the list using for loop and check if num >= 0, the condition to check positive numbers. If the condition satisfies, then increase pos_count else increase neg_count.
# Python program to count positive and negative numbers in a List  # list of numberslist1 = [10, -21, 4, -45, 66, -93, 1]  pos_count, neg_count = 0, 0  # iterating each number in listfor num in list1:          # checking condition    if num >= 0:        pos_count += 1      else:        neg_count += 1          print("Positive numbers in the list: ", pos_count)print("Negative numbers in the list: ", neg_count)
Output:
Positive numbers in the list:  4
Negative numbers in the list:  3

 
Example #2: Using while loop
# Python program to count positive and negative numbers in a List  # list of numberslist1 = [-10, -21, -4, -45, -66, 93, 11]  pos_count, neg_count = 0, 0num = 0  # using while loop     while(num < len(list1)):          # checking condition    if list1[num] >= 0:        pos_count += 1    else:        neg_count += 1          # increment num     num += 1      print("Positive numbers in the list: ", pos_count)print("Negative numbers in the list: ", neg_count)
Output:
Positive numbers in the list:  2
Negative numbers in the list:  5

 
Example #3 : Using Python Lambda Expressions
# Python program to count positive# and negative numbers in a List  # list of numberslist1 = [10, -21, -4, 45, 66, 93, -11]  neg_count = len(list(filter(lambda x: (x < 0), list1)))  # we can also do len(list1) - neg_countpos_count = len(list(filter(lambda x: (x >= 0), list1)))  print("Positive numbers in the list: ", pos_count)print("Negative numbers in the list: ", neg_count)
Output:
Positive numbers in the list:  4
Negative numbers in the list:  3

 
Example #4 : Using List Comprehension
# Python program to count positive# and negative numbers in a List  # list of numberslist1 = [-10, -21, -4, -45, -66, -93, 11]  only_pos = [num for num in list1 if num >= 1]pos_count = len(only_pos)  print("Positive numbers in the list: ", pos_count)print("Negative numbers in the list: ", len(list1) - pos_count)
Output:
Positive numbers in the list:  1
Negative numbers in the list:  6

Python list-programs
python-list
Python
Python Programs
School Programming
python-list
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Different ways to create Pandas Dataframe
Enumerate() in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python | Convert string dictionary to dictionary
Python Program for Fibonacci numbers
Float compare() Method in Java with Examples

22 Jun, 2021
The compare() method of Float Class is a built-in method in Java that compares the two specified float values. The sign of the integer value returned is the same as that of the integer that would be returned by the function call. 
Syntax: 
public static int compare(float f1, float f2)
Parameters: The function accepts two parameters:  
f1: The first float value to be compared.
f2: The second float value to be compared.
Return Value: The function returns value as below:  
0: if f1 is numerically equal to f2.
Negative value: if f1 is numerically less than f2.
Positive value: if f1 is numerically greater than f2.
Below programs illustrates the use of Float.compare() function:
Program 1: When two integers are same  
Java
// Java Program to illustrate// the Float.compare() method import java.lang.Float; public class GFG {    public static void main(String[] args)    {         // Get the two float values        // to be compared        Float f1 = 1023f;        Float f2 = 1023f;         // function call to compare two float values        if (Float.compare(f1, f2) == 0) {             System.out.println("f1=f2");        }        else if (Float.compare(f1, f2) < 0) {             System.out.println("f1<f2");        }        else {             System.out.println("f1>f2");        }    }}
f1=f2
 
Program 2 : When f1<f2
Java
// Java Program to illustrate// the Float.compare() method import java.lang.Float; public class GFG {    public static void main(String[] args)    {         // Get the two float values        // to be compared        Float f1 = 10f;        Float f2 = 1023f;         // function call to compare two float values        if (Float.compare(f1, f2) == 0) {             System.out.println("f1=f2");        }        else if (Float.compare(f1, f2) < 0) {             System.out.println("f1<f2");        }        else {             System.out.println("f1>f2");        }    }}
f1
Program 3 : When f1>f2
Java
// Java Program to illustrate// the Float.compare() method import java.lang.Float; public class GFG {    public static void main(String[] args)    {         // Get the two float values        // to be compared        Float f1 = 1023f;        Float f2 = 10f;         // function call to compare two float values        if (Float.compare(f1, f2) == 0) {             System.out.println("f1=f2");        }        else if (Float.compare(f1, f2) < 0) {             System.out.println("f1<f2");        }        else {             System.out.println("f1>f2");        }    }}
f1>f2
 
Reference: https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#compare(float, %20float) 
rajeev0719singh
Java-Float
Java-Functions
Java-lang package
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Interfaces in Java
Queue Interface In Java
Multidimensional Arrays in Java
How to add an element to an Array in Java?
HashMap in Java with Examples
Stack Class in Java
PriorityQueue in Java
Math pow() method in Java with Example
Initialize an ArrayList in Java
List Interface in Java with Examples
C# Program to count number of Vowels and Consonants in a string

You need to check for both the vowels and consonants, but do not forget to check for both the uppercase as well lowercase.
For counting vowels, check for “aeiou” characters separately i.e.
if (myStr[i] == 'a' || myStr[i] == 'e' || myStr[i] == 'i' || myStr[i] == 'o' || myStr[i] == 'u' || myStr[i] == 'A' || myStr[i] == 'E' || myStr[i] == 'I' || myStr[i] == 'O' || myStr[i] == 'U') {
   vowel_count++;
}
For counting consonants, check for other characters in elseif condition −
else if ((myStr[i] >= 'a' &amp;&amp; myStr[i] <= 'z') || (myStr[i] >= 'A' &amp;&amp; myStr[i] <= 'Z')) {
   cons_count++;
}
The following is the code to count a number of Vowels and Consonants in a string.
Live Demo
using System;
public class Demo {
   public static void Main() {
      string myStr;
      int i, len, vowel_count, cons_count;
      myStr = "Jack Sparrow";
      vowel_count = 0;
      cons_count = 0;
      // find length
      len = myStr.Length;
      for(i=0; i<len; i++) {
         if(myStr[i] =='a' || myStr[i]=='e' || myStr[i]=='i' || myStr[i]=='o' || myStr[i]=='u' || myStr[i]=='A' || myStr[i]=='E' || myStr[i]=='I' || myStr[i]=='O' || myStr[i]=='U') {
            vowel_count++;
         } else if((myStr[i]>='a' &amp;&amp; myStr[i]<='z') || (myStr[i]>='A' &amp;&amp; myStr[i]<='Z')) {
            cons_count++;
         }
      }
      Console.Write("\nVowel in the string: {0}\n", vowel_count);
      Console.Write("Consonant in the string: {0}\n\n", cons_count);
   }
}
Vowel in the string: 3
Consonant in the string: 8
How to find the largest number contained in a JavaScript array?

To get the largest number in the array, you can try to run the following code. It returns the largest number 530 −
Live Demo
<!DOCTYPE html>
<html>
   <body>
      <script>
         var myArr = [340, 25, 530, 299];
         var max = myArr.reduce(function(a,b){
            return (a > b) ? a : b;
         });
         document.write("Largest number in the array: "+max);
      </script>
   </body>
</html>
Largest number in the array: 530
turtle.title() function in Python

26 Jul, 2020
The turtle module provides turtle graphics primitives, in both object-oriented and procedure-oriented ways. Because it uses Tkinter for the underlying graphics, it needs a version of Python installed with Tk support.
This function is used to set the title of turtle-window. It requires only one argument as “titlestring” a string, to appear in the titlebar of the turtle graphics window. In other words, it is a string to display the title of the turtle window. By default title of the turtle graphics window is “Python Turtle Graphics”.
Syntax :
turtle.title()

Below is the implementation of the above method with some examples :
Example 1 :
Python3
# import packageimport turtle    # make turtle object # and set sizesc = turtle.Screen()sc.setup(400,300)
Output :
Example 2 :
Python3
# import packageimport turtle    # make turtle object # and set sizesc = turtle.Screen()sc.setup(400,300)  # set turtle screen titleturtle.title("Turtle Window For GFG")
Output :
Python-turtle
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
Python | os.path.join() method
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | datetime.timedelta() function
Python | Get unique values from a list
Queue in Java

The queue interface is provided in java.util package and it implements the Collection interface. The queue implements FIFO i.e. First In First Out. This means that the elements entered first are the ones that are deleted first.
A program that demonstrates queue in Java is given as follows −
 Live Demo
import java.util.LinkedList;
import java.util.Queue;
public class Example {
   public static void main(String[] args) {
      Queue<Integer> q = new LinkedList<>();
      q.add(6);
      q.add(1);
      q.add(8);
      q.add(4);
      q.add(7);
      System.out.println("The queue is: " + q);
      int num1 = q.remove();
System.out.println("The element deleted from the head is: " + num1);
System.out.println("The queue after deletion is: " + q);
int head = q.peek();
System.out.println("The head of the queue is: " + head);
int size = q.size();
System.out.println("The size of the queue is: " + size);
}
}
The queue is: [6, 1, 8, 4, 7]
The element deleted from the head is: 6
The queue after deletion is: [1, 8, 4, 7]
The head of the queue is: 1
The size of the queue is: 4
Now let us understand the above program.
Five elements are inserted in the queue. Then the queue is displayed. The code snippet that demonstrates this is given as follows −
Queue<Integer> q = new LinkedList<>();
q.add(6);
q.add(1);
q.add(8);
q.add(4);
q.add(7);
System.out.println("The queue is: " + q);
The element from the head of the queue is deleted and it is displayed. Then the size of the queue is displayed. The code snippet that demonstrates this is given as follows −
int num1 = q.remove();
System.out.println("The element deleted from the head is: " + num1);
System.out.println("The queue after deletion is: " + q);
int head = q.peek();
System.out.println("The head of the queue is: " + head);
int size = q.size();
System.out.println("The size of the queue is: " + size);
How to reverse column order in a matrix with Python?

08 Sep, 2021
In this article, we will see how to reverse the column order of a matrix in Python.
Examples:
Input: 
arr = [[10,20,30],
       [40,50,60],
       [70,80,90]]
Output:
30 20 10 
60 50 40
90 80 70 

Input:
arr = [[15,30],
       [45,60],
       [75,90],
       [105,120]]
Output:
30 15
60 45
90 75
120 105
Matrices are created in python by using nested lists/arrays. However, a more efficient way to handle arrays in python is the NumPy library. To create arrays using NumPy use this or matrix in python once go through this.
Method 1:
Iterate through each rowFor every row, use list comprehension to reverse the row (i.e. a[::-1])Append the reversed rows into a new matrixPrint the matrix
Iterate through each row
For every row, use list comprehension to reverse the row (i.e. a[::-1])
Append the reversed rows into a new matrix
Print the matrix
Example:
Python3
# creating a 3X4 matrix using nested listsmatrix_1 = [['c1', 'c2', 'c3'],            [10, 20, 30],            [40, 50, 60],            [70, 80, 90]] # creating an empty array to store the reversed column matrixmatrix_2 = [] # looping through matrix_1 and appending matrix_2for i in range(len(matrix_1)):    matrix_2.append(matrix_1[i][::-1]) print('Matrix before changing column order:\n')for rows in matrix_1:    print(rows)print('\nMatrix after changing column order:\n')for rows in matrix_2:    print(rows)
Output:
Method 2:
An array object in NumPy is called ndarray, which is created using the array() function. To reverse column order in a matrix, we make use of the numpy.fliplr() method. The method flips the entries in each row in the left/right direction. Column data is preserved but appears in a different order than before.
Syntax:  numpy.fliplr(m)
Parameters: m (array_like) – Input array must be at least 2-D.
Returned Value: ndarray – A view of m is returned with the columns reversed, and this operation’s time complexity is O(1).
Example:
Python3
import numpy as np # creating a numpy array(matrix) with 3-columns and 4-rowsarr = np.array([    ['c1', 'c2', 'c3'],    [10, 20, 30],    [40, 50, 60],    [70, 80, 90]]) # reversing column order in matrixflipped_arr = np.fliplr(arr) print('Array before changing column order:\n', arr)print('\nArray after changing column order:\n', flipped_arr)
Output:
Flipped_arr contains a reversed column order matrix where the column order has changed from c1,c2,c3 to c3,c2,c1, and the elements of each column remain intact under their respective headers (c1,c2,c3).
adnanirshad158
Picked
Python-Matrix
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to iterate through Excel rows in Python?
Rotate axis tick labels in Seaborn and Matplotlib
Deque in Python
Queue in Python
Defaultdict in Python
Check if element exists in list in Python
Python Classes and Objects
Bar Plot in Matplotlib
reduce() in Python
Python | Get unique values from a list
How to declare a multi dimensional dictionary in Python?

Let us declare three dictionary objects as below −
>>> d1={"name":"Ravi","age":25, "marks":60}
>>> d2={"name":"Anil","age":23, "marks":75}
>>> d3={"name":"Asha", "age":20, "marks":70}
Now we shall use them as values in a parent dictionary
>>>twodimdict={1:d1,2:d2,3:d3}
>>>twodimdict
{1: {'name': 'Ravi', 'age': 25, 'marks': 60}, 2: {'name': 'Anil', 'age': 23, 'marks': 75}, 3: {'name': 'Asha', 'age': 20, 'marks': 70}}
Here d1, d2 and d3 are assigned as value to keys 1,2,3
twodimdict [1] returns d1. Value of a key inside d1 can be obtained as below −
>>>twodimdict[1]
{'name': 'Ravi', 'age': 25, 'marks': 60}
>>>twodimdict[1]["age"]
25
Note that the dictionary items are not indexed.
How to Deploy Next.js App to Vercel ?

14 Jul, 2021
Introduction: Vercel is a deployment tool used by frontend developers to instantly deploy and host web applications without knowing complex configurations. 
Easy to use and has a lifetime free tier service which is beneficial for beginners who want to deploy their side-project with minimal support.
Can create an account using GitHub, GitLab, Bitbucket, or with Email.
Allows developers to use a custom domain that is HTTPS enabled.
Can be used to build unlimited websites and APIs.
Changes in data lead to an automatic push of the web page thereby reducing the constraint of static generation.
High-Performance Edge Network leads to faster routing.
Each pull request has its preview URL which is useful while running tests or gathering feedbacks.
Step 1: Create a Next.js App and setup Vercel Account: Create the Next.js app by running the following command:
npx    create-next-app
or
yarn create next-app     
Once the Next.js app is created, go to Vercel website and signup with GitHub/Email-id to create an account. To deploy our application, we need to install the Vercel CLI. Run the following command to install Vercel globally (You can also install Vercel locally in your project folder).
npm i -g vercel
 
To check if vercel is installed in our machine, run the command:
vercel --version
If vercel is installed correctly, it will install the latest version i.e, 23.0.0
Login in to your vercel account by running the following command 
vercel login
You will be prompted with the following question – Enter your email: Enter your mail for confirmation.
Step 2: Deployment: Once you’ve logged in, in order to deploy your Next.js project you need to run ‘vercel’ command.
vercel
The command will show the latest Vercel version and ask the following questions:
Set up and deploy “~/projectname”? [Y/n]:Which scope do you want to deploy to?Link to an existing project? [y/n]What’s your project name?In which directory is your code located?Want to override the settings? [y/n]
Set up and deploy “~/projectname”? [Y/n]:
Which scope do you want to deploy to?
Link to an existing project? [y/n]
What’s your project name?
In which directory is your code located?
Want to override the settings? [y/n]
After you’ve completed these questions, head to your Vercel account and click on the Visit button to see your project live on Vercel.
Note: After deploying your project from the command line, Vercel creates a .vercel folder that contains the project.json file. This file contains the orgId and the projectId keys which are confidential and ‘SHOULD NOT’ be pushed to Git.
Step 3(Optional): Using Git and GitHub for Automation: Vercel automatically deploys any changes made to your Git repository. Each time a new pull or merge request is created, Vercel creates a new build and setups a new deployment.
React-Questions
ReactJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to access Static variable of Outer class from Static Inner class in java?

A class with in another class is known as inner class, you cannot declare a class static unless it is an inner class. A static inner class is just like other class variables. You can access it (static inner class) without instantiation
You can access the static variable of an outer class just using the class name. Following Java example demonstrates how to access static variables of a class from a static inner class.
public class Outer {
   static int data = 200;
   static class InnerDemo {
      public void my_method() {
         System.out.println("This is my nested class");
         System.out.println(Outer.data);
      }
   }
   public static void main(String args[]) {
      Outer.InnerDemo nested = new Outer.InnerDemo();
      nested.my_method();
   }
}
This is my nested class
200
C++ Program to Perform Inorder Non-Recursive Traversal of a Given Binary Tree

If a binary tree is traversed in-order, the left subtree is visited first, then the root and later the right sub-tree. The output the key in ascending order in in_order traversal. This is a C++ Program for Inorder Tree Traversal without Recursion.
Begin
   Declare a structure n.
      Declare d of the integer datatype.
      Declare a pointer l against structure n.
      Declare a pointer r against structure n.
      Declare a constructor of structure n.
         Pass an integer variable d to parameter.
         this->d = d
         l = r = NULL
   Declare inOrder(struct n *root) function.
      Declare a stack s.
      Declare a pointer current against structure n.
         Initialize n *current = root.
      while (current != NULL || s.empty() == false)
         while (current != NULL)
            s.push(current)
            current = current->l
         current = s.top()
         s.pop()
         print current->d.
         current = current->r.
   insert values in nodes of tree.
   Call inOrder(root) function to travern the tree.
End.

 Live Demo
#include<bits/stdc++.h>
using namespace std;
struct n {
   int d;
   struct n* l;
   struct n* r;
   n (int d) {
      this->d = d;
      l = r = NULL;
   }
};
void inOrder(struct n *root) {
   stack<n *> s;
   n *current = root;
   while (current != NULL || s.empty() == false) {
      while (current != NULL) {
         s.push(current);
         current = current->l;
      }
      current = s.top();
      s.pop();
      cout << current->d << " ";
      current = current->r;
   }
}
int main() {
   struct n* root = new n(6);
   root->l = new n(4);
   root->r= new n(7);
   root->l->l = new n(8);
   root->l->r= new n(5);
   root->r->l = new n(9);
   root->r->r = new n(10);
   inOrder(root);
   return 0;
}
8 4 5 6 9 7 10
C# Program to skip elements of an array from the end

Declare an array and initialize elements.
int[] marks = { 45, 50, 60, 70, 85 };
Use the SkipLast() method to skip elements of an array from the end.
IEnumerable<int> selMarks = marks.AsQueryable().SkipLast(3);
The elements are skipped and rest of the elements is returned as shown below −
 Live Demo
using System;
using System.Linq;
using System.Collections.Generic;
public class Demo {
   public static void Main() {
      int[] marks = { 45, 50, 60, 70, 85 };
      Console.WriteLine("Array...");

      foreach (int res in marks)
      Console.WriteLine(res);
      IEnumerable<int> selMarks = marks.AsQueryable().SkipLast(3);
      Console.WriteLine("Array after skipping last 3 elements...");

      foreach (int res in selMarks)
      Console.WriteLine(res);
   }
}
Array...
45
50
60
70
85
Array after skipping last 3 elements...
45
50
Search and Replace with Java regular expressions

Java provides the java.util.regex package for pattern matching with regular expressions. Java regular expressions are very similar to the Perl programming language and very easy to learn.
A regular expression is a special sequence of characters that help you match or find other strings or sets of strings, using a specialized syntax held in a pattern. They can be used to search, edit, or manipulate text and data.
The replaceFirst() and replaceAll() methods replace the text that matches a given regular expression. As their names indicate, replaceFirst replaces the first occurrence, and replaceAll replaces all occurrences.
Live Demo
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexMatches {
   private static String REGEX = "dog";
   private static String INPUT = "The dog says meow. " + "All dogs say meow.";
   private static String REPLACE = "cat";

   public static void main(String[] args) {
      Pattern p = Pattern.compile(REGEX);
      //get a matcher object
      Matcher m = p.matcher(INPUT);
      INPUT = m.replaceAll(REPLACE);
      System.out.println(INPUT);
   }
}
The cat says meow. All cats say meow.
Neo4j - Database Backup and Restore

In Real-time applications, we should take backup of our application Database regularly so that we can restore to some working condition at any failure point.
This rule is applicable for both RDBMS and No SQL databases.
In this section, we are going to discuss about two important DBA tasks.
How to backup a Neo4j Database.
How to restore Neo4j Database to a specific backup.
NOTE:-
These steps are applicable to Windows Operating System only. We should use similar kind of commands to do the same steps in other Operating Systems.
Step 1 - Click on "Neo4j Community" as shown below
Windows "Start" button >> "All Programs" >> "Neo4j Community" >> "Neo4j Community"
By default, it selects c:\Users\[username]\Documents\Neo4j\default.graphdb. If you want, you can change your path to different directory. Here we have changed to our Neo4j Database folder
C:\Ne04j2.0db
Click on "Start" button.
Once the server is started, we can observe our Neo4j Database files are generated at specified directory
Before taking Database backup, first and foremost thing we should do is shutdown the Neo4j Database server.
Click on "Stop" Button to shutdown the server
Step 2 - Our Neo4j Database files are available at C:\Ne04j2.0db
Step 3 - Open command prompt
Step 4 - Create a folder "Neo4jDbBackup-01" at C:\Neo4j  ( This may be any location in your file system)
mkdir C:\Neo4j\Neo4jDbBackup-01
It creates a new folder "Neo4jDbBackup-01" at specified file system location "C:\Neo4j\"
Step 5 - Type the below command and press Enter key
copy C:\Ne04j2.0db C:\Neo4j\Neo4jDbBackup-01
That means our files are copied to required destination folder. Access that folder and observe that folder has our database files.
Step 6 - Use any Windows compression/decompression tool like WinZip, 7 Zip, or WinRar to zip our Database folder.
Now our Neo4jDbBackup-01.zip file is created. If you have any memory constraints in your file system, then remove "Neo4jDbBackup-01" folder at "C:\Neo4j\"
Step 1 - Shutdown the database server. Please refer previous steps to shutdown the server.
Step 2 - Empty the current database folder
Step 3 - Use any Windows compression/decompression tool like WinZip, 7 Zip, or WinRar to unzip our backup folder.
Step 4 - Open command prompt and execute the following command
Copy C:\Neo4j\Neo4jDbBackup-01 C:\Ne04j2.0db
Step 5 - Now we can observe that our database folder contains working backup files
Step 6 - Start the server by clicking on "Start" button.
Now execute some MATCH + RETURN commands to verify whether we have restored our database properly or not
 Print
 Add Notes
 Bookmark this page