Throw Exception Without Breaking For Loop in Java

Maruthi Krishna
Updated on 12-Sep-2019 08:54:22

9K+ Views

Whenever an exception occurred in a loop the control gets out of the loop, by handling the exception the statements after the catch block in the method will get executed. But, the loop breaks.Example Live Demopublic class ExceptionInLoop{    public static void sampleMethod(){       String str[] = {"Mango", "Apple", "Banana", "Grapes", "Oranges"};          try {             for(int i=0; i

Give a Warning for Non-JavaScript Browsers

Giri Raju
Updated on 12-Sep-2019 08:47:00

268 Views

To let users know about non-JavaScript web browsers, use the tag. The HTML tag is used to handle the browsers, which do recognize tag but do not support scripting. This tag is used to display alternate text messageHere’s an example,           HTML noscript Tag                                              Your browser does not support JavaScript!          

Can We Override a Catch Block in Java

Maruthi Krishna
Updated on 12-Sep-2019 08:46:56

1K+ Views

DescriptionWhen a piece of code in particular method throws an exception, and is handled using try-catch pair. If we are calling this method from another one and, the calling line is wrapped within try-catch pair. Now, how can I override the catch block by the catch block of the calling method.When a piece of code in a method throws an exception (compile time) we must either handle it by wrapping it within the try-catch pair or, throw it (postpone) to the calling method using the throws keyword else a compile time error occurs.In the following Java example the code in ... Read More

Detect If JavaScript is Disabled in a Browser

radhakrishna
Updated on 12-Sep-2019 08:46:00

7K+ Views

To detect if JavaScript is disabled in a web browser, use the tag. The HTML tag is used to handle the browsers, which do recognize tag but do not support scripting. This tag is used to display an alternate text message.Here’s an example,           HTML noscript Tag                                                    Your browser does not support JavaScript!          

Get Exception Log from Console and Write to External File in Java

Maruthi Krishna
Updated on 12-Sep-2019 08:39:04

1K+ Views

There are several logging frame works available to log your data in to files. You can also define your own method.Example − Using I/O packageFollowing Java program has an array storing 5 integer values, we are letting the user to choose two elements from the array (indices of the elements) and performing division between them. We are wrapping this code in try block with three catch blocks catching ArithmeticException, InputMismatchException and, ArrayIndexOutOfBoundsException. In each of them we are invoking the writeToFile() method.This method accepts an exception object, and appends it to a file using the write() method of the Files ... Read More

Difference Between Comments and Documentation in JavaScript

radhakrishna
Updated on 12-Sep-2019 08:35:18

637 Views

/*…*/ and /**…*/ are multi-line comments. The following is a multi line comment in JavaScript./*    * This is a multiline comment in JavaScript    * It is very similar to comments in C Programming */The following example shows how to use multi-line comments in JavaScript.     The comment /** */ is for  PHPDocumentator ,  which is used to make automatic documentation.

Difference Between lang and type Attributes in a Script Tag

Arushi
Updated on 12-Sep-2019 08:31:25

291 Views

JavaScript lang attributeThis attribute specifies what scripting language you are using. Typically, its value will be javascript. Although recent versions of HTML (and XHTML, its successor) have phased out the use of this attribute.JavaScript type attributeThis attribute is what is now recommended to indicate the scripting language in use and its value should be set to "text/javascript".Here you can see how it is used:Live Demo                              

Why JavaScript is Case-Sensitive but HTML is Not

varun
Updated on 12-Sep-2019 08:28:32

530 Views

A script is in plain text and not just markup like HTML, which is case insensitive. In JavaScript, the while keyword should be "while", not "While" or "WHILE". Case sensitivity is important since it is closely related to HTML, but some methods and events are mentioned differently. JavaScrip has a strict syntax to process the client-side-scripts written in JavaScript.Some tags and attributes in HTML have the same name as JavaScript objects and properties. In HTML, the attribute and tag names are case-insensitive. The close association of HTML and JavaScript can lead to confusion, so case sensitivity is more important in ... Read More

Java Finally Block Explanation

Maruthi Krishna
Updated on 12-Sep-2019 08:26:37

195 Views

The finally block follows a try block or a catch block. A finally block of code always executes, irrespective of occurrence of an Exception.The return statement in the method too does not stop the finally block from getting executed.ExampleIn the following Java program we are using return statement at the end of the try block still, the statements in the finally block gets executed. Live Demopublic class FinallyExample {    public static void main(String args[]) {       int a[] = new int[2];       try {          System.out.println("Access element three :" + a[3]);     ... Read More

Guide Lines for Using Wildcards in Java

Maruthi Krishna
Updated on 12-Sep-2019 08:22:22

161 Views

Instead of the typed parameter in generics (T) you can also use “?”, representing an unknown type. You can use a wild card as a −Type of parameter.Field.Local field.The only restriction on wilds cards is that you cannot it as a type argument of a generic method while invoking it.Java provides 3 types of wild cards namely upper-bounded, lower-bounded, un-bounded. There are two types of wildcards in Java −Upper-bounded wildcards − Upper bounds in wild cards is similar to the bounded type in generics. Using this you can enable the usage of all the subtypes of a particular class as a ... Read More

Advertisements