code-rag-bench/online-tutorials huggingface dataset:
C# Substring() Method

The Substring() method in C# is used to retrieve a substring from this instance. The substring starts at a specified character position and continues to the end of the string.
The syntax is as follows -
public string Substring (int begnIndex);
public string Substring (int begnIndex, int len);
Above, begnIndex is the zero-based starting character position of a substring in this instance. The len parameter is the number of the substring to retrieve
Let us now see an example -
 Live Demo
using System;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "Katherine";
      string str2 = "PQRS";
      Console.WriteLine("String1 = "+str1);
      Console.WriteLine("String1 ToUpperInvariant = "+str1.ToUpperInvariant());
      Console.WriteLine("String1 Substring from index4 = " + str1.Substring(4));
      Console.WriteLine("\nString2 = "+str2);
      Console.WriteLine("String2 ToUpperInvariant = "+str2.ToLowerInvariant());
      Console.WriteLine("String2 Substring from index2 = " + str2.Substring(2));
   }
}
String1 = Katherine
String1 ToUpperInvariant = KATHERINE
String1 Substring from index4 = erine
String2 = PQRS
String2 ToUpperInvariant = pqrs
String2 Substring from index2 = RS
Let us now see another example -
 Live Demo
using System;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "Notebook";
      string str2 = "Ultrabook";
      Console.WriteLine("String1 = "+str1);
      Console.WriteLine("String1 ToUpperInvariant = "+str1.ToUpperInvariant());
      Console.WriteLine("String1 Substring from index4 = " + str1.Substring(4, 4));
      Console.WriteLine("\nString2 = "+str2);
      Console.WriteLine("String2 ToUpperInvariant = "+str2.ToLowerInvariant());
      Console.WriteLine("String2 Substring from index2 = " + str2.Substring(0, 5));
   }
}
String1 = Notebook
String1 ToUpperInvariant = NOTEBOOK
String1 Substring from index4 = book
String2 = Ultrabook
String2 ToUpperInvariant = ultrabook
String2 Substring from index2 = Ultra
CONCAT() function in SQL Server

28 Dec, 2020
CONCAT() :This function in SQL Server helps to concatenate two or more strings together. CONCAT() function can accept a minimum of 2 parameters and a maximum of 254 parameters.
Syntax :
CONCAT(string_1, string_2, .......string_n)
Parameters :
string_1, string_2, .......string_n –The given strings which need to be concatenated.
Returns :The function concatenates all the given string and returns them as one whole string.
Applicable to the following versions :
SQL Server 2017
SQL Server 2016
SQL Server 2014
SQL Server 2012
Example-1 :The general working of CONCAT() function.
Concatenating 3 strings together with space in between –SELECT CONCAT('PYTHON', ' ', 'is', ' ', 'fun!!!') 
As Combined;Output :CombinedPYTHON is fun!!!
SELECT CONCAT('PYTHON', ' ', 'is', ' ', 'fun!!!') 
As Combined;
Output :
Concatenating more than 3 strings together –SELECT CONCAT
('Every', 'next', 'level', 'of', 'your', 'life', 'demands', 'a', 'new', 'you!') 
As Combined;Output :CombinedEverynextlevelofyourlifedemandsanewyou!
SELECT CONCAT
('Every', 'next', 'level', 'of', 'your', 'life', 'demands', 'a', 'new', 'you!') 
As Combined;
Output :
Example-2 :Using a variable with CONCAT() function, we assign the strings to variables and then concatenate them.
DECLARE @Str1 AS VARCHAR(100)='Think'
DECLARE @Str2 AS VARCHAR(100)='-'
DECLARE @Str3 AS VARCHAR(100)='green'
DECLARE @Str4 AS VARCHAR(100)=' '
DECLARE @Str5 AS VARCHAR(100)='Be'
DECLARE @Str6 AS VARCHAR(100)='-'
DECLARE @Str7 AS VARCHAR(100)='green'

SELECT CONCAT(@Str1, @Str2, @Str3, @str4, @str5, @str6, @str7) AS Combined;
Output :
Example-3 :Concatenating numerical expression using CONCAT() function, here in place of string we combined numeric values.
SELECT CONCAT(13, 03, 1999) 
AS Combined;
Output :
DBMS-SQL
SQL-Server
Technical Scripter 2020
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | os.umask() method

26 Jan, 2022
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.
os.umask() method in Python is used to set the current numeric umask value and get the previous umask value.
umask stands for user file-creation mode mask. This is used to determine the file permission for newly created files or directories.
Syntax: os.umask(mask)
Parameter:mask: An integer value denoting a valid umask value.
Return Type: This method sets the current umask value and returns an integer value which represents the previous umask value.
Code #1: Use of os.umask() method
# Python program to explain os.umask() method     # importing os module import os  # mask# 18 in decimal is# equal to 0o022 in octalmask = 18  # Set the current umask value# and get the previous# umask valueumask = os.umask(mask)    # Print the # current and previous # umask valueprint("Current umask:", mask)print("Previous umask:", umask) 
Current umask: 18
Previous umask: 54

 
Code #2: Passing an octal value as parameter in os.umask() method
# Python program to explain os.umask() method     # importing os module import os  # Octal value for umask# octal value 0o777 is # 511 in decimalmask = 0o777  # Set the current umask value# and get the previous# umask valueumask = os.umask(mask)    # Print the # current and previous # umask valueprint("Current umask:", mask)print("Previous umask:", umask) 
Current umask: 511
Previous umask: 18

TOD
python-os-module
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
List get() method in Java with Examples

11 Dec, 2018
The get() method of List interface in Java is used to get the element present in this list at a given specific index.
Syntax :
E get(int index)

Where, E is the type of element maintained
by this List container.

Parameter : This method accepts a single parameter index of type integer which represents the index of the element in this list which is to be returned.
Return Value: It returns the element at the specified index in the given list.
Errors and exception : This method throws an IndexOutOfBoundsException if the index is out of range (index=size()).
Below programs illustrate the get() method:
Program 1 :
// Java code to demonstrate the working of// get() method in List  import java.util.*;  public class GFG {    public static void main(String[] args)    {        // creating an Empty Integer List        List<Integer> arr = new ArrayList<Integer>(4);          // using add() to initialize values        // [10, 20, 30, 40]        arr.add(10);        arr.add(20);        arr.add(30);        arr.add(40);          System.out.println("List: " + arr);          // element at index 2        int element = arr.get(2);          System.out.println("The element at index 2 is " + element);    }}
List: [10, 20, 30, 40]
The element at index 2 is 30

Program 2 : Program to demonstrate the error.
// Java code to demonstrate the error of// get() method in List  import java.util.*;  public class GFG {    public static void main(String[] args)    {        // creating an Empty Integer List        List<Integer> arr = new ArrayList<Integer>(4);          // using add() to initialize values        // [10, 20, 30, 40]        arr.add(10);        arr.add(20);        arr.add(30);        arr.add(40);          try {            // Trying to access element at index 8            // which will throw an Exception            int element = arr.get(8);        }        catch (Exception e) {            System.out.println(e);        }    }}
java.lang.IndexOutOfBoundsException: Index: 8, Size: 4

Reference: https://docs.oracle.com/javase/7/docs/api/java/util/List.html#get(int)
Java-Collections
Java-Functions
java-list
Java
Java
Java-Collections
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
HTML | DOM Input Image disabled Property

21 Jun, 2022
The HTML DOM Input Image disabled Property is used to set or return the boolean value that represents an image field should be disabled or not. By default, the disabled elements are displayed in gray and are unusable and unclickable. 
Syntax:
It returns the disabled property.
imageObject.disabled
It is used to set the disabled property.
imageObject.disabled = true|false
Property values: This property accepts two parameter which are mentioned above and described below:
true: It specifies the image field is disabled.
false: It specifies the image field is not disabled.
Return value: It returns a boolean value i.e. true if the image field is disabled or false if the image field is not disabled. 
Example 1: This example returns the value of disabled proper 
html
<!DOCTYPE html><html> <head>    <title>        HTML DOM Input Image Disabled property    </title></head> <body style="text-align:center;">     <h1 style="color:green;">      GeeksforGeeks    </h1>    <h4>      DOM Input Image Disabled Property    </h4>    <input id="myImage" formEnctype="application/x-www-form-urlencoded"           type="image" formtarget="#" src="https://media.geeksforgeeks.org/wp-content/uploads/gfg-40.png"           alt="Submit" width="48" height="48" formMethod="post"           disabled>    <br>    <br>    <button onclick="my_geek()">Submit </button>     <h2 id="Geek_h" style="color:green;"></h2>    <script>        function my_geek() {             // Return disabled Property            var txt = document.getElementById(                "myImage").disabled;            document.getElementById(                "Geek_h").innerHTML = txt;        }    </script></body> </html>
Output:
Before Clicking On Button:
 
After Clicking On Button:
 
Example 2: This Example sets the value of the Disabled Property. 
html
<!DOCTYPE html><html> <head>    <title>        HTML DOM Input Image Disabled property    </title></head> <body style="text-align:center;">     <h1 style="color:green;">      GeeksforGeeks    </h1>     <h4>      DOM Input Image Disabled Property    </h4>    <input id="myImage" formEnctype="application/x-www-form-urlencoded"           type="image" formtarget="#" src="https://media.geeksforgeeks.org/wp-content/uploads/gfg-40.png"           alt="Submit" width="48" height="48" formMethod="post"           disabled>    <br>    <br>    <button onclick="my_geek()">Submit </button>     <h2 id="Geek_h" style="color:green;"></h2>    <script>        function my_geek() {             // set Disabled Property.            var txt = document.getElementById(                "myImage").disabled = false;            document.getElementById(                "Geek_h").innerHTML = txt;        }    </script></body> </html>
Output:
Before Clicking On Button:
 
After Clicking On Button:
 
Supported Browsers: The browsers supported by HTML DOM Input Image disabled Property are listed below:
Google Chrome 10.0
Firefox 4.0
Opera 11.0
Safari 5.1
shubham_singh
hritikbhatnagar2182
HTML-DOM
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python PIL | blend() method

25 Jun, 2019
Syntax: PIL.Image.blend(image1, image2, alpha).
Parameter:image1: first imageimage2: second image, must have the same mode and size as the first image.alpha: The interpolation alpha factor. If alpha is 0.0, a copy of the first image is returned. If alpha is 1.0, a copy of the second image is returned. There are no restrictions on the alpha value. If necessary, the result is clipped to fit into the allowed output range.
Image1:
Image2:
# Importing Image module from PIL package from PIL import Image  # creating a image1 object and convert it to mode 'P'im1 = Image.open(r"C:\Users\sadow984\Desktop\i2.PNG").convert('L')  # creating a image2 object and convert it to mode 'P'im2 = Image.open(r"C:\Users\sadow984\Desktop\c2.PNG").convert('L')  # alpha is 0.0, a copy of the first image is returnedim3 = Image.blend(im1, im2, 0.0)  # to show specified image im3.show()
Output:
# Importing Image module from PIL package from PIL import Image  # creating a image1 object and convert it to mode 'P'im1 = Image.open(r"C:\Users\sadow984\Desktop\i2.PNG").convert('L')  # creating a image2 object and convert it to mode 'P' im2 = Image.open(r"C:\Users\sadow984\Desktop\c2.PNG").convert('L')  # alpha is 1.0, a copy of the second image is returnedim3 = Image.blend(im1, im2, 0.0)  # to show specified image im3.show()
Output:
python-utility
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
JavaScript if else else if

Conditional statements are used to perform different actions based on different conditions.
Very often when you write code, you want to perform different actions for different decisions.
You can use conditional statements in your code to do this.
In JavaScript we have the following conditional statements:
Use if to specify a block of code to be executed, if a specified condition is true
Use else to specify a block of code to be executed, if the same condition is 
  false
Use else if to specify a new condition to test, if the first condition is false
Use switch to specify many alternative blocks of code to be executed
The switch statement is described in the next chapter.
Use the if statement to specify a block of JavaScript code to 
be executed if a condition is true.
Note that if is in lowercase letters. Uppercase letters (If or IF) will generate a JavaScript error.
Make a "Good day" greeting if the hour is less than 
18:00:
The result of greeting will be:
Use the else statement to specify a block of code to be 
executed if the condition is 
false.
If the hour is less than 18, create a "Good day" 
greeting, otherwise "Good evening":
The result of greeting will be:
Use the else if statement to specify a new condition if the first condition is false.
If time is less than 10:00, create a "Good 
morning" 
greeting, if not, but time is less than 20:00, create a "Good day" greeting, 
otherwise a "Good evening":
The result of greeting will be:
Random link
This example will write a link to either W3Schools or to the World Wildlife 
Foundation (WWF). By using a random number, there is a 50% chance for each of the 
links.
Fix the if statement to alert "Hello World" if x is greater than y.
if x > y 
  alert("Hello World");


Start the Exercise
We just launchedW3Schools videos
Get certifiedby completinga course today!
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
help@w3schools.com
Your message has been sent to W3Schools.
Count number of lines in a text file in Python

08 Jul, 2022
Prerequisites: File Handling in Python 
Counting the number of characters is important because almost all the text boxes that rely on user input have a certain limit on the number of characters that can be inserted. For example, If the file is small, you can use readlines() or an A loop approach. If you have a lot of files to work with To determine line count, use the Generator and Raw interface,  If you don’t want to load the complete file in, utilize a loop and enumerate() for huge files. This program in Data file handling in Python emphasizes counting the number of lines in a text file in Python. 
Below is the implementation. 
Let’s suppose the text file looks like this – 
myfile.txt
The readlines() are used to read all the lines at a single go and then return them as each line a string element in a list. This function can be used for small files
Python3
with open(r"myfile.txt", 'r') as fp:    lines = len(fp.readlines())    print('Total Number of lines:', lines)
Output:
Total Number of lines: 5
Enumerate() method adds a counter to an iterable and returns it in a form of enumerating object. 
Python3
with open(r"myfile.txt", 'r') as fp:    for count, line in enumerate(fp):        passprint('Total Number of lines:', count + 1)
Output:
Total Number of lines: 5
Loops python is used for sequential traversal. here we will count the number of lines using the loop and if statement. if help us to determine is there any character or not, if there will be any character present the IF condition returns true and the counter will increment.
Python3
# Opening a filefile = open("gfg.txt", "r")Counter = 0 # Reading from fileContent = file.read()CoList = Content.split("\n") for i in CoList:    if i:        Counter += 1 print("This is the number of lines in the file")print(Counter)
Output:
This is the number of lines in the file
4
Loops python is used for sequential traversal. here we will count the number of lines using the sum function in Python. if help us to determine is there any character or not, if there will be any character present the IF condition returns true and the counter will increment.
Python3
with open(r"myfile.txt", 'r') as fp:    lines = sum(1 for line in fp)    print('Total Number of lines:', lines)
Output:
Total Number of lines: 5
surajkumarguptaintern
Python file-handling-programs
python-file-handling
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Angular CLI - ng version Command

This chapter explains the syntax, options of ng version command along with an example.
The syntax for ng version command is as follows −
ng version [options]
ng v [options]

ng version command shows the Angular CLI version installed.
Options are optional parameters.
An example for ng version command is given below −
\>Node ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / ? \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 9.1.0
Node: 12.16.1
OS: win32 x64
Random Pick with Weight in C++

Suppose we have an array w of positive integers, were w[i] describes the weight of index i, we have to define a function pickIndex() which randomly picks an index in proportion to its weight.
So if the input is like [1,3], call pickIndex() five times, then the answer may come as − 0, 1, 1, 1, 0.
To solve this, we will follow these steps −
Define an array v,
Through the initializer, initialize as
n := w[0]
for i in range 1 to size of ww[i] := w[i] + w[i – 1]n := w[i]
w[i] := w[i] + w[i – 1]
n := w[i]
v = w
The pickIndex() will work as follows −
Take a random number r, perform r mod last element of v
take the smallest number, not smaller than r from v, then subtract first number of v from the element and return.
Let us see the following implementation to get better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
class Solution {
   public:
   int n;
   vector <int> v;
   Solution(vector<int>& w) {
      srand(time(NULL));
      n = w[0];
      for(int i = 1; i < w.size(); i++){
         w[i] += w[i - 1];
         n = w[i];
      }
      v = w;
   }
   int pickIndex() {
      return upper_bound(v.begin(), v.end(), rand() % v.back()) - v.begin();
   }
};
main(){
   vector<int> v = {1,3};
   Solution ob(v);
   cout << (ob.pickIndex()) << endl;
   cout << (ob.pickIndex()) << endl;
   cout << (ob.pickIndex()) << endl;
   cout << (ob.pickIndex()) << endl;
   cout << (ob.pickIndex()) << endl;
}
Initialize with [1, 3] and call pickIndex five times.
1
1
1
1
0
Docker – Concept of Dockerfile

28 Jul, 2021
Dockerfile is a simple text file with instructions to build a Docker image.  As shown below dockerfile is a simple text file where we give some instructions to build an image. And when we run docker build command a file image gets created.
If you want to create your own image you can use a dockerfile. So dockerfile is basically automation of docker image creation and there are some basic instructions that you use in the docker file. Let’s check out how it’s done.
Follow the below steps to create a dockerfile:
Step 1: Create a file name called “Dockerfile”.By default when you run the docker build commands docker searches for a file named Dockerfile. However, it is not compulsory, you can also give some different names, and then you can tell the docker that this particular file is a local file but for now we will go with the Dockerfile.
Step 2:  The very first instruction that a dockerfile starts with is FROM. Here you have to give a base image. So for example, if you want to get a base image from ubuntu we will use FROM ubuntu.  
FROM ubuntu
Then the other instruction is you have to give a MAINTAINER. This is optional but its best practice that you give the maintainer of this image so that it is very easy to find out who is the maintainer and you can give your name and email as well. And if you want you can just give the email as well without giving the name. But here we are giving the entire thing here. 
MAINTAINER YOUR_NAME <YOUR_EMAIL_ID>
Next, we want to run something so we will say run any command we can use RUN and add the command that you need to run.
RUN apt-get update
. And if you want to run something on the command line during container creation you can give CMD and inside square brackets, we add the command. Here it ba as shown below:
CMD ["echo", "Hello Geeks!"]
At this point the file will have the following commands:
FROM ubuntu
MAINTAINER YOUR_NAME <YOUR_EMAIL_ID>
RUN apt-get update
CMD ["echo", "Hello Geeks!"]
Step 3: Now we have to build the image so here are the commands you can use:
docker build /<FILE_LOCATION> 
Or,
docker build . -f Dockerfile.txt
It says docker build and you have to give the location of your docker file.  This will start building the image.
Now if we use the below command, we can check if the docker image has been created:
docker images
So we have successfully created a Dockerfile and a respective Docker image for the same.
docker
Picked
Advanced Computer Subject
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
System Design Tutorial
Docker - COPY Instruction
ML | Monte Carlo Tree Search (MCTS)
Markov Decision Process
How to Run a Python Script using Docker?
Copying Files to and from Docker Containers
ML | Underfitting and Overfitting
Basics of API Testing Using Postman
Clustering in Machine Learning
ML | Label Encoding of datasets in Python
Python | os.sched_setaffinity() method

02 Nov, 2021
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.
os.sched_setaffinity() method in Python is used to set the CPU affinity mask of a process indicated by the specified process id. A process’s CPU affinity mask determines the set of CPUs on which it is eligible to run.
Note: This method is only available on some UNIX platforms.
Syntax: os.sched_setaffinity(pid, mask)
Parameter:pid: The process id of the process whose CPU affinity mask is to be set required. Process’s CPU affinity mask determines the set of CPUs on which it is eligible to run.A pid of 0 represents the calling process.mask: An iterable of integers representing the set of CPUs to which the process should be restricted.
Return Type: This method does not return any value.
# Python program to explain os.sched_setaffinity() method    # importing os module import os  # Get the number of CPUs# in the system# using os.cpu_count() methodprint("Number of CPUs:", os.cpu_count())  # Get the set of CPUs# on which the calling process# is eligible to run. using# os.sched_getaffinity() method# 0 as PID represents the# calling processpid = 0affinity = os.sched_getaffinity(pid)  # Print the resultprint("Process is eligible to run on:", affinity)    # Change the CPU affinity mask# of the calling process# using os.sched_setaffinity() method  # Below CPU affinity mask will# restrict a process to only# these 2 CPUs (0, 1) i.e process can# run on these CPUs onlyaffinity_mask = {0, 1}pid = 0os.sched_setaffinity(0, affinity_mask)print("CPU affinity mask is modified for process id % s" % pid)     # Now again, Get the set of CPUs# on which the calling process# is eligible to run.pid = 0affinity = os.sched_getaffinity(pid)  # Print the resultprint("Now, process is eligible to run on:", affinity)
Number of CPUs: 4
Process is eligible to run on: {0, 1, 2, 3}
CPU affinity mask is modified for process id 0
Now, process is eligible to run on: {0, 1}

References:
https://docs.python.org/3/library/os.html#os.sched_setaffinity
https://linux.die.net/man/2/sched_getaffinity
adnanirshad158
clintra
python-os-module
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 | os.path.join() method
Introduction To PYTHON
Python OOPs Concepts
How to drop one or multiple columns in Pandas Dataframe
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | Get unique values from a list
Create a directory in Python
How to Select date from a datepicker with Selenium Webdriver using Python?

We can select a date from a datepicker with Selenium webdriver using Python. To identify a particular date, first we have to use the find_elements method and identify all the dates having a common locator value.
The find_elements returns a list of matching elements. We have to iterate through this list and search for the date which meets our criteria. Once we get that date, we would select it. Then break out from this iteration.
from selenium import webdriver
#set chromodriver.exe path
driver = webdriver.Chrome(executable_path="C:\\chromedriver.exe")
driver.implicitly_wait(0.5)
#launch URL
driver.get("https://jqueryui.com/datepicker/")
#switch to frame
l = driver.find_element_by_xpath("//iframe[@class='demo-frame']")
driver.switch_to.frame(l);
#identify element inside frame
d= driver.find_element_by_id("datepicker")
d.click()
#identify list of all dates
m = driver.find_elements_by_xpath("//table/tbody/tr/td")
#iterate over list
for i in m:
#verify required date then click
   if i.text == '3':
      i.click()
   break
#get selected date
s = d.get_attribute('value')
print("Date entered is: ")
print(s)
#browser quit
driver.quit()
Interface in Java

An interface is a reference type in Java. It is similar to a class. It is a collection of abstract methods. A class implements an interface, thereby inheriting the abstract methods of the interface.
Along with abstract methods, an interface may also contain constants, default methods, static methods, and nested types. Method bodies exist only for default methods and static methods.
Writing an interface is similar to writing a class. But a class describes the attributes and behaviors of an object. And an interface contains behaviors that a class implements.
Unless the class that implements the interface is abstract, all the methods of the interface need to be defined in the class.
An interface is similar to a class in the following ways −
An interface can contain any number of methods.
An interface is written in a file with a .java extension, with the name of the interface matching the name of the file.
The byte code of an interface appears in a .class file.
Interfaces appear in packages, and their corresponding bytecode file must be in a directory structure that matches the package name.
However, an interface is different from a class in several ways, including −
You cannot instantiate an interface.
An interface does not contain any constructors.
All of the methods in an interface are abstract.
An interface cannot contain instance fields. The only fields that can appear in an interface must be declared both static and final.
An interface is not extended by a class; it is implemented by a class.
An interface can extend multiple interfaces.
Declaring Interfaces
The interface keyword is used to declare an interface. Here is a simple example to declare an interface −
Example
Following is an example of an interface − 
/* File name : NameOfInterface.java */
import java.lang.*;
// Any number of import statements
public interface NameOfInterface {
   // Any number of final, static fields //
   Any number of abstract method declarations
}
Sort an array of objects using Boolean property in JavaScript

30 Jan, 2020
Given the JavaScript array containing Boolean values. The task is to sort the array on the basis of Boolean value with the help of JavaScript. Here 2 approaches are discussed here.Approach 1:
Use JavaScript Array.sort() method.
In Comparison condition, Use === operator to compare the Boolean objects.
Return 0, 1 and -1 means equal, greater and smaller respectively depending upon the comparison.
Example 1: This example implements the above approach.
<!DOCTYPE HTML><html>  <head>    <title>        Sort an array of objects by a      Boolean property in JavaScript.    </title>    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js">    </script></head>  <body style="text-align:center;">    <h1 style="color:green;">              GeeksForGeeks          </h1>    <p id="GFG_UP">    </p>    <button onclick="GFG_Fun();">        click here    </button>    <p id="GFG_DOWN"        style="color: green;">    </p>    <script>        var up = document.getElementById('GFG_UP');        var down = document.getElementById('GFG_DOWN');        a = [false, true, false, true, false];        up.innerHTML =            "Click on the button to sort the array"+          "on boolean property.<br>Array = [" + a + "]";          function GFG_Fun() {            a.sort(function(x, y) {                return (x === y) ? 0 : x ? -1 : 1;            });            down.innerHTML = "Sorted Array - [" + a + "]";        }    </script></body>  </html>
Output:
Before clicking on the button:
After clicking on the button:
Approach 2:
Use JavaScript Array.sort() method.
In Comparison condition, Subtract the first element from the second one to compare the objects and return that value.
Use .reverse() method, If the result is needed to be reversed.
Example 2: This example implements the above approach.
<!DOCTYPE HTML><html>  <head>    <title>        Sort an array of objects by a       Boolean property in JavaScript.    </title>    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js">    </script></head>  <body style="text-align:center;">    <h1 style="color:green;">              GeeksForGeeks          </h1>    <p id="GFG_UP">    </p>    <button onclick="GFG_Fun();">        click here    </button>    <p id="GFG_DOWN"       style="color: green;">    </p>    <script>        var up = document.getElementById('GFG_UP');        var down = document.getElementById('GFG_DOWN');        a = [false, true, false, true, false];        up.innerHTML =           "Click on the button to sort the array on boolean "+          "property.<br>Array = [" + a + "]";          function GFG_Fun() {            a.sort((a, b) => b - a).reverse();            down.innerHTML = "Sorted Array - [" + a + "]";        }    </script></body>  </html>
Output:
Before clicking on the button:
After clicking on the button:
JavaScript-Misc
JavaScript
Web Technologies
Web technologies Questions
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Sort DataFrame by column name in R

26 Mar, 2021
Sorting is the process of ordering items. It can be ascending order, descending order, alphabetical order, numerical order. To sort a DataFrame by column name in R programming, we can use various methods as discussed below. To get a better understanding of how to sort DataFrame by column name, let’s take some examples.
Example:
Let’s suppose we have the following dataset with column names as English alphabets and tuples are integer values. Now we want to sort the column by column name in alphabetical order. 
 
  Column Names          
R
o
w
s
After sorting DataFrame by column name it should look alike this:
R
o
w
s
dplyr is used to manipulate the DataFrame and names is used to set or get t the object name in R. To use dplyr, it needs to be installed explicitly.
Approach
Import library
Create data frame
Sort the DataFrame using sort function and pass the DataFrame name as an argument.
Syntax:
DataFrame %>% select(sort(names(DataFrame)))
Display sorted dataframe
Example:
R
#Sort DataFrame by column name in R  # Creating a dataset.z <- c(1,6,5,5,6)x <- c(6,2,3,7,4)y <- c(2,4,4,0,3)a <- c(4,2,3,9,7)  dataframe <- data.frame(Banana = z,Orange=x,Mango=y,Apple=a)  # install dplyr packageinstall.packages("dplyr")  # loading librarylibrary("dplyr")  # sorting dataframe %>% select(sort(names(dataframe)))dataframe
Output:
Sorted DataFrame
We can use the order function to sort the columns by column name.
Syntax:
order(names(dataframe))
Approach
Create dataframe
Pass the names of columns in order function
Save the sorted data
Display result
Program:
R
#Sort DataFrame by column name in R  # Creating a dataset.z <- c(1,6,5,5,6)x <- c(6,2,3,7,4)y <- c(2,4,4,0,3)a <- c(4,2,3,9,7)  dataframe <- data.frame(Banana = z,Orange=x,Mango=y,Apple=a)  # sorting dataframe[order(names(dataframe))]
Output:
Sorted dataframe
Picked
R DataFrame-Programs
R-DataFrame
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?
How to filter R DataFrame by values in a column?
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 ?
Tryit Editor v3.7

Tryit: The padding-left property
How to auto increment with 1 after deleting data from a MySQL table?

For this, you can use TRUNCATE TABLE command. Let us first create a table −
mysql> create table DemoTable1796
     (
     StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
     StudentName varchar(20)
     );
Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1796(StudentName) values('Chris Brown');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1796(StudentName) values('David Miller');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1796(StudentName) values('John Doe');
Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement
mysql> select * from DemoTable1796;
This will produce the following output
+-----------+--------------+
| StudentId | StudentName  |
+-----------+--------------+
|         1 | Chris Brown  |
|         2 | David Miller |
|         3 | John Doe     |
+-----------+--------------+
3 rows in set (0.00 sec)
Here is the query to delete records from the table −
mysql> delete from DemoTable1796;
Query OK, 3 rows affected (0.00 sec)
Now insert a record into the table
mysql> insert into DemoTable1796(StudentName) values('John Doe');
Query OK, 1 row affected (0.00 sec)
mysql> select * from DemoTable1796;
+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
|         4 | John Doe    |
+-----------+-------------+
1 row in set (0.00 sec)
Now you can use TRUNCATE TABLE command
mysql> truncate table DemoTable1796;
Query OK, 0 rows affected (0.00 sec)
Now, let us insert some records into the table
mysql> insert into DemoTable1796(StudentName) values('John Doe');
Query OK, 1 row affected (0.00 sec)
mysql> select * from DemoTable1796;
+-----------+-------------+
| StudentId | StudentName |
+-----------+-------------+
|         1 | John Doe    |
+-----------+-------------+
1 row in set (0.00 sec)
Java program to find the area of a circle

Area of a circle is the product of the square of its radius, and the value of PI, Therefore, to calculate the area of a rectangle
Get the radius of the circle.
Calculate the square of the radius.
Calculate the product of the value of PI and the value of the square of the radius.
Print the result.
import java.util.Scanner;
public class AreaOfCircle {
   public static void main(String args[]){
      int radius;
      double area;
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the radius of the circle ::");
      radius = sc.nextInt();
      area = (radius*radius)*Math.PI;
      System.out.println("Area of the circle is ::"+area);
   }
}
Enter the radius of the circle ::
55
Area of the circle is ::9503.317777109125
Tryit Editor v3.7

Tryit: Use six of the animation properties
MySQL query to return a string as a result of IF statement?

Let us first create a table −
mysql> create table DemoTable
(
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   EmployeeSalary int
);
Query OK, 0 rows affected (1.68 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(EmployeeSalary) values(12000);
Query OK, 1 row affected (0.24 sec)
mysql> insert into DemoTable(EmployeeSalary) values(20000);
Query OK, 1 row affected (0.55 sec)
mysql> insert into DemoTable(EmployeeSalary) values(11500);
Query OK, 1 row affected (0.94 sec)
mysql> insert into DemoTable(EmployeeSalary) values(15500);
Query OK, 1 row affected (0.44 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+----------------+
| Id | EmployeeSalary |
+----+----------------+
|  1 | 12000          |
|  2 | 20000          |
|  3 | 11500          |
|  4 | 15500          |
+----+----------------+
4 rows in set (0.00 sec)
Following is the query to return a string as a result of IF statement −
mysql> select Id,if(EmployeeSalary <= 12000 ,'Internship Employee','FullTime Employee') as status from DemoTable;
This will produce the following output −
+----+---------------------+
| Id | status              |
+----+---------------------+
|  1 | Internship Employee |
|  2 | FullTime Employee   |
|  3 | Internship Employee |
|  4 | FullTime Employee   |
+----+---------------------+
4 rows in set (0.00 sec)
How to create a mega menu (full-width dropdown menu in a navigation bar) with HTML and CSS?

Following is the code to create a mega menu using HTML and CSS −
 Live Demo
<!DOCTYPE html>
<html>
<head>
<style>
body {
   margin: 0;
   padding: 0;
}
*,*::before,*::after{
   box-sizing: border-box;
}
nav {
   overflow: hidden;
   background-color: rgb(2, 161, 127);
   font-family: Arial, Helvetica, sans-serif;
}
nav a {
   float: left;
   font-size: 16px;
   color: white;
   text-align: center;
   padding: 14px 16px;
   text-decoration: none;
}
.dropdown {
   float: left;
   overflow: hidden;
}
.dropdown .megaButton {
   font-size: 16px;
   border: none;
   outline: none;
   color: white;
   padding: 14px 16px;
   background-color: inherit;
   font: inherit;
   margin: 0;
}
nav a:hover, .dropdown:hover .megaButton {
   background-color: rgb(0, 63, 146);
}
.megaContent {
   text-align: center;
   display: none;
   position: absolute;
   background-color: #f9f9f9;
   width: 100%;
   left: 0;
   z-index: 1;
}
.megaContent .megaHeader {
   background: rgb(119, 6, 194);
   padding: 16px;
   color: white;
}
.dropdown:hover .megaContent {
   display: block;
}
.megaColumn {
   float: left;
   width: 50%;
   padding: 10px;
   background-color: rgb(233, 255, 198);
   height: 250px;
}
.megaColumn .links {
   color: black;
   padding: 16px;
   margin:10px;
   text-decoration: none;
   display: block;
   text-align: left;
   border-bottom: 4px solid rgb(69, 0, 90);
}
.megaColumn a:hover {
   background-color: lightblue;
}
/*Float reset trick for clearing floats*/
.megaRow:after {
   content: "";
   display: table;
   clear: both;
}
</style>
</head>
<body>
<nav>
<a class="links" href="#">Home</a>
<a class="links" href="#">About</a>
<a class="links" href="#">Contact Us</a>
<a class="links" href="#">More Info</a>
<div class="dropdown">
<button class="megaButton">Projects ></button>
<div class="megaContent">
<div class="megaHeader">
<h2>Projects Menu</h2>
</div>
<div class="megaRow">
<div class="megaColumn">
<h3>Commercial</h3>
<a class="links" href="#">Project 1</a>
<a class="links" href="#">Project 2</a>
</div>
<div class="megaColumn">
<h3>Non-Commerial</h3>
<a class="links" href="#">Project 1</a>
<a class="links" href="#">Project 2</a>
</div>
</div>
</div>
</div>
</nav>
</body>
</html>
The above code will produce the following output −
On hovering over the Project dropdown button −
Ruby Integer abs() function with example - GeeksforGeeks

09 Jan, 2020
The abs() function in Ruby returns the absolute value of the integer.
Syntax: (number).abs
Parameter: The function takes the integer whose absolute value is to be returned.
Return Value: The function returns the absolute value of the integer.
Example #1:
# Ruby program Integer abs() function  # Initializing the numbers num1 = -21num2 = 21 num3 = 0 num4 = -100          # Printing the absolute value of integers puts (num1).absputs (num2).absputs (num3).absputs (num4).abs
Output :
21
21
0
100

Example #2:
# Ruby program of Integer abs() function  # Initializing the numbers num1 =29num2 = -7num3 = 90num4 = -10         # Printing the absolute value of integers puts (num1).absputs (num2).absputs (num3).absputs (num4).abs
Output:
29
7
90
10

Ruby Integer-class
Ruby-Methods
Ruby
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Ruby | Array count() operation
Include v/s Extend in Ruby
Ruby | Array slice() function
Ruby | Enumerator each_with_index function
Global Variable in Ruby
Ruby | Array select() function
Ruby | Hash delete() function
Ruby | String capitalize() Method
Ruby | String gsub! Method
How to Make a Custom Array of Hashes in Ruby?
HTML5 using src using raw binary data

If an audio file is stored in database and then we want to use this file as a blob or binary in an application where audio source is according to session then binary data is returned through ${sessionScope.user.music}. To load the audio file in an audio tag, data:audio/mp3;base64 works well.
As for the image, image tag is used as follows:
<img src="data:image/gif;base64,source “,width="30" height="25" alt="My Image">
Similarly for audio, audio tag data:audio/mp3 is used.
DoubleStream max() in Java with examples - GeeksforGeeks

06 Dec, 2018
java.util.stream.DoubleStream in Java 8, deals with primitive doubles. It helps to solve the problems like finding maximum value in array, finding minimum value in array, sum of all elements in array, and average of all values in array in a new way. DoubleStream max() returns an OptionalDouble describing the maximum element of this stream, or an empty optional if this stream is empty.
Syntax :
OptionalDouble() max()

Where, OptionalDouble is a container object which 
may or may not contain a double value.

Note :
Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero.This is a special case of a reduction.
Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero.
This is a special case of a reduction.
Example 1 :
// Java code for DoubleStream max()import java.util.*;import java.util.stream.DoubleStream;  class GFG {      // Driver code    public static void main(String[] args)    {        // creating a stream        DoubleStream stream = DoubleStream.of(-9.5, -18.6, 54.3,                                            8.5, 7.4, 14.2, 3.9);          // OptionalDouble is a container object        // which may or may not contain a        // double value.        OptionalDouble obj = stream.max();          // If a value is present, isPresent() will        // return true and getAsDouble() will        // return the value        if (obj.isPresent()) {            System.out.println(obj.getAsDouble());        }        else {            System.out.println("-1");        }    }}
54.3

Example 2 :
// Java code for DoubleStream max()import java.util.*;import java.util.stream.DoubleStream;  class GFG {      // Driver code    public static void main(String[] args)    {        // OptionalDouble is a container object        // which may or may not contain a        // double value.        OptionalDouble obj = DoubleStream.empty()                                 .max();          // If a value is present, isPresent() will        // return true and getAsDouble() will        // return the value        if (obj.isPresent()) {            System.out.println(obj.getAsDouble());        }        else {            System.out.println("-1");        }    }}
-1

Java - util package
java-DoubleStream
Java-Functions
java-stream
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
HashMap in Java with Examples
Object Oriented Programming (OOPs) Concept in Java
Interfaces in Java
ArrayList in Java
Initialize an ArrayList in Java
Overriding in Java
LinkedList in Java
How to iterate any Map in Java
Queue Interface In Java
Collections in Java
Change the padding of a button with CSS

To change the padding of a button, use the padding property.
You can try to run the following code to change the button’s padding
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <style>
         .button {
            background-color: yellow;
            color: black;
            text-align: center;
            font-size: 15px;
            padding: 10px;
         }
      </style>
   </head>
   <body>
      <h2>Result</h2>
      <p>Click below for result:</p>
      <button class = "button">Result</button>
   </body>
</html>
Erlang - Web Programming

In Erlang, the inets library is available to build web servers in Erlang. Let’s look at some of the functions available in Erlang for web programming. One can implement the HTTP server, also referred to as httpd to handle HTTP requests.
The server implements numerous features, such as −
Secure Sockets Layer (SSL)
Erlang Scripting Interface (ESI)
Common Gateway Interface (CGI)
User Authentication (using Mnesia, Dets or plain text database)
Common Logfile Format (with or without disk_log(3) support)
URL Aliasing
Action Mappings
Directory Listings
The first job is to start the web library via the command.
inets:start()

The next step is to implement the start function of the inets library so that the web server can be implemented.
Following is an example of creating a web server process in Erlang.
-module(helloworld). 
-export([start/0]). 

start() ->
   inets:start(), 
   Pid = inets:start(httpd, [{port, 8081}, {server_name,"httpd_test"}, 
   {server_root,"D://tmp"},{document_root,"D://tmp/htdocs"},
   {bind_address, "localhost"}]), io:fwrite("~p",[Pid]).
The following points need to be noted about the above program.
The port number needs to be unique and not used by any other program. The httpd service would be started on this port no.
The port number needs to be unique and not used by any other program. The httpd service would be started on this port no.
The server_root and document_root are mandatory parameters.
The server_root and document_root are mandatory parameters.
Following is the output of the above program.
{ok,<0.42.0>}

To implement a Hello world web server in Erlang, perform the following steps −
Step 1 − Implement the following code −
-module(helloworld). 
-export([start/0,service/3]). 

start() ->
   inets:start(httpd, [ 
      {modules, [ 
         mod_alias, 
         mod_auth, 
         mod_esi, 
         mod_actions, 
         mod_cgi, 
         mod_dir,
         mod_get, 
         mod_head, 
         mod_log, 
         mod_disk_log 
      ]}, 
      
      {port,8081}, 
      {server_name,"helloworld"}, 
      {server_root,"D://tmp"}, 
      {document_root,"D://tmp/htdocs"}, 
      {erl_script_alias, {"/erl", [helloworld]}}, 
      {error_log, "error.log"}, 
      {security_log, "security.log"}, 
      {transfer_log, "transfer.log"}, 
      
      {mime_types,[ 
         {"html","text/html"}, {"css","text/css"}, {"js","application/x-javascript"} ]} 
   ]). 
         
service(SessionID, _Env, _Input) -> mod_esi:deliver(SessionID, [ 
   "Content-Type: text/html\r\n\r\n", "<html><body>Hello, World!</body></html>" ]).
Step 2 − Run the code as follows. Compile the above file and then run the following commands in erl.
c(helloworld).

You will get the following output.
{ok,helloworld}

The next command is −
inets:start().

You will get the following output.
ok

The next command is −
helloworld:start().

You will get the following output.
{ok,<0.50.0>}

Step 3 − You can now access the url - http://localhost:8081/erl/hello_world:service.
 Print
 Add Notes
 Bookmark this page