IntBuffer Slice Method in Java

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

188 Views

A new IntBuffer with the content as a shared subsequence of the original IntBuffer can be created using the method slice() in the class java.nio.IntBuffer. This method returns the new IntBuffer that is read-only if the original buffer is read-only and direct if the original buffer is direct.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 buffer1 = IntBuffer.allocate(n);          buffer1.put(3);       ... Read More

KeyPairGenerator generateKeyPair Method in Java

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

161 Views

A key pair can be generated using the genKeyPair() method in the class java.security.KeyPairGenerator. This method requires no parameters and it returns the key pair that is generated.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) throws Exception {       try {          KeyPairGenerator kpGenerator = KeyPairGenerator.getInstance("RSA");          KeyPair keyPair = kpGenerator.genKeyPair();          System.out.println(keyPair);       } catch (NoSuchAlgorithmException e) { System.out.println("Error!!! NoSuchAlgorithmException"); ... Read More

Print List Values in Random Order in Android

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

496 Views

This example demonstrates How to print list values in random order 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 ... Read More

Running Example of Include Directive in JSP

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

140 Views

The include directive is used to include a file during the translation phase. This directive tells the container to merge the content of other external files with the current JSP during the translation phase. You may code include directives anywhere in your JSP page.The general usage form of this directive is as follows −The filename in the include directive is actually a relative URL. If you just specify a filename with no associated path, the JSP compiler assumes that the file is in the same directory as your JSP.You can write the XML equivalent of the above syntax as follows ... Read More

Handle Exceptions While Working with JDBC Applications

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

250 Views

Whenever a JDBC application encounters an issue while executing SQL statements an SQLException is thrown.This class provides information on the errors that occur while interacting with the database.Following are the main methods of the SQLException class:Sr.NoMethod & Description1int getErrorCode()This method returns the exception code for the Exception occurred.2SQLException setNextException(SQLException ex)Using this method you can create a chain of exceptions by adding a new exception to the current exception.3String getSQLState()This method returns the SQLState of the current exception.4Iterator iterator()This method returns an iterator to iterate through the chain of SQLExceptions.5void getNextException(SQLException ex)This method is used to retrieve next SQLException in this ... Read More

The addAll Method of AbstractList Class in Java

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

165 Views

The addAll() method of the AbstractList class is used to insert all of the elements in the specified collection into this list at the specified position.The syntax is as followsboolean addAll(int index, Collection

The containsAll Method of Java AbstractCollection Class

Anvi Jain
Updated on 30-Jul-2019 22:30:25

347 Views

The containsAll() method checks for all the elements in the specified collection. It returns TRUE if this collection has all the elements. The methods check for each element one by one to see if it's contained in this collection.The syntax is as follows −public boolean containsAll(Collection c)To work with AbstractCollection class in Java, import the following package −import java.util.AbstractCollection;The following is an example to implement AbstractCollection containsAll() method in Java −Example Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection1 = new ArrayList();       absCollection1.add("These");   ... Read More

Delete Everything in a MongoDB Database

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

592 Views

You can delete everything in a MongoDB database using dropDatabase() function. The syntax is as follows −use yourDatabaseName; db.dropDatabase();The above syntax will delete everything in a MongoDB database.To delete everything in a MongoDB database, let us first display all the databases from MongoDB. The query is as follows −> show dbsThe following is the output −use yourDatabaseName; admin 0.000GB config 0.000GB flighInformation 0.000GB local 0.000GB sample 0.000GB sampleDemo 0.000GB test 0.003GBNow we will delete everything from the database ‘flightInformation’.First, you need to switch the database to ‘flightInformation’. The query is as follows −> use flighInformation; switched to db flighInformationNow here ... Read More

Casting in a MongoDB Query

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

352 Views

Yes, it is possible to cast in a MongoDB query −db.yourCollectionName.find("this.yourFieldName >yourValue);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.castingDemo.insertOne({"Amount":"200"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c947e874cf1f7a64fa4df42") } > db.castingDemo.insertOne({"Amount":"100"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c947e8e4cf1f7a64fa4df43") } > db.castingDemo.insertOne({"Amount":"110"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c947e944cf1f7a64fa4df44") } > db.castingDemo.insertOne({"Amount":"95"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c947e9d4cf1f7a64fa4df45") } > db.castingDemo.insertOne({"Amount":"85"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c947ea44cf1f7a64fa4df46") } > db.castingDemo.insertOne({"Amount":"75"}); {    "acknowledged" ... Read More

Function Decorators in Python

Nitya Raut
Updated on 30-Jul-2019 22:30:25

836 Views

Python developers can extend and modify the behavior of a callable functions, methods or classes without permanently modifying the callable itself by using decorators. In short we can say they are callable objects which are used to modify functions or classes.Function decorators are functions which accepts function references as arguments and adds a wrapper around them and returns the function with the wrapper as a new function.Let’s understand function decorator bye an example:Code1@decorator def func(arg):    return "value"Above code is same as:Code2def func(arg):    return "value" func = decorator(func)So from above, we can see a decorator is simply another function ... Read More

Advertisements