Use Singleton Dialog Using Synchronized in Android

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

289 Views

Before getting into example, we should know what singleton design pattern is. A singleton is a design pattern that restricts the instantiation of a class to only one instance. Notable uses include controlling concurrency and creating a central point of access for an application to access its data store.Synchronized means only one thread can access at a time.This example demonstrates How to use singleton dialog using synchronized in androidStep 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 ... Read More

Get Names of All Keys in MongoDB Collection

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

2K+ Views

The syntax to get names of all keys in the collection is as follows:var yourVariableName1=db.yourCollectionName.findOne(); for(var yourVariableName 2 in yourVariableName1) { print(yourVariableName); }To understand the above syntax, let us create a collection with documents. The collection name we are creating is “studentGetKeysDemo”.The following is the query to create documents:>db.studentGetKeysDemo.insert({"StudentId":1, "StudentName":"Larry", "StudentAge":23, "StudentAddress":"US", ... "StudentHobby":["Cricket", "Football", "ReadingNovel"],    "StudentMathMarks":89, "StudentDOB":ISODate('1998-04-06')});The following is the output:WriteResult({ "nInserted" : 1 })Display all documents from a collection with the help of find() method. The query is as follows:> db.studentGetKeysDemo.find().pretty();The following is the output:{    "_id" : ObjectId("5c6c12dd68174aae23f5ef5f"),    "StudentId" : 1,    "StudentName" : ... Read More

Use Time Zone in a JSP

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

556 Views

The tag is used to specify the time zone that all tags within its body will use.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultValueTime zone to apply to the bodyYesNoneExample           JSTL fmt:timeZone Tag                                                                                                  Formatting:                                                                                                                                                                                                                                                                 The above code will generate the following result −Formatting: 23 September 2010 15:09:09 GST Etc/GMT+1222-Sep-2010 23:09:09Etc/GMT+1123-Sep-2010 00:09:09

The remove Method of Java AbstractSequentialList Class

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

85 Views

The remove() method of the AbstractSequentialList class removes the element at the specified position in this list.The syntax is as followsE remove(int index)Here, index is the index of the element to be removed. 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 remove() method in JavaExample Live Demoimport java.util.LinkedList; import java.util.AbstractSequentialList; public class Demo { public static void main(String[] args) { AbstractSequentialList absSequential = new LinkedList(); absSequential.add(25); ... Read More

Create Decade Tuple from a List Collection in Java

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

134 Views

Use the fromCollection() method to create a Decade tuple from a List collection in Java. Let us first see what we need to work with JavaTuples. To work with Decade class in JavaTuples, you need to import the following package.import org.javatuples.Decade;Note Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples.Steps: How to run JavaTuples program in EclipseThe following is an example to create ... Read More

Detect Integer Overflow in C/C++

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

386 Views

The only safe way is to check for overflow before it occurs. There are some hacky ways of checking for integer overflow though. So if you're aiming for detecting overflow in unsigned int addition, you can check if the result is actually lesser than either values added. So for example, Example Codeunsigned int x, y; unsigned int value = x + y; bool overflow = value < x; // Alternatively "value < y" should also workThis is because if x and y are both unsigned ints, if added and they overflow, their values can't be greater than either of them ... Read More

Delete One Row and Reorder Others with Correct ID in MySQL

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

604 Views

To understand the concept, let us first create a table. The query to create a table is as followsmysql> create table ReorderSortDemo -> ( -> UserId int -> ); Query OK, 0 rows affected (0.57 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into ReorderSortDemo values(14); Query OK, 1 row affected (0.13 sec) mysql> insert into ReorderSortDemo values(4); Query OK, 1 row affected (0.10 sec) mysql> insert into ReorderSortDemo values(6); Query OK, 1 row affected (0.11 sec) mysql> insert into ReorderSortDemo values(3); Query ... Read More

Insert Null Values into a Column Using JDBC

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

7K+ Views

You can insert null values into a table in SQL in two ways:Directly inserting the value NULL into the desired column as:Insert into SampleTable values (NULL);Using ‘ ’ as nullInsert into SampleTable values (NULL);While inserting data into a table using prepared statement object you can set null values to a column using the setNull() method of the PreparedStatement interface.pstmt.setNull(parameterIndex, sqlType);ExampleAssume we have a table named cricketers_data in the database with the following contents:+------------+------------+---------------+----------------+-------------+ | First_Name | Last_Name  | Date_Of_Birth | Place_Of_Birth | Country | +------------+------------+---------------+----------------+-------------+ | Shikhar    | Dhawan     | 1981-12-05    | ... Read More

Delete Multiple IDs in MongoDB

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

1K+ Views

To delete multiple ids in MongoDB, you can use $in operator. Following is the syntaxdb.yourCollectionName.remove( { _id : { $in: [yourObjectId1, yourObjectId2, yourObjectId3)] } } );Let us create a collection with documents> db.deleteMultipleIdsDemo.insertOne({"ClientName":"Chris", "ClientAge":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9cd7d6a629b87623db1b19") } > db.deleteMultipleIdsDemo.insertOne({"ClientName":"Robert", "ClientAge":28}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9cd7dea629b87623db1b1a") } > db.deleteMultipleIdsDemo.insertOne({"ClientName":"Sam", "ClientAge":25}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9cd7e9a629b87623db1b1b") } > db.deleteMultipleIdsDemo.insertOne({"ClientName":"John", "ClientAge":34}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9cd7f7a629b87623db1b1c") } > db.deleteMultipleIdsDemo.insertOne({"ClientName":"Carol", "ClientAge":36}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9cd803a629b87623db1b1d") }Following is the query to ... Read More

Extract Part of a URL in MySQL

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

3K+ Views

You need to use SUBSTRING_INDEX() function from MySQL to extract part of a URL. Let us first create a table −mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    URL text ); Query OK, 0 rows affected (0.53 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(URL) values('https:\www.example.com\homepage'); Query OK, 1 row affected (0.27 sec) mysql> insert into DemoTable(URL) values('https:\www.onlinetest.com\welcome\indexpage'); Query OK, 1 row affected (0.12 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;This will produce the following output. Here, we can ... Read More

Advertisements