code-rag-bench/online-tutorials huggingface dataset:
Why an interface cannot implement another interface in Java?

An interface cannot implement another interface in Java.
An interface in Java is essentially a special kind of class. Like classes, the interface contains methods and variables. Unlike classes, interfaces are always completely abstract.
An interface is defined just like a class except for the keyword interface in place of a class, the variables are declared in an interface are static and final and the methods are defined in an interface are public abstract methods.
An interface can extend any number of interfaces but one interface cannot implement another interface, because if any interface is implemented then its methods must be defined and interface never has the definition of any method.
If we try to implement an interface with another interface, it will throw a compile-time error in Java.
interface MainInterface {
   void mainMethod();
}
interface SubInterface extends MainInterface { // If we put implements keyword in place of extends,                                               // compiler throws an error.
   void subMethod();
}
class MainClass implements MainInterface {
   public void mainMethod() {
      System.out.println("Main Interface Method");
   }
   public void subMethod() {
      System.out.println("Sub Interface Method");
   }
}
public class Test {
   public static void main(String args[]) {
      MainClass main = new MainClass();
      main.mainMethod();
      main.subMethod();
   }
}
Main Interface Method
Sub Interface Method
How to use SQLCA in a COBOL-DB2 program? What is the purpose of SQLCA?

SQLCA stands for SQL-Communication Area. It is a medium through which DB2 can
communicate with the COBOL program. In a typical COBOL-DB2 program, there are many
SQL statements used. The main purpose of SQLCA is to inform the COBOL program about
the status and other details of the most recently executed SQL query.
The SQLCA has a total length of 136 bytes and it is composed of various fields like
SQLCODE, SQLERRD, SQLWARN, etc. Each of these fields give specific details of the last
executed SQL query.
For example, SQLCODE returns the DB2 error code (if any), SQLWARN returns the warning
issued while executing SQL statements.
The SQLCA is declared in COBOL working storage area with INCLUDE statement as below−
EXEC SQL
INCLUDE SQLCA
END-EXEC
C++ | Inheritance | Question 3 - GeeksforGeeks

28 Jun, 2021
Assume that an integer takes 4 bytes and there is no alignment in following classes, predict the output.
#include<iostream>using namespace std;  class base {    int arr[10];};  class b1: public base { };  class b2: public base { };  class derived: public b1, public b2 {};  int main(void){  cout << sizeof(derived);  return 0;}
(A) 40(B) 80(C) 0(D) 4Answer: (B)Explanation: Since b1 and b2 both inherit from class base, two copies of class base are there in class derived. This kind of inheritance without virtual causes wastage of space and ambiguities. virtual base classes are used to save space and avoid ambiguities in such cases. For example, following program prints 48. 8 extra bytes are for bookkeeping information stored by the compiler (See this for details)
#include<iostream>
using namespace std;
 
class base {
  int arr[10];     
};
 
class b1: virtual public base { };
 
class b2: virtual public base { };
 
class derived: public b1, public b2 {};
 
int main(void)
{ 
  cout << sizeof(derived);
  return 0;
} 
Quiz of this Question
C++-Inheritance
Inheritance
C Language
C++ Quiz
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
fork() in C
Command line arguments in C/C++
Function Pointer in C
Substring in C++
Structures in C
C++ | Exception Handling | Question 3
C++ | new and delete | Question 4
C++ | Operator Overloading | Question 10
C++ | Virtual Functions | Question 2
C++ | Virtual Functions | Question 12
Cognizant GenC Next Interview Experience - GeeksforGeeks

05 Oct, 2021
Cognizant was hiring from on-campus through the Digital Nurture learning platform. Digital Base 2 students were eligible for the Genc next profile.
Round 1: It was a 2 hours exam that consists of questions on
Java
HTML,CSS, JavaScript
C#
RDBMS
The students need to secure 60% in this round and then they were eligible for round 2(Digital Base 2)
Round 2: This round was also of 2 hours which consists of questions on
Advance Java(OOPs concept, JDBC, JUnit, Collections, Lambda Functions)
Pl/SQL
MCQ on Advance java, RDBMS, Web, and Cloud Computing.
After this round students were selected for the Genc next technical interview.
Round 3: Technical Round Interview
My interview was fully based on Java as the role was for the Java Developer.
Introduce Yourself
Explain Oops concept
Type of Polymorphism with example
Difference between method overloading and method overriding
Access modifiers in java
Difference between abstract and interface
Are multiple inheritances possible in java? Reason
Write a program for the Fibonacci series using objects and classes
Write a program using ArrayList to print the even no from 1 to n.
New Features of Java 8?
Final keyword
Collection framework?
List the names of classes and interfaces in the collection framework
What do you understand by this code
Java
final int i = 5;final Employee ob = new Employee();
How will we design a table for students and Department such that we can access data from both the tables together?
Any Questions the interviewer asked?
Ended
Round 4: HR Round
It was basically a document verification round in which they will check your 10th mark sheet, Aadhar card, and pan card. And that’s it for the HR round.
Tips: My interviewer just asked questions in java from basic to depth. So you have to be proficient with java as he was giving me code snippet and was asked about the errors and also what will happen if he alters that. And also in-depth questions were asked from inheritance. But, many of my friend’s interview was not fully based on java, but yes oops concept was asked.
Cognizant
Marketing
On-Campus
Interview Experiences
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Amazon Interview Experience for SDE-1 (On-Campus)
Microsoft Interview Experience for Internship (Via Engage)
Amazon Interview Experience
Amazon Interview Experience for SDE-1
Amazon Interview Experience (Off-Campus) 2022
Amazon Interview Experience for SDE-1(Off-Campus)
Amazon Interview Experience for SDE-1
Amazon Interview Experience for SDE1 (8 Months Experienced) 2022
Persistent Systems Interview Experience (Martian Program)
Zoho Interview | Set 2 (On-Campus)
How to execute an external program like windows media player in Java?

Java provides a class named java.lang.Runtime, using this class you can interface with the current environment.
The getRunTime() (static) method of this class returns a Runtime object associated with the current application.
The exec() method accepts a String value representing the command to execute a process in the current environment (system) and executes it.
Therefore, to execute an external application using the Runtime class −
Get the run time object using the getRuntime() method.
Get the run time object using the getRuntime() method.
Execute the required process by passing the path of it as a String value to the exec() method.
Execute the required process by passing the path of it as a String value to the exec() method.
import java.io.IOException;
public class Trail {
   public static void main(String args[]) throws IOException {
      Runtime run = Runtime.getRuntime();
      System.out.println("Executing the external program . . . . . . . .");
      String file = "C:\\Program Files\\Windows Media Player\\wmplayer.exe";
      run.exec(file);
   }
}
System.out.println("Executing the external program . . . . . . . .
Similarly, the constructor of the ProcessBuilder class accepts a variable arguments of type string representing the command to execute a process and its arguments as parameters and constructs an object.
The start() method of this class starts/executes the process(es) in the current ProcessBuilder. Therefore, to run an external program using the ProcessBuilder class −
Instantiate the ProcessBuilder class by passing the command to execute a process and arguments for it as parameters to its constructor.
Instantiate the ProcessBuilder class by passing the command to execute a process and arguments for it as parameters to its constructor.
Execute the process by invoking the start() method on the above created object.
Execute the process by invoking the start() method on the above created object.
 Live Demo
import java.io.IOException;
public class ExternalProcess {
   public static void main(String args[]) throws IOException {
      String command = "C:\\Program Files\\Windows Media Player\\wmplayer.exe";
      String arg = "D:\\sample.mp3";
      //Building a process
      ProcessBuilder builder = new ProcessBuilder(command, arg);
      System.out.println("Executing the external program . . . . . . . .");
      //Starting the process
      builder.start();
   }
}
Executing the external program . . . . . . . .
New line separator doesn't work for group_concat function in MySQL? How to use it correctly?

To use new line separator in group_concat() function, follow the below syntax −
select group_concat(concat_ws(' ',yourColumnName1, yourColumnName2) SEPARATOR "\r\n") from yourTableName;
Let us first create a table −
mysql> create table DemoTable
   (
   Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   FirstName varchar(20),
   LastName varchar(20)
   );
Query OK, 0 rows affected (0.67 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(FirstName,LastName) values('John','Smith');
Query OK, 1 row affected (0.10 sec)

mysql> insert into DemoTable(FirstName,LastName) values('David','Miller');
Query OK, 1 row affected (0.14 sec)

mysql> insert into DemoTable(FirstName,LastName) values('John','Doe');
Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+----+-----------+----------+
| Id | FirstName | LastName |
+----+-----------+----------+
| 1  | John      | Smith    |
| 2  | David     | Miller   |
| 3  | John      | Doe      |
+----+-----------+----------+
3 rows in set (0.00 sec)
Following is the query to work with new line separator for group_concat function −
mysql> select group_concat(concat_ws(' ',FirstName, LastName) SEPARATOR "\r\n") from DemoTable;
This will produce the following output &mnus;
+-------------------------------------------------------------------+
| group_concat(concat_ws(' ',FirstName, LastName) SEPARATOR "\r\n") |
+-------------------------------------------------------------------+
| John Smith David Miller John Doe                                  |
+-------------------------------------------------------------------+
1 row in set (0.00 sec)
How to loop through all the elements of an array in C#?

Firstly, set an array and initialize it −
int[] arr = new int[] {34, 56, 12};
To loop through all the elements of an array −
for (int i = 0; i < arr.Length; i++) {
   Console.WriteLine(arr[i]);
}
Let us see the complete code −
using System;
public class Program {
   public static void Main() {
      int[] arr = new int[] {34, 56, 12};

      // Length
      Console.WriteLine("Length:" + arr.Length);

      for (int i = 0; i< arr.Length; i++) {
         Console.WriteLine(arr[i]);
      }
   }
}
Difference between List comprehension and Lambda in Python - GeeksforGeeks

10 Jul, 2020
List comprehension: List comprehension is an elegant way to define and create a list in python. We can create lists just like mathematical statements and in one line only. The syntax of list comprehension is easier to grasp. A list comprehension generally consists of these parts :
Output expression,
Input sequence,
A variable representing a member of the input sequence and
An optional predicate part.
List = [expression(i) for i in another_list if filter(i)]

Example :
lst  =  [x ** 2  for x in range (1, 11)   if  x % 2 == 1]print(lst)
Output:
[1, 9, 25, 49, 81]
In the above example,
x ** 2 is the expression.
range (1, 11) is input sequence or another list.
x is the variable.
if x % 2 == 1 is predicate part.
Lambda: In Python, anonymous function means that a function is without a name. As we already know the def keyword is used to define the normal functions and the lambda keyword is used to create anonymous functions. It has the following syntax:
Syntax:
lambda arguments : expression
Example:
lst = list(map(lambda x: x**2, range(1, 5)))print(lst)
Output:
[1, 4, 9, 16]
List Comprehension is used to create lists, Lambdas are functions that can process like other functions and thus return values or list.Example :
# list from range 0 to 10list_ = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]print(list_)   # lambda functionlambda_list = list(map(lambda x: x * 2, list_))  # Map basically iterates every element# in the list_ and returns the lambda # function resultprint(lambda_list)   # list comprehensionlist_comp = [x * 2 for x in list_]print(list_comp)
Output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
[0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
python-lambda
python-list
Difference Between
Python
python-list
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Difference Between Method Overloading and Method Overriding in Java
Difference between Internal and External fragmentation
Difference between Prim's and Kruskal's algorithm for MST
Differences and Applications of List, Tuple, Set and Dictionary in Python
Read JSON file using Python
Adding new column to existing DataFrame in Pandas
Python map() function
How to get column names in Pandas dataframe
hashlib.sha3_256() in Python - GeeksforGeeks

22 Apr, 2020
With the help of hashlib.sha3_256() method, we can convert the normal string in byte format is converted to an encrypted form. Passwords and important files can be converted into hash to protect them with the help of hashlib.sha3_256() method.
Syntax : hashlib.sha3_256()
Return : Return the hash code for the string.
Example #1 :In this example we can see that by using hashlib.sha3_256() method, we are able to encrypt the byte string or passwords to protect them by using this method.
# import hashlibimport hashlib  # Using hashlib.sha3_256() methodgfg = hashlib.sha3_256()gfg.update(b'GeeksForGeeks')  print(gfg.digest())
Output :
b’\x14\xf7h\xf7\xb2w<\xe5\x8fQ\xe9s i\xd0\x89\x1c$\xfe\xac\xdb\xdfV\xe8c|\xb9\xdf\x96\xe3\x93z'
Example #2 :
# import hashlibimport hashlib  # Using hashlib.sha3_256() methodgfg = hashlib.sha3_256()gfg.update(b'xyz@1234_GFG')  print(gfg.digest())
Output :
b”b\xea\x7f’\x8a\xd3\x93\xb1k\t5\xa5J|U\xea\xad\x03\xc8\x9eGw\xdeW\x03\xa6\xb8\x85}\xd5~\xb6′′
Python-hashlib
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Python Dictionary
Enumerate() in Python
Iterate over a list in Python
Read a file line by line in Python
Python OOPs Concepts
Python program to convert a list to string
Python | Split string into list of characters
Python program to check whether a number is Prime or not
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Format date while inserting records in MySQL

To format date while inserting records, use DATE_FORMAT() in the MySQL INSERT statement. Let us first create a table −
mysql> create table DemoTable2012
   -> (
   -> ShippingDate varchar(20)
   -> );
Query OK, 0 rows affected (0.48 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2012 values(date_format(curdate(),'%d.%m.%Y'));
Query OK, 1 row affected (0.14 sec)

mysql> insert into DemoTable2012 values(date_format(now(),'%d.%m.%Y'));
Query OK, 1 row affected (0.13 sec)

mysql> insert into DemoTable2012 values(date_format('2014-01-21','%d.%m.%Y'));
Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable2012;
This will produce the following output −
+--------------+
| ShippingDate |
+--------------+
| 21.12.2019 |
| 21.12.2019 |
| 21.01.2014 |
+--------------+
3 rows in set (0.00 sec)
Count of lines required to write the given String in C++

We are given a string Str of alphabets and an array widths[]containing width of all English alphabets. The goal is to find the number of lines required to print this string on a page which has a width of 10 characters. Also print remaining characters.
We will traverse the string check width of the current character and add it, if this sum >=10 increment number of lines.
Let’s understand with examples.
Input 
Str = "ababababab"
widths[] = {2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 3, 1, 1, 1, 2, 1, 1, 1};
Output 
Count of lines: 2 Remaining width: 6
Explanation 
line 1 : ababab ( 2+1+2+1+2+1 = 3+3+3=9)
line 2 : abab (2+1+2+1)
Input 
Str = "bbbbbbbbbbdd"
widths[] = {2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,1, 1, 1, 1, 1, 3, 1, 1, 1, 2, 1, 1, 1};
Output 
Count of lines: 2 Remaining width: 2
Explanation 
line 1 : bbbbbbbbbb (1+1+1+1+1+1+1+1+1+1=10)
line 2 : dd (1+1)
We have a string Str and array widths[] of space of each alphabet.
We have a string Str and array widths[] of space of each alphabet.
Function numberOfLines(string str,int len, int w[]) displays number of lines in page and width of characters in the last line.
Function numberOfLines(string str,int len, int w[]) displays number of lines in page and width of characters in the last line.
Take initial count of lines as numoflines=0.
Take initial count of lines as numoflines=0.
Take initial last line width as remain=0
Take initial last line width as remain=0
Traverse string str using for loop.
Traverse string str using for loop.
Take current character c as str[i].
Take current character c as str[i].
Check width of c as num=width[c-’a’].
Check width of c as num=width[c-’a’].
Add this num to remain.
Add this num to remain.
If remain >=10 increment line count and update remain as num.
If remain >=10 increment line count and update remain as num.
Print results at the end of for loop.
Print results at the end of for loop.
 Live Demo
#include <bits/stdc++.h>
using namespace std;
// Function to return the number of lines required
void numberOfLines(string str,int len, int w[]){
   int numoflines = 0;
   int remain = 0;
   //traversing string
   for (int i=0;i<len;i++){
      char c=str[i]; //current character
      int num = w[c - 'a']; //units for current character remain += num;
      if (remain >= 10){
         numoflines+=1;
         remain = num;
      }
   }
   cout<<"Count of lines: "<<numoflines;
   cout<<endl<<"Remaining width: "<<remain;
}
int main(){
   string Str = "abcdefghijklmnop";
   int length=Str.length();
   int widths[] = {2, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 2, 1, 1, 1};
   numberOfLines(Str,length,widths);
   return 0;
}
If we run the above code it will generate the following output −
Count of lines: 3
Remaining width: 1
GATE | GATE-CS-2003 | Question 58 - GeeksforGeeks

17 Dec, 2021
Consider the translation scheme shown below
S → T R
R → + T {print ('+');} R | ε
T → num {print (num.val);} 
Here num is a token that represents an integer and num.val represents the corresponding integer value. For an input string ‘9 + 5 + 2’, this translation scheme will print(A) 9 + 5 + 2(B) 9 5 + 2 +(C) 9 5 2 + +(D) + + 9 5 2Answer: (B)Explanation: Let us make the parse tree for 9+5+2 in top down manner, left first derivation.
Steps:
1) Expand S->TR
2) apply T->Num...
3) apply R -> +T...
4) appy T->Num...
5) apply R-> +T..
6) apply T-> Num..
7) apply R-> epsilon 
After printing through the print statement in the parse tree formed you will get the answer as 95+2+Quiz of this Question
sweetyty
GATE-CS-2003
GATE-GATE-CS-2003
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | GATE-IT-2004 | Question 66
GATE | GATE-CS-2016 (Set 2) | Question 48
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE CS 2010 | Question 24
GATE | GATE CS 2011 | Question 65
GATE | GATE-CS-2004 | Question 3
GATE | GATE-CS-2006 | Question 49
GATE | GATE CS 2011 | Question 7
GATE | GATE-IT-2004 | Question 71
GATE | GATE CS 2019 | Question 27
Python | Find most common element in a 2D list - GeeksforGeeks

29 Apr, 2019
Given a 2D list (may or may not be of same length), write a Python program to find the most common element in the given 2D list.
Examples:
Input : [[10, 20, 30], [20, 50, 10], [30, 50, 10]]
Output : 10

Input : [['geeks', 'wins'], ['techie', 'wins']]
Output : wins

Approach #1 : Using max() function
First Pythonic approach is to use max() method of Python. We first flatten the 2D list and then simply apply max() method to find out the maximum occurring element among all the elements.
# Python3 program to find most # common element in a 2D list  def mostCommon(lst):    flatList = [el for sublist in lst for el in sublist]    return max(flatList, key = flatList.count)              # Driver codelst = [[10, 20, 30], [20, 50, 10], [30, 50, 10]]print(mostCommon(lst))
10

There is another method to flatten the list i.e chain.from_iterable() which gives rise to an alternative approach.
# Python3 program to find most # common element in a 2D listfrom itertools import chain  def mostCommon(lst):    flatList = list(chain.from_iterable(lst))    return max(flatList, key=flatList.count)  # Driver codelst = [[10, 20, 30], [20, 50, 10], [30, 50, 10]]print(mostCommon(lst))
10

 Approach #2 : Using most_common() from collections module
most_common() is used to produce a sequence of the n most frequently encountered input values. Therefore, we simply flatten the list and find the most common element using above mentioned method.
# Python3 program to find most # common element in a 2D listfrom itertools import chainfrom collections import Counter  def mostCommon(lst):    flatList = chain.from_iterable(lst)    return Counter(flatList).most_common(1)[0][0]              # Driver codelst = [[10, 20, 30], [20, 50, 10], [30, 50, 10]]print(mostCommon(lst))
10

Python list-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Enumerate() in Python
How to Install PIP on Windows ?
Different ways to create Pandas Dataframe
Python String | replace()
Create a Pandas DataFrame from Lists
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Split string into list of characters
Python | Convert a list to dictionary
Python program to check whether a number is Prime or not
C++ program to convert time from 12 hour to 24 hour format

This is a C++ program to convert time from 12 hour to 24 hour format.
Begin
   In main(),
   If median = pm
      Check if entered hours is less than 12
         Then add 12 to hours and print the time in 24 hours format.
      Check if entered hours is equal to 12
         Then print “00” as hours and print the time in 24 hours format.
   Else If median=am
      Check if entered hours is less than 12
         Then print the time in 24 hours format.
      Check if entered hours is equal to 12
         Then print “12” as hours and print the time in 24 hours format.
   Else print wrong choice.
End
#include<iostream>
#include<string.h>
#include <iomanip>
using namespace std;
int main() {
   int hours,minutes,seconds,h1,m1,s1;
   char median[10];
   cout<<"Enter hours, minutes, seconds:";
   cin>>hours;
   cin>>minutes;
   cin>>seconds;
   cout<<"Enter median:";
   cin>>median;
   cout<<"Time in 12 hour format:"<<setfill('0') << setw(2) <<hours<<":"<<setfill('0') << setw(2)
   <<minutes<<":"<<setfill('0') << setw(2) <<seconds<<median<<endl; //setw()=sets the field width,
   //setfill()=set character as the streams fill character.
   if(strcmp(median,"pm")==0) { //compare the strings "0" is for true "1" is for false.
      if (hours<12) {
         h1=hours+12;
         m1=minutes;
         s1=seconds;
         cout<<"Time in 24 hour format:" <<h1<<":"<<setfill('0') << setw(2) <<m1<<":"<<setfill('0') << setw(2) <<s1<<median;
      } else if(hours=12) {
         h1=12;
         m1=minutes;
         s1=seconds;
         cout<<"Time in 24 hour format:"<<h1<<":"<<setfill('0') << setw(2) <<m1<<":"<<setfill('0') << setw(2) <<s1<<median;
      }
   } else if(strcmp(median,"am")==0) {
      if (hours<12) {
         h1=hours;
         m1=minutes;
         s1=seconds;
         cout<<"Time in 24 hour format:"<<setfill('0') << setw(2) <<h1<<":"<<setfill('0') << setw(2) <<m1<<":"<<setfill('0') << setw(2) <<s1<<median;
      } else if(hours=12) {
         m1=minutes;
         s1=seconds;
         cout<<"Time in 24 hour format:"<<"00"<<":"<<setfill('0') << setw(2) <<m1<<":"<<setfill('0') << setw(2) <<s1<<median;
      }
   } else {
      printf("Wrong choice");
   }
}
Enter hours, minutes, seconds:12
07
06
Enter median:pm
Time in 12 hour format:12:07:06pm
Time in 24 hour format:12:07:06pm

Enter hours, minutes, seconds:01
02
30
Enter median:pm
Time in 12 hour format:01:02:30pm
Time in 24 hour format:13:2:30pm

Enter hours, minutes, seconds:10
10
03
Enter median:am
Time in 12 hour format:10:10:03am
Time in 24 hour format:10:10:03am

Enter hours, minutes, seconds:12
02
04
Enter median:am
Time in 12 hour format:12:02:04am
Time in 24 hour format:00:02:04am
DAX Filter - RELATED function

Returns a related value from another table.
RELATED (<column>) 

column
The column that contains the values you want to retrieve.
A single value that is related to the current row.
DAX RELATED function requires that a relationship exists between the current table and the table with related information. When you specify the column that contains the data that you want, the function follows an existing relationship to fetch the value from the specified column in the related table.
When DAX RELATED function performs a lookup, it examines all values in the specified table regardless of any filters that may have been applied.
DAX RELATED function needs a row context. Hence, it can be used only in one of the following cases −
A calculated column expression, where the current row context is unambiguous.
As a nested function in an expression that uses a DAX X function, such as SUMX.
= SUMX (FILTER (Sales, RELATED (Products[Product]) <>"Soap"), Sales[Sales Amount]) 

    53 Lectures 
     5.5 hours 

 Abhay Gadiya

    24 Lectures 
     2 hours 

 Randy Minder

    26 Lectures 
     4.5 hours 

 Randy Minder
 Print
 Add Notes
 Bookmark this page
How to stop form submission using JavaScript?

Use the return value of the function to stop the execution of a form in JavaScript.
<form onsubmit = "event.preventDefault(); myValidation();">
The JavaScript function would be like the following −
function myValidation()
{
   if(check if your conditions are not satisfying)
   {
      alert("Oops! Validation failed!");
      returnToPreviousPage();
      return false;
   }
   alert("Validations successful!");
   return true;
}
False would return if the form fails to submit.
Difference between COMMIT and ROLLBACK in SQL

24 Feb, 2022
1. COMMIT-COMMIT in SQL is a transaction control language that is used to permanently save the changes done in the transaction in tables/databases. The database cannot regain its previous state after its execution of commit. 
Example: Consider the following STAFF table with records: 
STAFF
sql> 
SELECT *
FROM Staff
WHERE Allowance = 400;

sql> COMMIT; 
Output: 
So, the SELECT statement produced the output consisting of three rows. 
2. ROLLBACK
ROLLBACK in SQL is a transactional control language that is used to undo the transactions that have not been saved in the database. The command is only been used to undo changes since the last COMMIT.
Example: Consider the following STAFF table with records: 
STAFF
sql> 
SELECT *
FROM EMPLOYEES
WHERE ALLOWANCE = 400;

sql> ROLLBACK; 
Output: 
So, the SELECT statement produced the same output with the ROLLBACK command. 
Syntax of COMMIT statement are:
COMMIT;
Syntax of ROLLBACK statement are:
ROLLBACK;
hemantsachdeva
itskawal2000
Picked
SQL-Clauses
DBMS
Difference Between
GATE CS
DBMS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Types of Functional dependencies in DBMS
MySQL | Regular expressions (Regexp)
Difference between OLAP and OLTP in DBMS
OLAP Guidelines (Codd's Rule)
What is Temporary Table in SQL?
Class method vs Static method in Python
Difference between BFS and DFS
Difference between var, let and const keywords in JavaScript
Difference Between Method Overloading and Method Overriding in Java
Differences between JDK, JRE and JVM
Provider getInfo() method in Java with Examples

04 Dec, 2018
The getInfo() method of java.security.Provider class is used to return a human-readable description of the provider and its services. This may return an HTML page, with relevant links.
Syntax:
public String getInfo()
Return Value: This method returns a description of the provider and its services.
Below are the examples to illustrate the getInfo() method:
Example 1:
// Java program to demonstrate// get() method  import java.security.*;import java.util.*;  public class GFG1 {    public static void main(String[] argv) throws Exception    {          try {            // creating the object of  KeyPairGenerator            KeyPairGenerator sr = KeyPairGenerator.getInstance("DSA", "SUN");              // getting the Provider of the KeyPairGenerator sr            // by using method getProvider()            Provider provider = sr.getProvider();              // getting the info            String info = provider.getInfo();              // printing the string info            System.out.println("info : " + info);        }          catch (NoSuchAlgorithmException e) {              System.out.println("Exception thrown : " + e);        }    }}
info : 
SUN (DSA key/parameter generation;
    DSA signing; SHA-1, MD5 digests; 
    SecureRandom; X.509 certificates; 
    JKS & DKS keystores; 
    PKIX CertPathValidator; 
    PKIX CertPathBuilder; 
    LDAP, Collection CertStores, JavaPolicy Policy; 
    JavaLoginConfig Configuration)

Example 2:
// Java program to demonstrate// get() method  import java.security.*;import java.util.*;  public class GFG1 {    public static void main(String[] argv) throws Exception    {          try {            // creating the object of  SecureRandom            SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");              // getting the Provider of the SecureRandom sr            // by using method getProvider()            Provider provider = sr.getProvider();              // getting the info            String info = provider.getInfo();              // printing the string info            System.out.println("info : " + info);        }          catch (NoSuchAlgorithmException e) {              System.out.println("Exception thrown : " + e);        }    }}
info : 
SUN (DSA key/parameter generation; 
    DSA signing; SHA-1, MD5 digests; 
    SecureRandom; X.509 certificates; 
    JKS & DKS keystores; 
    PKIX CertPathValidator; 
    PKIX CertPathBuilder; 
    LDAP, Collection CertStores, JavaPolicy Policy; 
    JavaLoginConfig Configuration)

Java - util package
Java-Functions
Java-Provider
Java-security package
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Stream In Java
Introduction to Java
Constructors in Java
Exceptions in Java
Generics in Java
Functional Interfaces in Java
Java Programming Examples
Strings in Java
Differences between JDK, JRE and JVM
Abstraction in Java
Read content from one file and write it into another file

03 Jan, 2021
Prerequisite: Reading and Writing to text files in Python
Python provides inbuilt functions for creating, writing, and reading files. Two types of files can be handled in python, normal text files and binary files (written in binary language,0s, and 1s).
Text files: In this type of file, Each line of text is terminated with a special character called EOL (End of Line), which is the new line character (‘\n’) in python by default.
Binary files: In this type of file, there is no terminator for a line, and the data is stored after converting it into machine-understandable binary language.
In this article, we will learn how to read content from one file and write it into another file. Here we are operating on the .txt file in Python.
Approach:
There are two approaches to do so:
Using loops to read and copy content from one file to another.
Using file methods to read and copy content from one file to another.
Input File:
Approach:
Opening the input file in the read mode.
Opening the output file in the write mode.
Read lines from the input file and write it in the output file.
Below is the implementation of the above approach:
Python3
# Taking "gfg input file.txt" as input file# in reading modewith open("gfg input file.txt", "r") as input:          # Creating "gfg output file.txt" as output    # file in write mode    with open("gfg output file.txt", "w") as output:                  # Writing each line from input file to        # output file using loop        for line in input:            output.write(line)
Output:
Approach:
Creating/opening an output file in writing mode.
Opening the input file in reading mode
Reading each line from the input file and writing it in the output file.
Closing the output file.
Below is the implementation of the above approach:
Python3
# Creating an output file in writing modeoutput_file = open("gfg output file.txt", "w")  # Opening input file and scanning each line# from input file and writing in output filewith open("gfg input file.txt", "r") as scan:    output_file.write(scan.read())  # Closing the output fileoutput_file.close()
Output:
Python file-handling-programs
python-file-handling
Technical Scripter 2020
Python
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Iterate over a list in Python
How to iterate through Excel rows in Python?
Enumerate() in Python
Python Dictionary
Python OOPs Concepts
Different ways to create Pandas Dataframe
*args and **kwargs in Python
Python Classes and Objects
Introduction To PYTHON
Stack in Python
Difference between byte and sbyte in C#

26 May, 2020
In C#, a single byte is used to store 8-bits value. The byte and sbyte both are used for byte type of data.
byte : This Struct is used to represent 8-bit unsigned integers. The byte is an immutable value type and the range of Byte is from 0 to 255. 
Example :
C#
// C# program to demonstrate // the byte Struct Fields  using System;using System.Text;  public class GFG{          // Main Method    static void Main(string[] args)    {          // printing minimum & maximum values        Console.WriteLine("Minimum value of byte: " + byte.MinValue);        Console.WriteLine("Maximum value of byte: " + byte.MaxValue);    }}
Output:
Minimum value of byte: 0
Maximum value of byte: 255

sbyte : This Struct is used to represent 8-bit signed integers. The sbyte represents integers with values ranging from -128 to +127.
Example :
C#
// C# program to demonstrate // the sbyte Struct Fields  using System;using System.Text;  public class GFG{          // Main Method    static void Main(string[] args)    {          // printing minimum & maximum values        Console.WriteLine("Minimum value of sbyte: " + sbyte.MinValue);        Console.WriteLine("Maximum value of sbyte: " + sbyte.MaxValue);    }}
Output:
Minimum value of sbyte: -128
Maximum value of sbyte: 127

Differences between byte and sbyte in C#
Sr.No
BYTE
SBYTE
1.
2.
3.
4.
5.
 6.
 Syntax to declare the byte:
byte variable_name;

  Syntax to declare the sbyte:
sbyte variable_name;

C#
Difference Between
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C# Dictionary with examples
Introduction to .NET Framework
C# | Delegates
C# | Multiple inheritance using interfaces
Differences Between .NET Core and .NET Framework
Difference between BFS and DFS
Class method vs Static method in Python
Stack vs Heap Memory Allocation
Differences between TCP and UDP
Difference between Process and Thread
Scala List takeRight() method with example

26 Jul, 2019
The takeRight() method is utilized to select the last ‘n’ elements of the list.
Method Definition: def takeRight(n: Int): List[A]
Return Type: It returns the last ‘n’ elements of the list.
Example #1:
// Scala program of takeRight()// method  // Creating objectobject GfG{       // Main method    def main(args:Array[String])    {              // Creating a list        val m1 = List(1, 2, 3, 4, 5, 7)                  // Applying takeRight method        val result = m1.takeRight(3)                  // Displays output        println(result)              }}
List(4, 5, 7)

Example #2:
// Scala program of takeRight()// method  // Creating objectobject GfG{       // Main method    def main(args:Array[String])    {              // Creating a list        val m1 = List(1, 2, 3, 4, 5, 7)                  // Applying takeRight method        val result = m1.takeRight(7)                  // Displays output        println(result)          }}
List(1, 2, 3, 4, 5, 7)

Scala
Scala-list
Scala-Method
Scala
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Program for factorial of a number

09 Aug, 2021
Factorial of a non-negative integer, is multiplication of all integers smaller than or equal to n. For example factorial of 6 is 6*5*4*3*2*1 which is 720.
python3
# Python 3 program to find# factorial of given numberdef factorial(n):         # single line to find factorial    return 1 if (n==1 or n==0) else n * factorial(n - 1); # Driver Codenum = 5;print("Factorial of",num,"is",factorial(num)) # This code is contributed by Smitha Dinesh Semwal
Output:
Factorial of 5 is 120
python3
# Python 3 program to find # factorial of given numberdef factorial(n):    if n < 0:        return 0    elif n == 0 or n == 1:        return 1    else:        fact = 1        while(n > 1):            fact *= n            n -= 1        return fact # Driver Codenum = 5;print("Factorial of",num,"is",factorial(num)) # This code is contributed by Dharmik Thakkar
Output:
Factorial of 5 is 120
Python3
# Python 3 program to find# factorial of given number def factorial(n):     # single line to find factorial    return 1 if (n==1 or n==0) else n * factorial(n - 1)  # Driver Codenum = 5print ("Factorial of",num,"is",      factorial(num)) # This code is contributed# by Smitha Dinesh Semwal.
Output:
Factorial of 5 is 120
Please refer complete article on Program for factorial of a number for more details!
Python3
# Python 3 program to find# factorial of given numberimport math def factorial(n):    return(math.factorial(n))  # Driver Codenum = 5print("Factorial of", num, "is",      factorial(num)) # This code is contributed by Ashutosh Pandit
Output:
Factorial of 5 is 120
Dharmik Thakkar
AshutoshPandit
vaibhavsuryan
factorial
Python Programs
factorial
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Convert a list to dictionary
Python | Convert string dictionary to dictionary
Python Program for Binary Search (Recursive and Iterative)
Python program to find second largest number in a list
Iterate over characters of a string in Python
Python | Convert set into a list
Python program to interchange first and last elements in a list
Appending to list in Python dictionary
Python | Convert a list into a tuple
Add a key:value pair to dictionary in Python
PyQt5 | How to create capsule shaped push button ?

22 Apr, 2020
Capsule shape is basically shape which consist of one rectangle and two semi circle is connected to both the ends, in this tutorial we will see how to create these shaped button.
Below is normal Push button vs capsule shaped push button. 
In order to create capsule shape button we have to do the following steps :
1. Create a button.2. Resize the button to make it rectangle.3. Set the radius of button using style sheet to half of height.
Note : If the button will not be rectangle it will become circle.
Code :
# importing librariesfrom PyQt5.QtWidgets import * from PyQt5.QtGui import * from PyQt5.QtCore import * import sys    class Window(QMainWindow):    def __init__(self):        super().__init__()          # setting title        self.setWindowTitle("Python ")          # setting geometry        self.setGeometry(100, 100, 600, 400)          # calling method        self.UiComponents()          # showing all the widgets        self.show()      # method for widgets    def UiComponents(self):          # creating a push button        button = QPushButton("CLICK", self)          # setting geometry of button        # rectangular shape i.e width > height        button.setGeometry(200, 150, 150, 40)          # adding action to a button        button.clicked.connect(self.clickme)          # setting border and radius        # radius = half of height        button.setStyleSheet("border : 2px solid black;                               border-radius : 20px;")        # action method    def clickme(self):          # printing pressed        print("pressed")  # create pyqt5 appApp = QApplication(sys.argv)  # create the instance of our Windowwindow = Window()  # start the appsys.exit(App.exec())
Output :
Python-gui
Python-PyQt
Python
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()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Iterate over a list in Python
Python OOPs Concepts
Read a string after reading an integer

04 May, 2021
In this article, we will discuss how to read a string after reading an integer.
Program 1:
Below is the program that inputs a string with spaces just after taken an input of an integer: 
C++
// C++ program that inputs a string// with spaces just after taken an// input of an integer  #include <iostream>#include <string>using namespace std;  // Driver Codeint main(){    int t = 0;    cin >> t;      string s;      // Taking input with spaces    getline(cin, s);      cout << "You entered : "         << s << "\n";      return 0;}
Output:
Explanation:
In the above code, the string variable S is not able to store our input.
The reason for this is that, when entering the integer T, and pressed enter, the newline character (\n) was not stored in the integer variable T.
Instead, this newline character was stored in the upcoming string variable S.
Hence, when displaying string S, it gives output as blank spaces. This is true even if the data type preceding the string is not int. It can be any data type besides int.
As soon as enter is pressed, the newline character will get stored into the string which is inputting.
Program 2: In C++, the ignore() function accounts for nullifying the extra newline character which is generated by pressing “enter”. Below is the C++ program illustrating the use of the function ignore():
C++
// C++ program to illustrate the use// of the function ignore()  #include <iostream>#include <string>using namespace std;  // Driver Codeint main(){    int t = 0;    cin >> t;      // Adding the ignore()    cin.ignore();      string s;    getline(cin, s);      cout << "You entered : "         << s << "\n";      return 0;}
Output:
cpp-input-output
C++
C++ Programs
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Sorting a vector in C++
Polymorphism in C++
Friend class and function in C++
Pair in C++ Standard Template Library (STL)
std::string class in C++
Header files in C/C++ and its uses
Sorting a Map by value in C++ STL
Program to print ASCII Value of a character
How to return multiple values from a function in C or C++?
Shallow Copy and Deep Copy in C++
Birman Schiper Stephenson Protocol

18 Jan, 2021
This algorithm is used to maintain the causal ordering of the messages i.e. the message which is sent first should be received first. If send (M1)–>send(M2) then for all processes which receive the messages M1 and M2 should receive M1 before M2.
Features :
Broadcast based messaging.
Size of the messages are small.
More no. of messages are sent.
Limited state information.
Key Points :
Each process increases its vector clock by 1 upon sending of messages.
Message is delivered to a process if the process has received all the messages preceding to it.
Else buffer the message.
Update the vector clock for the process.
Reference :
Process: Pi
Event: eij , where i:process is number & j: jth event in ith process.
Tm:vector time stamp for message m.
Ci vector clock associated with process Pi; jth element is Ci[j] and contains Pi‘s latest value for the current time in process Pj
Protocol :Pi sending a message to Pj –
Pi increments Ci[i] and sets the timestamp tm = Ci[i] for message m.
Pj receiving a message from Pi –
When Pj, j != i, receives m with timestamp tm, it delays the message’s delivery until both as follows.Cj[i] = tm[i] - 1; and
for all k <= n and k != i, Cj[k] <= tm[k].
Cj[i] = tm[i] - 1; and
for all k <= n and k != i, Cj[k] <= tm[k].
When the message is delivered to Pj, update Pj‘s vector clock.
Check buffer to see if any can be delivered.
Example –
Initial state for all the processes are 000.
M1 is broadcasted from P3 to P1 and P2. e31 updates the vector clock to (001) and sends P1 and P2.
P2 accepts the M1 with timestamp (001) because when it compares it with its initial timestamp i.e. (000) it finds that M1 is the 1st message it is receiving.
Now we consider that before M1 could reach P1, P2 sends M2 to P1 and P3 with time stamp (011).
P1 could not accept M2 because upon comparing the timestamp of M2 with its initial timestamp a discrepancy is found because P1 has no message with timestamp (001) received earlier, so M2 is stored in buffer.
Now M1 is received by P1 and accepted.
M2 is removed from buffer and accepted by P1.
M2 is accepted by P3 as there is no discrepancy in the time stamp.
cryptography
Computer Networks
cryptography
Computer Networks
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GSM in Wireless Communication
Secure Socket Layer (SSL)
Wireless Application Protocol
Mobile Internet Protocol (or Mobile IP)
Introduction of Mobile Ad hoc Network (MANET)
Advanced Encryption Standard (AES)
Bluetooth
Intrusion Detection System (IDS)
Cryptography and its Types
Difference between FDMA, TDMA and CDMA