IntBuffer put Method in Java

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

115 Views

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.IntBuffer. 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 {          IntBuffer buffer = IntBuffer.allocate(5);     ... Read More

KeyPairGenerator getInstance Method in Java

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

199 Views

A KeyPairGenerator object with the key pairs for a particular algorithm can be obtained using the getInstance() method in the class java.security.KeyPairGenerator. This method requires a single parameter i.e. the algorithm name and it returns the KeyPairGenerator object created.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 {          KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("RSA");          String algorithm = kpGenerator.getAlgorithm();          System.out.println("The Algorithm is: " + algorithm);       } catch (NoSuchAlgorithmException ... Read More

What is a Taglib Directive in JSP

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

152 Views

The JavaServer Pages API allow you to define custom JSP tags that look like HTML or XML tags and a tag library is a set of user-defined tags that implement custom behavior.The taglib directive declares that your JSP page uses a set of custom tags, identifies the location of the library, and provides means for identifying the custom tags in your JSP page.The taglib directive follows the syntax given below −Here, the uri attribute value resolves to a location the container understands and the prefix attribute informs a container what bits of markup are custom actions.You can write the XML ... Read More

Enable Back Button in Action Bar

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

2K+ Views

This example demonstrates How to get action bar tittle 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.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.View; import android.widget.TextView; public class MainActivity extends AppCompatActivity ... Read More

MonthDay Range Method in Java

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

110 Views

The range of values for a ChronoField can be obtained using the range() method in the MonthDay class in Java. This method requires a single parameter i.e. the ChronoField for which the range of values is required and it returns the range of values.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; import java.time.temporal.ChronoField; import java.time.temporal.ValueRange; public class Main {    public static void main(String[] args) {       MonthDay md = MonthDay.parse("--02-21");       System.out.println("The MonthDay is: " + md);       ValueRange range = md.range(ChronoField.DAY_OF_MONTH);       System.out.println("The range of DAY_OF_MONTH is: ... Read More

LocalDateTime withDayOfMonth Method in Java

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

102 Views

An immutable copy of a LocalDateTime with the day of month altered as required is done using the method withDayOfMonth() in the LocalDateTime class in Java. This method requires a single parameter i.e. the day of month that is to be set in the LocalDateTime and it returns the LocalDateTime with the day of month altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt1);       LocalDateTime ... Read More

Convert MySQL NULL to 0 Using COALESCE Function

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

728 Views

You can use the COALESCE() function to convert MySQL null to 0SELECT COALESCE(yourColumnName, 0) AS anyAliasName FROM yourTableName;Let us first create a table. The query to create a table is as followsmysql> create table convertNullToZeroDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20),    -> Salary int    -> ); Query OK, 0 rows affected (1.28 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into convertNullToZeroDemo(Name, Salary) values('John', NULL); Query OK, 1 row affected (0.20 sec) mysql> insert into convertNullToZeroDemo(Name, Salary) values('Carol', 5610); Query OK, 1 ... Read More

Implement MongoDB OR Query

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

168 Views

The syntax is as follows for the $or query in MongoDB −db.yourCollectionName.find({ $or : [ { "yourFieldName" : "yourValue1" }, {"yourFieldName":"yourValue2"}, ...........N ] } ).pretty();To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.orDemo.insertOne({"UserName":"Larry", "UserAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9491fd4cf1f7a64fa4df4c") } > db.orDemo.insertOne({"UserName":"David", "UserAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9492074cf1f7a64fa4df4d") } > db.orDemo.insertOne({"UserName":"Mike", "UserAge":25}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c94920e4cf1f7a64fa4df4e") } > db.orDemo.insertOne({"UserName":"Sam", "UserAge":20}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9492144cf1f7a64fa4df4f") } ... Read More

Unordered Multimap Size Function in C++ STL

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

106 Views

unordered_multimap size() function in C++ STL returns the number of elements in the unordered map.AlgorithmBegin    Declare an empty map container m.    Performing reserve function to restrict the most appropriate    bucket_count of the map container.    Insert values in the map container.    Print the size of the unorderd multimap container by using the size() function. EndExample Code Live Demo#include #include using namespace std; int main() {    unordered_map m; // declaring m as empty map container    m.reserve(6); //restricting the most appropriate bucket_count of map container    m.insert (pair('b', 10)); // inserting some values    m.insert (pair('a', 20));    cout

Random Number Generation in C++

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

301 Views

Let us see how to generate random numbers using C++. Here we are generating a random number in range 0 to some value. (In this program the max value is 100).To perform this operation we are using the srand() function. This is in the C library. The function void srand(unsigned int seed) seeds the random number generator used by the function rand.The declaration of srand() is like below:void srand(unsigned int seed)It takes a parameter called seed. This is an integer value to be used as seed by the pseudo-random number generator algorithm. This function returns nothing.To get the number we ... Read More

Advertisements