Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do Java programs ever crash?

Tags:

java

c++

crash

I am a c++ programmer , I know little bit about java. I know that java programmers do not have to work with memory directly like C++. I also know that most crashes in C++ appliations are due to memory corruptions.

So can an application written in Java crash due to a memory related issue?

Thanks

like image 352
Satbir Avatar asked May 19 '10 08:05

Satbir


People also ask

Can a Java program crash?

There are various possible reasons for a crash. For example, a crash can occur due to a bug in the Java HotSpot VM, in a system library, in a Java SE library or an API, in application native code, or even in the operating system (OS). External factors, such as resource exhaustion in the OS can also cause a crash.

How do you make a Java crash?

To crash a JVM, aside from JNI, you need to find a bug in the VM itself. An infinite loop just consumes CPU. Infinitely allocating memory should just cause OutOfMemoryError's in a well built JVM. This would probably cause problems for other threads, but a good JVM still should not crash.

What causes a program to crash?

Typical causes include accessing invalid memory addresses, incorrect address values in the program counter, buffer overflow, overwriting a portion of the affected program code due to an earlier bug, executing invalid machine instructions (an illegal opcode), or triggering an unhandled exception.


1 Answers

Contrary to some other answers I’ll claim that Java programs will crash as often, or possibly even more often than C++ programs.

By “crash” most people understand that a program encounters an error that isn’t properly handled, causing the application to terminate. Well, this of course happens and has got nothing to do with the way Java treats memory.

This is a good thing. What makes C++ so dangerous, and Java comparatively safe, is the precisely the fact that Java will crash in cases where C++ will happily continue running, albeit doing very wrong and potentially dangerous things (such as writing to uninitialized memory, overflowing buffers, …). Java’s crashing (e.g. throwing exceptions) prevents worse damage. C++ applications, on the other hand (due to the failure to terminate on errors), may do damage to external data or the system. Or they may just deliver a wrong (but seemingly plausible) result.

It’s against these dangers that Java guards, not against crashes per se.

like image 178
Konrad Rudolph Avatar answered Oct 09 '22 01:10

Konrad Rudolph