answersLogoWhite

0

What else can I help you with?

Continue Learning about Engineering

What keyword are used in java for exception handling?

The important keywords used in Java with respect to Exception Handling are: a. Throw - The "throw" keyword is used to throw exceptions from inside a method b. Throws - The "throws" keyword is used to signify the fact that the code contents within the current method may be throwing an exception and the calling method must handle them appropriately


What is difference between exception handling in C and Java?

Easy: there is no exception-handling in C.


How nesting of methods is done in java?

No, Java only allows a method to be defined within a class, not within another method.


Define an exception called NoMatchException that is thrown when a string is not equal to Symbiosis Write a Java program that uses this exception?

import java.util.Scanner; class NoMatchException extends Exception { static void method() throws Exception{ String s = "India"; String s2 = " "; try { if (!s.equals(s2)){ throw new NoMatchException(); //System.out.println("Strings are equal"); } else { System.out.println("Strings are equal"); //throw new NoMatchException(); } } catch(NoMatchException ne){ System.out.println("Exception Found For String"); } finally { System.out.println("In Finally Block"); } } } public class BasicException { static void myMethod(int x, int y) throws Exception{ try { if(x < y ) { System.out.println("Y is greater then X"); throw new Exception(); } else System.out.println("Y is smaller"); } catch(Exception ex) { System.out.println("exception found"); //System.out.println(ex.toString()); } finally { System.out.println("FINALLY block"); } } public static void main(String args[]) throws Exception{ Scanner s = new Scanner(System.in); int d, a, x, y; System.out.println("Enter the value of x and y"); x = s.nextInt(); y = s.nextInt(); try { BasicException.myMethod(x , y); }catch(Exception e) { System.out.println("main method exception"); System.out.println(e.toString()); } try { NoMatchException.method(); } catch(NoMatchException e) { System.out.println("Exception Caught"); } try{ d=0; a=42/d; System.out.println("This will not be printed."); } catch(ArithmeticException e){ System.out.println("Division by zero."); } } }


Why constructor in Java doesn't have any return type?

The constructor of a Java class is not an ordinary method. Its purpose is not to return any value. The purpose of the constructor is to instantiate the class which it does. Since, the purpose of a constructor is only to instantiate and initialize its class and not anything else, it does not have a return type. All it does is creates an object of that class.

Related Questions

What is the purpose of method in java?

go ask your monitor.


What keyword are used in java for exception handling?

The important keywords used in Java with respect to Exception Handling are: a. Throw - The "throw" keyword is used to throw exceptions from inside a method b. Throws - The "throws" keyword is used to signify the fact that the code contents within the current method may be throwing an exception and the calling method must handle them appropriately


What are the Topics under Advanced Java?

Some topics under Advanced Java are: a. Exception Handling b. Threading/Multi-Threading c. Remote Method Invocation d. Serialization e. etc


What is overridnig method and overlording method in java?

There is no such thing as overlording in Java.


What is the purpose of integer Java?

Within Java, an integer is an Object, which is converse to the "int", which is a primitive. In reality, this means that for an integer, a method can be called upon it, whereas with a primitive, this is not the case.


What is the task of the main method in java platform?

It is the method that gets called when a Java application is started.


How do you use the hasNext method in java but not have it block waiting for input?

hasNext() is a method of different classes in Java. If you mean java.util.Iterator.hasNext() or java.util.Scanner.hasNext(), it shouldn't block while waiting for input. That is part of the purpose of the hasNext() method - so that the caller can determine if there is more data without actually fetching the data.


What is difference between exception handling in C and Java?

Easy: there is no exception-handling in C.


Which is the most usable method or constructor in java?

There is no comparison between methods and constructors. They are both present for a reason and each has its own purpose.


How nesting of methods is done in java?

No, Java only allows a method to be defined within a class, not within another method.


What is function in java terminology?

In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.In Java, a function is called a "method". In Java as well as other languages, a method is a function defined specifically for one class. In Java, this is the only way to define functions, therefore, all functions are methods.


What is a method in Java?

A Java method is a sequence of statements. It is comparable to a function, subroutine, or procedure in other languages.