Create Octet Tuple from an Array in Java

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

132 Views

To create Octet Tuple from an array in Java, use the fromArray() method. Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package:import org.javatuples.Octet;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples:Steps: How to run JavaTuples program in EclipseThe following is an example to create Octet Tuple ... Read More

Check If Field Is a Number in MongoDB

George John
Updated on 30-Jul-2019 22:30:25

542 Views

To check if field is a number in MongoDB, use the $type operator. Following is the syntaxdb.yourCollectionName.find({youtFieldName: {$type:"number"}}).pretty();Let us first create a collection with documents> db.checkIfFieldIsNumberDemo.insertOne({"StudentName":"John", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9ec75dd628fa4220163b83") } >db.checkIfFieldIsNumberDemo.insertOne({"StudentName":"Chris", "StudentMathScore":98, "StudentCountryName":"US"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9ec77cd628fa4220163b84") } >db.checkIfFieldIsNumberDemo.insertOne({"StudentName":"Robert", "StudentCountryName":"AUS"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9ec7a4d628fa4220163b85") } >db.checkIfFieldIsNumberDemo.insertOne({"StudentId":101, "StudentName":"Larry", "StudentCountryName":"AUS"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9ec7ccd628fa4220163b86") }Following is the query to display all documents from a collection with the help of find() method> db.checkIfFieldIsNumberDemo.find().pretty();This will produce the following output{    "_id" : ... Read More

Count Values That Appear Only Once in a MySQL Column

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

674 Views

To get number of values that only appear once in a column, use GROUP BY HAVING. Let us first create a table:mysql> create table DemoTable (    Name varchar(20) ); Query OK, 0 rows affected (0.55 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable values('Larry'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('Larry'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('Sam'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into ... Read More

CharBuffer get Method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

139 Views

The value at the current position of the buffer is read and then incremented using the method get() in the class java.nio.CharBuffer. This method returns the value that is at the current buffer position. Also, the BufferUnderflowException is thrown if underflow situation occurs.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          CharBuffer buffer = CharBuffer.allocate(n);          buffer.put('A');          buffer.put('P');       ... Read More

Group By Dates in MongoDB

Nancy Den
Updated on 30-Jul-2019 22:30:25

588 Views

You can use aggregate framework to group by dates in MongoDB. Let us first create a collection with some documents. The query to create a collection with documents are as follows:> db.groupByDateDemo.insertOne({"UserLoginDateTime":new ISODate()}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6ee4df6fd07954a4890695") } > db.groupByDateDemo.insertOne({"UserLoginDateTime":new ISODate("2019-01-31 15:20:09.234Z")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6ee51c6fd07954a4890696") } > db.groupByDateDemo.insertOne({"UserLoginDateTime":new ISODate("2017-04-21 16:12:13.240Z")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6ee5336fd07954a4890697") } > db.groupByDateDemo.insertOne({"UserLoginDateTime":new ISODate("2016-05-25 19:11:21.130Z")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6ee54b6fd07954a4890698") } > db.groupByDateDemo.insertOne({"UserLoginDateTime":new ISODate("2016-05-25 19:11:21.130Z")}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6ee8de6fd07954a4890699") } > ... Read More

Enable Back Button in Android WebView

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

4K+ Views

This example demonstrate about How to enable back button in android webview.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 web view to show facebook.com.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.app.ProgressDialog; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.webkit.CookieManager; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.EditText; public class MainActivity extends AppCompatActivity ... Read More

Set Time in a Table Using JDBC

Nancy Den
Updated on 30-Jul-2019 22:30:25

323 Views

You can insert time values in SQL using the time datatype, The java.sql.Time class maps to the SQL Time type.The PreparedStatement interface provides a method named setTime(). Using this you can insert time into a table. This method accepts two parameters −An integer representing the parameter index of the place holder (?) to which we need to set date value.A Time object representing the time value to be passed. The constructor of java.sql.Time class accepts a variable of long type representing the number of milliseconds from the epoch (standard base time I.e. January 1, 1970, 00:00:00 GMT).ExampleAssume we have created ... Read More

Print ID of Record in Android SQLite

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

442 Views

Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How to print id of record in Android sqlite.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details ... Read More

Period plusYears Method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25

155 Views

An immutable copy of the Period object where some years are added to it can be obtained using the plusYears() method in the Period class in Java. This method requires a single parameter i.e. the number of years to be added and it returns the Period object with the added years.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p1 = Period.parse(period);       System.out.println("The Period is: " + p1);       Period p2 ... Read More

Get Day of Year using LocalDateTime in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

109 Views

The day of the year for a particular LocalDateTime can be obtained using the getDayOfYear() method in the LocalDateTime class in Java. This method requires no parameters and it returns the day of the year which can be in the range of 1 to 365 and also 366 for leap years.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T11:30:15");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The day of the year is: " + ... Read More

Advertisements