Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 556 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.3K Development
- 17 Developer Projects
- 139 Programming Languages
- 293K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 158 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 468 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
Division by Zero Execption

870171
Member Posts: 10
hi;
i have heard about java.lang.AirthmeticException / by zero execption.
class abc
{
public static void main(String args[])
{
int a = 10/0;
System.out.println(a);
}
}
this shows / by zero execption.
but when i used the following code
class abc
{
public static void main(String args[])
{
double a = 10.0/0;
System.out.println(a);
}
}
then it doesnot shows execption. in this case output comes Infinity .
is / by zero execption only comes in case of int. i need some explanation for clearing this concept
regards
pardeep jangra
i have heard about java.lang.AirthmeticException / by zero execption.
class abc
{
public static void main(String args[])
{
int a = 10/0;
System.out.println(a);
}
}
this shows / by zero execption.
but when i used the following code
class abc
{
public static void main(String args[])
{
double a = 10.0/0;
System.out.println(a);
}
}
then it doesnot shows execption. in this case output comes Infinity .
is / by zero execption only comes in case of int. i need some explanation for clearing this concept
regards
pardeep jangra
Answers
-
867168 wrote:Yes.
is / by zero execption only comes in case of int. -
Out of curiosity, why would you ever want to divide by zero?
-
sosc wrote:I'm not sure that's the point. I think the point is to know when an exception could be thrown. I could see the case where someone mistakenly putting a try catch block around doubles that might divide by 0.
Out of curiosity, why would you ever want to divide by zero? -
Yes, but it is also typical to separate input validation from main code.
But I guess that may not necessarily be the scenario here. -
sosc wrote:Considering the question was in the Training / Learning / Certification section , I dont think he really wanted to
Out of curiosity, why would you ever want to divide by zero? -
hi;
i just want to improve the concept. because i have seen many people who use try and catch block when double and float is divided by zero. if it does not shows exception then what is the need of try and catch block?
if somebody knows more on this topic please share his experience with us. and who thinks this is a really boring concept kindly move out of this thread.
regards
pardeep jangra -
867168 wrote:Just because people might be putting try/catch blocks everywhere, doesn't mean they are needed. Have you ever thought that maybe those people don't really know Java? You should be careful whose code you trust.
hi;
i just want to improve the concept. because i have seen many people who use try and catch block when double and float is divided by zero. if it does not shows exception then what is the need of try and catch block?if somebody knows more on this topic please share his experience with us. and who thinks this is a really boring concept kindly move out of this thread.Well it is a pretty boring concept. At least unless we go down to the machine instructions and see how the FPU and integer division work.
This discussion has been closed.