IntBuffer Compact Method in Java

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

174 Views

The buffer can be compacted using the compact() method in the class java.nio.IntBuffer. This method does not require a parameter and it returns the new compacted IntBuffer with the same content as the original buffer. If the buffer is read-only, then the ReadOnlyBufferException is thrown.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(n);          buffer.put(3);          buffer.put(7);   ... Read More

SecureRandom setSeed Method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

484 Views

The random object can be reseeded using the setSeed() method in the class java.security.SecureRandom. This method requires a single parameter i.e. the required seed byte array and it returns the reseeded random object.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 {          SecureRandom sRandom = SecureRandom.getInstance("SHA1PRNG");          String str = "Apple";          byte[] arrB = str.getBytes();          sRandom.setSeed(arrB);          byte[] arrSeed = sRandom.getSeed(5);   ... Read More

Print Numbers from 1 to 100 Without Using Loop

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

792 Views

Here we will see how to write a C program that can print numbers from 1 to 100 without using any kind of loops.This problem can be solved using the recursion. We will create a function that will be called recursively. As we know that a recursive function has basically two sections. The base case and the recursive call and other operation. In this function the base case is the argument n is greater than 1. Until it reaches 1, the function will be called recursively. Now at the end it will print the value of n. Thus the entire ... Read More

Order By Inside of Group By in MySQL: Is It Possible?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

845 Views

Instead of using ORDER BY inside GROUP BY, you can use the MAX() aggregate function.The syntax is as follows −SELECT yourNameColumnName, MAX(yourRankColumnName) FROM yourTableName GROUP BY yourNameColumnName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table MaxDemo    -> (    -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserName varchar(20),    -> UserRank int    -> ); Query OK, 0 rows affected (0.77 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into MaxDemo(UserName, UserRank) values('Larry', 2); Query ... Read More

What is Info Attribute in JSP

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

377 Views

The info attribute lets you provide a description of the JSP. The following is a coding example −

Add Action Icon in Android

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

488 Views

This example demonstrates how to add an action icon 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 action bar icon status.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; ... Read More

LocalTime equals Method in Java

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

500 Views

The equality of two LocalTime objects can be determined using the equals() method in the LocalTime class in Java. This method requires a single parameter i.e. the LocalTime object to be compared. Also it returns true if both the LocalTime objects are equal and false otherwise.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalTime lt1 = LocalTime.parse("23:15:30");       LocalTime lt2 = LocalTime.parse("23:15:30");       System.out.println("The LocalTime lt1 is: " + lt1);       System.out.println("The LocalTime lt2 is: " + ... Read More

Equals Method of AbstractSequentialList in Java

Smita Kapse
Updated on 30-Jul-2019 22:30:25

140 Views

The equals() method is inherited from the AbstractList class in Java. It is used to check the object for equality with this list. It returns TRUE if the object is equal to this list, else FALSE is returned.The syntax is as follows −public boolean equals(Object o)Here, o is the object to be compared for equality with this list.To work with the AbstractSequentialList class in Java, you need to import the following packageimport java.util.AbstractSequentialList;The following is an example to implement AbstractSequentialList equals() method in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo {    public static void main(String[] args) { ... Read More

Compare Only Day and Month with Date Field in MySQL

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

3K+ Views

You can compare only day and month with date field in MySQL with the help of DATE_FORMAT().The syntax is as followsselect *from yourTableName WHERE DATE_FORMAT(yourColumnName, '%m-%d') = DATE_FORMAT('yourValue', '%m-%d') and yourCondition;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table compareDayAndMonthDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> compareDayAndTime date    -> ); Query OK, 0 rows affected (0.49 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into compareDayAndMonthDemo(compareDayAndTime) values('2014-01-31'); Query OK, 1 row affected (0.20 ... Read More

MongoDB Query by Sub-Field

Smita Kapse
Updated on 30-Jul-2019 22:30:25

2K+ Views

You can use dot(.) notation to query by subfield. Let us create a collection with a document. The query to create a collection with a document is as follows −> db.queryBySubFieldDemo.insertOne(    ... {       ... "StudentPersonalDetails" : {"StudentName" : "John", "StudentHobby" :"Photography"},       ... "StudentScores" : {"MathScore" : 56}    ... } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5c92c2995259fcd195499808") } > db.queryBySubFieldDemo.insertOne(    ... {       ... "StudentPersonalDetails" : {"StudentName" : "Chris", "StudentHobby" :"Reading"},       ... "StudentScores" : {"MathScore" : 97}    ... } ... ); { ... Read More

Advertisements