HTML DOM Anchor Search Property

AmitDiwan
Updated on 02-Jul-2020 14:53:54

154 Views

The HTML DOM search property associated with the anchor tag () returns the query string part of the href property value. The query string part is after the ? in a url and is usually used to pass information to the server. It is used when a get request is sent to the server and information is embedded in cleartext in the link.SyntaxFollowing is the syntax fora) Returning the search propertyanchorObject.searchb) Setting the search propertyanchorObject.search = querystringExampleLet us see an example of HTML DOM anchor search property − Example Site Click the button to change the querystring part ... Read More

Difference Between throw e and throw new Exception(e) in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:46:36

6K+ Views

An exception is an issue (run time error) occurred during the execution of a program. Here are some example scenarios −If you have an array of size 10 if a line in your code tries to access the 11th element in this array.If you are trying to divide a number with 0 which (results to infinity and JVM doesn’t understand how to valuate it).When exception occurs the program terminates abruptly at the line that caused exception, leaving the remaining part of the program unexecuted. To prevent this, you need to handle exceptions.There are two types of exceptions in java.Unchecked Exception ... Read More

How IllegalArgumentException is Handled Inside If Condition in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:44:42

989 Views

Whenever you pass inappropriate arguments to a method or constructor, an IllegalArgumentException is thrown. It is a Runtime exception therefore there is no need to handle this at the time of compilation.ExampleThe valueOf() method of the java.sql.Date class accepts a String representing a date in JDBC escape format yyyy-[m]m-[d]d and converts it into a java.sql.Date object.import java.sql.Date; import java.util.Scanner; public class IllegalArgumentExample {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter your date of birth in JDBC escape format (yyyy-mm-dd) ");       String dateString = sc.next();   ... Read More

Throw Null in Java and Upcast to NullPointerException

Maruthi Krishna
Updated on 02-Jul-2020 14:42:59

1K+ Views

In Java there is default value for every type, when you don’t initialize the instance variables of a class Java compiler initializes them on your be-half with these values. Null is the default value of the object type, you can also manually assign null to objects in a method.Object obj = null;But, you cannot use an object with null value or (a null value instead of an object) if you do so, a NullPointerException will be thrown.Examplepublic class Demo {    String name = "Krishna";    int age = 25;    public static void main(String args[]) {       ... Read More

When Does a Java Array Throw a NullPointerException

Maruthi Krishna
Updated on 02-Jul-2020 14:40:03

4K+ Views

In Java there is default value for every type, when you don’t initialize the instance variables of a class Java compiler initializes them on your be-half with these values. Null is the default value of the object type, you can also manually assign null to objects in a method.Object obj = null;But, you cannot use an object with null value or (a null value instead of an object) if you do so, a NullPointerException will be thrown.Examplepublic class Demo {    String name = "Krishna";    int age = 25;    public static void main(String args[]) {       ... Read More

Try-Catch-Finally Blocks in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:35:00

2K+ Views

An exception is an issue (run time error) occurred during the execution of a program. For understanding purpose let us look at it in a different manner.Generally, when you compile a program, if it gets compiled without a .class file will be created, this is the executable file in Java, and every time you execute this .class file it is supposed to run successfully executing each line in the program without any issues. But, in some exceptional cases, while executing the program, JVM encounters some ambiguous scenarios where it doesn’t know what to do.Here are some example scenarios −If you ... Read More

Cause of NoSuchElementException and How to Fix it in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:33:06

1K+ Views

What is the cause of NoSuchElementException and how can we fix it in java?An exception is an issue (run time error) occurred during the execution of a program. When an exception occurred the program gets terminated abruptly and, the code past the line that generated the exception never gets executed. Each exception is represented by its respective class.Cause for NosuchElementExceptionThis is a Runtime exception i.e. it occurs at the execution time.While accessing the contents of a collection, array or other objects using the accessor methods of an Enumeration, Iterator or, tokenizer, such as next() or nextElement(), if you try to ... Read More

Handle MalformedURLException in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:31:32

2K+ Views

While working with client-server programming in Java (JSE), if you are using java.net.URL class object in your program, you need to instantiate this class by passing a string representing required URL to which you need to establish connection. If the url you have passed in the string which cannot be parsed or, without legal protocol a MalformedURLException is generated.ExampleIn the following Java example we are tring to get establish a connection to a page and publishing the response.We have tampered the protocol part, changed it to htt, which should be http or, https.import java.util.Scanner; import java.io.IOException; import java.net.HttpURLConnection; import java.net.URL; ... Read More

Variables Defined in Try Cannot Be Used in Catch or Finally in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:30:03

6K+ Views

A class in Java will have three kinds of variables namely, static (class), instance and, local.Instance variables − These variables belong to the instances (objects) of a class. These are declared within a class but outside methods. These are initialized when the class is instantiated. They can be accessed from any method, constructor or blocks of that particular class.Class/static variables − class/static variables belong to a class, just like instance variables they are declared within a class, outside any method, but, with the static keyword.They are available to access at the compile time, you can access them before/without instantiating the ... Read More

Do All Properties of an Immutable Object Need to Be Final in Java

Maruthi Krishna
Updated on 02-Jul-2020 14:29:20

1K+ Views

Immutable class/object is the one whose value cannot be modified. For example, Strings are immutable in Java i.e. once you create a String value in Java you cannot modify it. Even if you try to modify, an intermediate String is created with the modified value and is assigned to the original literal.Defining immutable objectsWhenever you need to create an object which cannot be changed after initialization you can define an immutable object. There are no specific rules to create immutable objects, the idea is to restrict the access of the fields of a class after initialization.ExampleFollowing Java program demonstrates the ... Read More

Advertisements