The required value can be written at the current position of the buffer and then the current position is incremented using the method put() in the class java.nio.FloatBuffer. This method requires a single parameter i.e. the value to be written in the buffer and it returns the buffer in which the value is inserted.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 { FloatBuffer buffer = FloatBuffer.allocate(n); ... Read More
The algorithm name for the parameter generator can be obtained using the method getAlgorithm() in the class java.security.AlgorithmParameterGenerator. This method requires no parameters and it returns the algorithm name in string form.A program that demonstrates this is given as follows −Example Live Demoimport java.security.*; import java.util.*; public class Demo { public static void main(String[] argv) { try { AlgorithmParameterGenerator apGenerator = AlgorithmParameterGenerator.getInstance("DiffieHellman"); apGenerator.init(1024); String algorithm = apGenerator.getAlgorithm(); System.out.println("The Algorithm is: " + algorithm); } catch (NoSuchAlgorithmException e) { ... Read More
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 use ORDER BY in Android sqlite.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to ... Read More
Your web application may define several different filters with a specific purpose. Consider, you define two filters AuthenFilter and LogFilter. Rest of the process will remain as explained above except you need to create a different mapping as mentioned below − LogFilter LogFilter test-param Initialization Paramter AuthenFilter AuthenFilter test-param Initialization Paramter LogFilter /* AuthenFilter /* Filters Application OrderThe order of filter-mapping elements ... Read More
This example demonstrates How to get current status bar elevation in android.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 text view to show status bar elevation.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; 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.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity ... Read More
The MonthDay can be formatted with the specified formatter using the format() method in the MonthDay class in Java. This method requires a single parameter i.e. the MonthDay object to be formatted and it returns the formatted MonthDay with the specified formatter.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; import java.time.temporal.*; import java.time.format.DateTimeFormatter; public class Demo { public static void main(String[] args) { MonthDay md = MonthDay.parse("--02-22"); LocalDate ld = md.atYear(2019); System.out.println("The MonthDay is: " + md); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("YYYY-MM-dd"); ... Read More
An immutable copy of a duration where some days are removed from it can be obtained using the minusDays() method in the Duration class in Java. This method requires a single parameter i.e. the number of days to be subtracted and it returns the duration with the subtracted days.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofDays(5); System.out.println("The duration is: " + d); System.out.println("A copy with 2 days removed from the duration is: ... Read More
To identify the last document from MongoDB find() result set, you can use sort() in descending order. The syntax is as follows −db.yourCollectionName.find().sort( { _id : -1 } ).limit(1).pretty();To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.identifyLastDocuementDemo.insertOne({"UserName":"Larry", "UserAge":24, "UserCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5c94a2ff4cf1f7a64fa4df57") } > db.identifyLastDocuementDemo.insertOne({"UserName":"Chris", "UserAge":21, "UserCountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5c94a3094cf1f7a64fa4df58") } > db.identifyLastDocuementDemo.insertOne({"UserName":"David", "UserAge":25, "UserCountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5c94a3174cf1f7a64fa4df59") } > db.identifyLastDocuementDemo.insertOne({"UserName":"Sam", "UserAge":26, "UserCountryName":"US"}); { ... Read More
The effective result of i++ and ++i are same. The only difference is that the i++ increases the value of i after assigning it, and for ++i, it increases the value first, then assigns its value. We can see the difference in the following code.Example Code#include using namespace std; int main() { int x = 3, y, z; y = x++; z = ++x; cout
Use the CURRENT_TIMESTAMP instead of current_date() in MySQL for timestamp default current_date. Let us first create a table. Following is the query −mysql> create table defaultCurrent_DateDemo -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20), -> StudentAdmissionDate timestamp default CURRENT_TIMESTAMP -> ); 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 defaultCurrent_DateDemo(StudentName) values('Larry'); Query OK, 1 row affected (0.52 sec) mysql> insert into defaultCurrent_DateDemo(StudentName, StudentAdmissionDate) values('Chris', '2019-01-31'); Query OK, 1 row affected (0.18 sec)Following is the ... Read More