Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles on Trending Technologies
Technical articles with clear explanations and examples
Take Matrix input from user in Python
In this tutorial, we are going to learn how to take matric input in Python from the user. We can take input from the user in two different ways. Let's see two of them.Method 1Taking all numbers of the matric one by one from the user. See the code below.Example# initializing an empty matrix matrix = [] # taking 2x2 matrix from the user for i in range(2): # empty row row = [] for j in range(2): # asking the user to input the number # converts the input to ...
Read MoreStructuring Python Programs
In this tutorial, we are going to see some best practices for structuring the Python programs. Let's see one by oneUse a tab for indentationUsing a tab for indentation in the code make code more readable instead of using random spaces for multiple functions and methods. You can set the number of spaces for a tab in any code editors' settings.Example# example def sample(random): # statement 1 # statement 2 # ... return randomDon't write more than 79 characters in a lineWriting more than 79 characters in a line is not recommended Python. Avoid this by breaking line into multiple ...
Read MoreHow to write a conditional expression in lambda expression in Java?
The conditional operator is used to make conditional expressions in Java. It is also called a Ternary operator because it has three operands such as boolean condition, first expression, and second expression.We can also write a conditional expression in lambda expression in the below program.Exampleinterface Algebra { int substraction(int a, int b); } public class ConditionalExpressionLambdaTest { public static void main(String args[]) { System.out.println("The value is: " + getAlgebra(false).substraction(20, 40)); System.out.println("The value is: " + getAlgebra(true).substraction(40, 10)); } static Algebra getAlgebra(boolean reverse) { Algebra alg = reverse ...
Read MoreHow to use a return statement in lambda expression in Java?
A return statement is not an expression in a lambda expression. We must enclose statements in braces ({}). However, we do not have to enclose a void method invocation in braces. The return type of a method in which lambda expression used in a return statement must be a functional interface.Example 1public class LambdaReturnTest1 { interface Addition { int add(int a, int b); } public static Addition getAddition() { return (a, b) -> a + b; // lambda expression return statement } public static void main(String args[]) { System.out.println("The ...
Read MoreHow to initialize an array using lambda expression in Java?
An array is a fixed size element of the same type. The lambda expressions can also be used to initialize arrays in Java. But generic array initializes cannot be used.Example-1interface Algebra { int operate(int a, int b); } public class LambdaWithArray1 { public static void main(String[] args) { // Initialization of an array in Lambda Expression Algebra alg[] = new Algebra[] { (a, b) -> a+b, ...
Read MoreHow to implement an action listener using method reference in Java?
In Java 8, lambda expression accepts an anonymous function as a parameter. In the case of providing an anonymous method, we can also pass references of existing methods using "::" symbol. A method reference enables us to do the same thing but with existing methods.We can also implement an action listener for a JButton by using static method reference and referred using the class name.Syntax:: Method-name;Exampleimport java.awt.*; import java.awt.event.*; import javax.swing.*; public class MethodReferenceButtonListenerTest extends JFrame { private JButton button; public MethodReferenceButtonListenerTest() { setTitle("Method Reference Button Listener"); button = new JButton("Method Reference"); ...
Read MoreSQL using Python
In this tutorial, we are going to learn how to use SQL with Python using SQLite database. has a built-in module to connect with SQLite database. We are going to use sqlite3 module to connect Python and SQLite.We have to follow the below steps to connect the SQLite database with Python. Have a look at the steps and write the program.Import the sqlite3 module.Create a connection using the sqlite3.connect(db_name) the method that takes a database name is an argument. It creates one file if doesn't exist with the given name else it opens the file with the given name.Get the ...
Read MoreSend SMS updates to mobile phone using python
In this tutorial, we are going to learn how to send SMS in Python. We will be using Twilio for sending SMS.First of all, go the Twilio and create an account. You will get free trial account. And finish settings.We have to install a module called twilio to work with Twilio client. Install it with the following command.pip install twilioNow, go to the Twilio Documentation on how to send SMS using Twilio client. Or follow the steps to send the SMS.Import the twilio Client from twilio.rest.Get and store the account_sid and auth_token from the your Twilio account.Make instance of the ...
Read MoreHow to implement an instance method of an arbitrary object using method reference in Java?
A method reference is a new feature in Java 8, which is related to Lambda Expression. It can allow us to reference constructors or methods without executing them. The method references and lambda expressions are similar in that they both require a target type that consists of a compatible functional interface.SyntaxClass :: instanceMethodNameExampleimport java.util.*; import java.util.function.*; public class ArbitraryObjectMethodRefTest { public static void main(String[] args) { List persons = new ArrayList(); persons.add(new Person("Raja", 30)); persons.add(new Person("Jai", 25)); persons.add(new Person("Adithya", 20)); persons.add(new Person("Surya", 35)); persons.add(new ...
Read MoreHow can we iterate the elements of List and Map using lambda expression in Java?
The lambda expressions are inline code that implements a functional interface without creating an anonymous class. In Java 8, forEach statement can be used along with lambda expression that reduces the looping through a Map to a single statement and also iterates over the elements of a list. The forEach() method defined in an Iterable interface and accepts lambda expression as a parameter.Example ( List using Lambda Expression)import java.util.*; public class ListIterateLambdaTest { public static void main(String[] argv) { List countryNames = new ArrayList(); countryNames.add("India"); countryNames.add("England"); countryNames.add("Australia"); ...
Read More