Handle an Exception in JSP

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

244 Views

The tag catches any Throwable that occurs in its body and optionally exposes it. It is used for error handling and to deal more gracefully with the problem.AttributeThe tag has the following attributes −AttributeDescriptionRequiredDefaultvarThe name of the variable to hold the java.lang.Throwable if thrown by elements in the body.NoNoneExample           Tag Example                                              The exception is : ${catchException}          There is an exception: ${catchException.message}       The above code will generate the following result −The exception is : java.lang.ArithmaticException: / by zero There is an exception: / by zero

Period ofYears Method in Java

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

219 Views

The Period can be obtained with the given number of years using the ofYears() method in the Period class in Java. This method requires a single parameter i.e. the number of years and it returns the Period object with the given number of years.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Period; public class Demo { public static void main(String[] args) { int years = 3; Period p = Period.ofYears(years); System.out.println("The Period is: " + p); ... Read More

Collectors Counting Method in Java 8

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

1K+ Views

The counting() method of the Java 8 Collectors class returns a Collector accepting elements of type T that counts the number of input elements.The syntax is as follows −static Collector counting()Here, the parameter −T − type of input elementsLong − This class value of the primitive type long in an objectTo work with Collectors class in Java, import the following package −import java.util.stream.Collectors;The following is an example to implement counting() method in Java 8 −Example Live Demoimport java.util.stream.Collectors; import java.util.stream.Stream; public class Demo {    public static void main(String[] args) {       Stream stream = Stream.of("25", "50", ... Read More

Discover Current Default Database Collation via Command Line Client

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

320 Views

You need to use INFORMATION_SCHEMA.SCHEMATA for current default database collation.The syntax is as followsSELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'yourDatabaseName' LIMIT 1;Let us implement the above syntax to discover current default database collation (via command line client). Our database here is ‘sample’.The query is as follows −mysql> SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'sample' LIMIT 1;The following is the output+------------------------+ | DEFAULT_COLLATION_NAME | +------------------------+ | utf8_general_ci | +------------------------+ 1 row in set (0.00 sec)

Check If a Given Tree is a Binary Search Tree in C++

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

367 Views

Binary Search Tree is a binary tree data structure in which we have 3 propertiesThe left subtree of a binary search tree of a node contains only nodes with keys lesser than the node’s key.The right subtree of a binary search tree node contains only nodes with keys greater than the node’s key.The left and right trees of a subtree each must also be a binary search tree.AlgorithmBegin    function BSTUtill()       If node is equals to NULL then          Returns 1.       If data of node is less than minimum or greater ... Read More

Get Distinct Values with Sorted Data in MongoDB

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

1K+ Views

Following is the query to get distinct values with sorted data in MongoDBdb.yourCollectionName.distinct("yourFieldName").sort();Let us first create a collection with documents>db.getDistinctWithSortedDataDemo.insertOne({"StudentId":10, "StudentName":"John", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b1e3315e86fd1496b38c3") } >db.getDistinctWithSortedDataDemo.insertOne({"StudentId":20, "StudentName":"Carol", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b1e3e15e86fd1496b38c4") } >db.getDistinctWithSortedDataDemo.insertOne({"StudentId":10, "StudentName":"John", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b1e4415e86fd1496b38c5") } >db.getDistinctWithSortedDataDemo.insertOne({"StudentId":30, "StudentName":"Chris", "StudentAge":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b1e5115e86fd1496b38c6") } >db.getDistinctWithSortedDataDemo.insertOne({"StudentId":20, "StudentName":"Carol", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b1e5715e86fd1496b38c7") } >db.getDistinctWithSortedDataDemo.insertOne({"StudentId":40, "StudentName":"Bob", "StudentAge":20}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b1e6515e86fd1496b38c8") } >db.getDistinctWithSortedDataDemo.insertOne({"StudentId":40, "StudentName":"Bob", "Stude ... Read More

Generate 10 Random Four-Digit Numbers in Java

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

5K+ Views

To generated random integer, use the Random class with nextInt. At first, create a Random object −Random rand = new Random();The Random above is a random number generator. Now, pick the random numbers one by one. We want 10 random four-digit numbers, therefore loop it until i = 1 to 10 −for (int i = 1; i

Divide Records in Ascending and Descending Order in MySQL

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

126 Views

Yes, you can perform this in MySQL by first getting the middle value. Let us first create a table:mysql> create table DemoTable (    UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY ); Query OK, 0 rows affected (0.65 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable values(); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.08 sec) mysql> insert into DemoTable values(); Query OK, 1 row affected (0.16 sec) mysql> ... Read More

What is an Unsigned Char in C++

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

6K+ Views

In C++ we have seen there is character type data called char. Sometimes we have seen unsigned char also. So here we will see what is basically the unsigned char means. What are the basic differences between signed char and unsigned char?Signed char and unsigned char both are used to store single character. The variable stores the ASCII value of the characters. For an example if ‘A’ is stored, actually it will hold 65. For signed char we need not to write the signed keyword. But for unsigned, we have to mention the keyword. The syntax is like below.unsigned char ... Read More

Meaning of Background App in Android

Sashi K
Updated on 30-Jul-2019 22:30:25

7K+ Views

Foreground refers to the active apps which consume data and are currently running on the mobile. Background refers to the data used when the app is doing some activity in the background, which is not active right now.This is due to the fact that whether they are active or not, apps consume data. They may bechecking for updates or refreshing the user contentrunning ads in the backgroundsending notificationsAll these may be useful activities, but we do not want our data to deplete in the background without our permission and notice. We can restrict this background data depletion by using the ... Read More

Advertisements