CharBuffer Allocate Method in Java

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

145 Views

A new CharBuffer can be allocated using the method allocate() in the class java.nio.CharBuffer. This method requires a single parameter i.e. the capacity of the buffer. It returns the new CharBuffer that is allocated. If the capacity provided is negative, then the IllegalArgumentException 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 {          CharBuffer buffer = CharBuffer.allocate(n);          buffer.put('A');          buffer.put('P');   ... Read More

Add String and Other Data Types for ListView in Android

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

715 Views

This example demonstrates How to add string and other data types for Listview 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 name and record number as Edit text, when user click on save button it will store the data into arraylist. Click on refresh ... Read More

Handle Error Object in JSP Using JSTL Tags

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

595 Views

You can make use of JSTL tags to write an error page ShowError.jsp with better structure and more information −           Show Error Page               Opps...                             Error:             ${pageContext.exception}                                 URI:             ${pageContext.errorData.requestURI}                             ... Read More

Set Data Source in a JSP

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

587 Views

The tag sets the data source configuration variable or saves the data-source information in a scoped variable that can be used as input to the other JSTL database actions.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultdriverName of the JDBC driver class to be registeredNoNoneurlJDBC URL for the database connectionNoNoneuserDatabase usernameNoNonepasswordDatabase passwordNoNonepasswordDatabase passwordNoNonedataSourceDatabase prepared in advanceNoNonevarName of the variable to represent the databaseNoSet defaultscopeScope of the variable to represent the databaseNoPageExampleConsider the following information about your MySQL database setup −We are using JDBC MySQL driver.We are going to connect to TEST database on local machine.We would use user_id and my ... Read More

DoubleStream Parallel Method in Java

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

132 Views

The parallel() method of the DoubleStream class returns an equivalent stream which is parallel.The syntax is as followsDoubleStream parallel()To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream parallel() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) { DoubleStream doubleStream = DoubleStream.of(35.8, 14.9, 23.3, 67.8, 89.4, 45.6); System.out.println("Parallel DoubleStream = "); doubleStream.parallel().forEach(System.out::println); } }OutputParallel DoubleStream = 67.8 14.9 23.3 89.4 45.6 35.8

Period.from() Method in Java

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

116 Views

An instance of a Period object can be obtained from a Temporal object using the from() method in the Period class in Java. This method requires a single parameter i.e. the TemporalAmount and it returns the Period object that is obtained.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       int days = 20;       int months = 11;       int years = 3;       Period p = Period.from(Period.of(years, months, days));       System.out.println("The Period is: " + ... Read More

Avoid Null Result of SELECT MAX Rank from Empty Table

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

3K+ Views

You can use COALESCE() along with aggregate function MAX() for this.The syntax is as followsSELECT COALESCE(MAX(`yourColumnName`), 0) FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table avoidNullDemo    -> (    -> `rank` int    -> ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into avoidNullDemo values(10); Query OK, 1 row affected (0.20 sec) mysql> insert into avoidNullDemo values(NULL); Query OK, 1 row affected (0.18 sec) mysql> insert into avoidNullDemo values(20); Query OK, 1 ... Read More

Query MySQL on the Current Week

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

2K+ Views

To query MySQL on the current week, you can use YEARWEEK() function.The syntax is as followsSELECT *FROM yourTableName WHERE YEARWEEK(yourDateColumnName) = YEARWEEK(NOW());To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table currentWeekDemo -> ( -> UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> UserName varchar(20), -> UserPostDate date -> ); Query OK, 0 rows affected (0.68 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into currentWeekDemo(UserName, ... Read More

The clear Method of CopyOnWriteArrayList in Java

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

98 Views

To remove all the elements from the CopyOnWriteArrayList, use the clear() method. It empties the list.The syntax is as follows:void clear()To work with CopyOnWriteArrayList class, you need to import the following package:import java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class clear() method in Java:Example Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList arrList = new CopyOnWriteArrayList();       arrList.add(220);       arrList.add(250);       arrList.add(400);       arrList.add(500);       arrList.add(650);       arrList.add(700);       arrList.add(800);       System.out.println("CopyOnWriteArrayList String Representation ... Read More

Print a Variable at the MongoDB Command Prompt

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

2K+ Views

In order to print a variable at the MongoDB command prompt, use the following syntax//Declaring and Initializing a variable. var anyVariableName=yourValue; //To print the above variable. yourVariableName; Or print(yourVariableName);Following is how you can declare and initialize a variable at the MongoDB command prompt> var myIntegerValue=20;Print a variable at the MongoDB command prompt:> myIntegerValueThis will produce the following output20You can also use print(). Following is the query> print(myIntegerValue);This will produce the following output20Let us see another example. Following is the query to declare and initialize a string variable at MongoDB shell.> var myStringValue="Hello MongoDB!!!";Following is the query to print a variable ... Read More

Advertisements