The LinkedBlockingQueue Class in Java has a blocking queue that is optionally bounded and based on linked nodes. This means that if the capacity is provided then the LinkedBlockingQueue is bound, otherwise it is not bound. Also, FIFO for ordering elements.A program that demonstrates this is given as follows −Example Live Demoimport java.util.concurrent.LinkedBlockingQueue; public class Demo { public static void main(String[] args) { LinkedBlockingQueue lbQueue = new LinkedBlockingQueue(); lbQueue.add("Amy"); lbQueue.add("John"); lbQueue.add("May"); lbQueue.add("Harry"); lbQueue.add("Anne"); System.out.println("The elements in LinkedBlockingQueue are: " ... Read More
The buffer can be compacted using the compact() method in the class java.nio.CharBuffer. This method does not require a parameter and it returns the new compacted CharBuffer 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 { CharBuffer buffer = CharBuffer.allocate(n); buffer.put('A'); buffer.put('B'); ... 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 sort string number 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
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 sqlite_source_id () in Android sqliteStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to ... Read More
JSP gives you an option to specify Error Page for each JSP using page attribute. Whenever the page throws an exception, the JSP container automatically invokes the error page.Following is an example to specifiy an error page for a main.jsp. To set up an error page, use the directive. Error Handling Example We will now write one Error Handling JSP ShowError.jsp, which is given below. Notice that the error-handling page includes the directive . This directive causes ... Read More
The tag maps key to the localized message and performs the parametric replacement.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultkeyMessage key to retrieveNoBodybundleResource bundle to useNoDefault bundlevarName of the variable to store the localized messageNoPrint to pagescopeThe scope of the variable to store the localized messageNoPageExample JSTL fmt:message Tag You will receive the following result −One Two Three
Let us first create a table in a database. The query to create a table is as followsmysql> create table customerDetails -> ( -> CustomerId int, -> CustomerName varchar(30) -> ); Query OK, 0 rows affected (0.56 sec)Now display all tables from the database in order to check the customerDetails table is present or not.The query is as followsmysql> show tables;The following is the output+------------------------------+ | Tables_in_test3 | +------------------------------+ | bestdateformatdemo | | customerdetails | | deletedemo ... Read More
First check all the user and host from MySQL.user table with the help of select statement as shown belowmysql> select user, host from MySQL.user;The following is the output+------------------+-----------+ | user | host | +------------------+-----------+ | Bob | % | | Manish | % | | User2 | % | | mysql.infoschema | % | | mysql.session | % ... Read More
To retrieve the first document in a collection, you can use findOne(). Following is the syntaxvar anyVariableName=db.yourCollectionName.findOne(); //To print result at MongoDB console write the variable name yourVariableNameLet us first create a collection with documents> db.retrieveFirstDocumentDemo.insertOne({"ClientName":"Robert", "ClientAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5ca2325966324ffac2a7dc6d") } > db.retrieveFirstDocumentDemo.insertOne({"ClientName":"Chris", "ClientAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5ca2326266324ffac2a7dc6e") } > db.retrieveFirstDocumentDemo.insertOne({"ClientName":"Larry", "ClientAge":29}); { "acknowledged" : true, "insertedId" : ObjectId("5ca2326a66324ffac2a7dc6f") } > db.retrieveFirstDocumentDemo.insertOne({"ClientName":"David", "ClientAge":39}); { "acknowledged" : true, "insertedId" : ObjectId("5ca2327566324ffac2a7dc70") }Following is the query to display all documents from a collection with the help of ... Read More
Let’s say the following is our Collection i.e. ArrayList −Listlist = new ArrayList(); list.add(100); list.add(200); list.add(200); list.add(200); list.add(300); list.add(400); list.add(400); list.add(500);Now, create another Collection −List list2 = new ArrayList(); list2.add(100); list2.add(200); list2.add(300); list2.add(400);To remove all elements from a Collection in another Collection, try the following with list and list2 as our two Collections −list.removeAll(list2);Example Live Demoimport java.util.ArrayList; import java.util.List; public class Demo { public static void main(String args[]) throws Exception { Listlist = new ArrayList(); list.add(100); list.add(200); list.add(200); list.add(200); list.add(300); ... Read More