Example on ToggleButton in Android

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

217 Views

Before getting into example, we should know what is togglebutton in android, Toggle button is extended view of Button view. It going to represent of state of button as checked and unchecked. Here is the simple solution about toggle button 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 added toggle button, when user click on toggle button it going to change the state.Step 3 ... Read More

Find Document by Field Name with Specific Value in MongoDB

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

625 Views

To find the document by field name with a specific value, you can use $exists operator. Let us create a collection with documents> db.findByFieldName.insertOne( { "Client":{ "ClientDetails":{ "ClientName":"Larry", "ClientAge":29 }, "ClientProjectDetails":{ "ProjectName":"Online Book Store", "TeamSize":10, "TechnologyUsed":"Spring Boot" } } } ); { "acknowledged" : true, "insertedId" : ObjectId("5c9e93b2d628fa4220163b64") } > db.findByFieldName.insertOne({ ... "   Client":{ ... "      ClientDetails":{ ... "         ClientName":"Chris", ... "         ClientAge":27 ...        }, ...       "ClientEducationDetails":{ ... "         isEducated":true, ...          "CollegeName":"M.I.T." ... ...   ... Read More

Get Checksum of a Byte Array in Java

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

1K+ Views

Create a Byte Array for which you want the Checksum −byte[] arr = "This is it!".getBytes();Now, create a Checksum object −Checksum checksum = new Adler32(); checksum.update(arr, 0, arr.length);The update() above updates the current checksum with the specified array of bytes.Now, get the checksum with getValue() method, which gives the current checksum value.Example Live Demoimport java.util.zip.Adler32; import java.util.zip.Checksum; public class Demo {    public static void main(String[] argv) throws Exception {       byte[] arr = "This is it!".getBytes();       Checksum checksum = new Adler32();       checksum.update(arr, 0, arr.length);       long res = checksum.getValue();   ... Read More

Select from MySQL Where Last Value in a String

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

254 Views

You can use LIKE operator with wildcards to select the records where last value in a string = x, for example ‘10’, ‘15’, etc.Let us first create a table −mysql> create table DemoTable (    ClientId varchar(20) ); Query OK, 0 rows affected (0.68 sec)Insert records in the table using insert command −mysql> insert into DemoTable values('CLI-101'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('CLI-110'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('CLI-201'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('CLI-210'); Query OK, 1 row affected (0.13 sec) ... Read More

CharBuffer equals Method in Java

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

167 Views

The equality of two buffers can be checked using the method equals() in the class java.nio.CharBuffer. Two buffers are equal if they have the same type of elements, the same number of elements and the same sequence of elements. The method equals() returns true if the buffers are equal and false otherwise.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 buffer1 = CharBuffer.allocate(n);         ... Read More

Pre and Post Increment Operator Behavior in C, C++, Java, and C#

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

4K+ Views

The Pre increment and post increment both operators are used as increment operations. The pre increment operator is used to increment the value of some variable before using it in an expression. In the pre increment the value is incremented at first, then used inside the expression.if the expression is a = ++b; and b is holding 5 at first, then a will hold 6. Because increase b by 1, then set the value of a with it.Example Code#include using namespace std; main () { int a, b = 15; a = ++b; cout

Find Document with Array Containing Specific Value in MongoDB

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

798 Views

You can use find() method to find document with array that contains a specific value. The syntax is as follows:db.yourCollectionName.find({"yourArrayFieldName":"yourValue"}, .......N).pretty();To understand the above syntax, let us create a collection with documents. The query to create a collection with documents is as follows:>db.findSpecificValue.insertOne({"StudentId":1, "StudentName":"Larry", "FavouriteSubject":["C", "C++", "Java"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6e8996140577d89182b8d0") } >db.findSpecificValue.insertOne({"StudentId":2, "StudentName":"Larry", "FavouriteSubject":["MongoDB", "MySQL", "SQL Server"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6e89b1140577d89182b8d1") }Display all documents from a collection with the help of find() method. The query is as follows:> db.findSpecificValue.find().pretty();The following is the output:{    "_id" : ObjectId("5c6e8996140577d89182b8d0"),    "StudentId" ... Read More

What is a Response Object in JSP

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

1K+ Views

The response object is an instance of a javax.servlet.http.HttpServletResponse object. Just as the server creates the request object, it also creates an object to represent the response to the client.The response object also defines the interfaces that deal with creating new HTTP headers. Through this object, the JSP programmer can add new cookies or date stamps, HTTP status codes etc.The response object methods can be used to set HTTP response header in your servlet program. This object represents the server response.Following example would use setIntHeader() method to set Refresh header to simulate a digital clock −       ... Read More

LOB Data Types and Their Restrictions in JDBC

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

210 Views

A BLOB is binary large object that can hold a variable amount of data with a maximum length of 65535 charactersThese are used to store large amounts of binary data, such as images or other types of files.A CLOB stands for Character Large Object in general, an SQL Clob is a built-in datatype is used to store large amount of textual data. Using this datatype, you can store data up to 2, 147, 483, 647 characters.Blob and Clob data types together are known as LOB (Large Object) datatypes. Following are the restrictions on these datatypes.Cannot compare: We cannot compare CLOB ... Read More

LocalTime ofNanoOfDay Method in Java

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

123 Views

A LocalTime object can be obtained using the nanoseconds of the day with the ofNanoOfDay() method in the LocalTime class in Java. This method requires a single parameter i.e. the nanoseconds of the day and it returns the LocalTime object for the nanoseconds of the dayA program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args){       long nanoSeconds = 1000000000;       System.out.println("The nanoseconds of the day: " + nanoSeconds);       System.out.println("The LocalTime is: " + LocalTime.ofNanoOfDay(nanoSeconds));    } }outputThe nanoseconds of the day: ... Read More

Advertisements