Validate an IP Address in C

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

8K+ Views

In this program we will see how to validate an IP address using C. The IPv4 addresses are represented in dot-decimal notation. There are four decimal numbers (all are ranging from 0 to 255). These four numbers are separated by three dots.An example of a valid IP is: 192.168.4.1To validate the IP address we should follow these stepsTokenize the string (IP address) using the dot “.” delimiterIf the sub strings are containing any non-numeric character, then return falseIf the number in each token is not in range 0 to 255, then return falseIf there are exactly three dots and four ... Read More

Read Form Data Using JSP

Arjun Thakur
Updated on 30-Jul-2019 22:30:25

3K+ Views

JSP handles requests using getParameter() method to read simple parameters and getInputStream() method to read binary data stream coming from the client.Reading Form Data using JSPJSP handles form data parsing automatically using the following methods depending on the situation −getParameter(): You call request.getParameter() method to get the value of a form parameter.getParameterValues(): Call this method if the parameter appears more than once and returns multiple values, for example, checkbox.getParameterNames(): Call this method if you want a complete list of all parameters in the current request.getInputStream(): Call this method to read binary data stream coming from the client.Read More

Enable Back Button Action in Action Bar

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

446 Views

This example demonstrates How to enable back button action in the action bar.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     In the above code, we have taken a text view.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.annotation.SuppressLint; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import android.view.View; import android.widget.TextView; public class ... Read More

MonthDay hashCode Method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

139 Views

The hash code value of the MonthDay can be obtained using the hashCode() method in the MonthDay class in Java. This method requires no parameters and it returns the hash code value of the MonthDay.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {         MonthDay md = MonthDay.parse("--02-21");       System.out.println("The MonthDay is: " + md);       System.out.println("The hash code is: " + md.hashCode());    } }outputThe MonthDay is: --02-21 The hash code is: 149Now let us understand the above program.First ... Read More

IntStream findAny Method in Java

Anvi Jain
Updated on 30-Jul-2019 22:30:25

180 Views

The findAny() method of the IntStream class in Java is used to return an OptionalInt describing some element of the stream, or an empty OptionalInt if the stream is empty.The syntax is as follows −OptionalInt findAny()Here, OptionalInt is a container object which may or may not contain an int value.Create an IntStream and add some elements −IntStream intStream = IntStream.of(20, 35, 50, 60, 80, 100);Now, return any of the element of the stream using findAny() in Java −OptionalInt res = intStream.findAny();The following is an example to implement IntStream findAny() method in Java −Example Live Demoimport java.util.*; import java.util.stream.IntStream; public class ... Read More

Update Date of Datetime Field with MySQL

Chandu yadav
Updated on 30-Jul-2019 22:30:25

13K+ Views

Update date of datetime field with the help of arithmetic operator minus(-).The syntax is as followsupdate yourTableName set yourDateTimeColumnName=yourDateTimeColumnName - interval yourValue day where date(yourDateTimeColumnName)=’yourDateValue’;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table updateDateDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> ArrivalDate datetime    -> ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into updateDateDemo(ArrivalDate) values('2011-01-13'); Query OK, 1 row affected (0.19 sec) mysql> insert into updateDateDemo(ArrivalDate) values('2013-04-21'); ... Read More

Update All Documents in MongoDB

Anvi Jain
Updated on 30-Jul-2019 22:30:25

858 Views

You can use updateMany() to update documents. Let us create a collection with a document. The query to create a collection with a document is as follows −> db.updateManyDocumentsDemo.insertOne({"StudentName":"John", "StudentLastName":"Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c948edd4cf1f7a64fa4df48") } > db.updateManyDocumentsDemo.insertOne({"StudentName":"John", "StudentLastName":"Doe"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c948ee64cf1f7a64fa4df49") } > db.updateManyDocumentsDemo.insertOne({"StudentName":"Carol", "StudentLastName":"Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c948ef14cf1f7a64fa4df4a") } > db.updateManyDocumentsDemo.insertOne({"StudentName":"David", "StudentLastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c948f044cf1f7a64fa4df4b") }Display all documents from a collection with the help of find() method. The query is as follows −> db.updateManyDocumentsDemo.find().pretty();The following is the ... Read More

Unordered Multimap Rehash Function in C++ STL

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25

128 Views

The unordered_multimap rehash(N) function in C++ STL sets the number of buckets in the container to n or more. A rehash is forced if n is greater than the current number of buckets in the container. The new bucket count can either be equal to or greater than n. The function may have no effect on the bucket count and may not force a rehash if n is lower than the current number of buckets in the container. Rehash () returns nothing and take n as a parameter which specifies the minimum number of buckets for the container hash table.AlgorithmBegin ... Read More

MongoDB Equivalent of WHERE IN

Ankith Reddy
Updated on 30-Jul-2019 22:30:25

249 Views

The MongoDB equivalent of WHERE IN(1, 2, ....) is $in operator. The syntax is as followsdb.yourCollectionName.find({yourFieldName:{$in:[yourValue1, yourValue2, ....N]}}).pretty();Let us first create a collection with documents> db.whereInDemo.insertOne({"StudentName":"John", "StudentMathScore":57}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca281ec6304881c5ce84ba5") } > db.whereInDemo.insertOne({"StudentName":"Larry", "StudentMathScore":89}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca281f56304881c5ce84ba6") } > db.whereInDemo.insertOne({"StudentName":"Chris", "StudentMathScore":98}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca281fd6304881c5ce84ba7") } > db.whereInDemo.insertOne({"StudentName":"Robert", "StudentMathScore":99}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca2820a6304881c5ce84ba8") } > db.whereInDemo.insertOne({"StudentName":"Bob", "StudentMathScore":97}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ca282206304881c5ce84ba9") }Following is the query to display all documents from a collection with ... Read More

Skip Blank and Null Values in MySQL

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

4K+ Views

To skip blank and null in MySQL, use the following syntax:select *from yourTableName where yourColumnName IS NOT NULL AND yourColumnName '';Let us first create a table:mysql> create table DemoTable (Id int, FirstName varchar(20)); Query OK, 0 rows affected (0.66 sec)Following is the query to insert records in the table using insert command:mysql> insert into DemoTable values(100, 'Larry'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(101, ''); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(102, 'Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(103, null); Query OK, 1 ... Read More

Advertisements