There are many reasons why Java is a safe language, and it's definitely safer than some languages, but I think it's a stretch to say that it's safer than all other languages.

Java has a variety of safety features in place:

  1. Automatic null-checking of references, bounds-checking of arrays, verification of casts, etc. to prevent the program from making type errors. Compare this to C or C++, where these same errors (with a few exceptions) cause undefined behavior.

  2. Verification of bytecode prior to execution. This makes it impossible for the program to jump to an undefined instruction, or to try to perform an operation on a nonexistent object, or to make a type error at the instruction level, etc. Compare this to C or assembly, where the program can jump to bad instructions, or try reading nonexistent parameters to functions (think va_args), etc.)

  3. Runtime security checks when loading in new code. The use of SecurityManager and ClassLoader make it easy for the Java runtime to prevent arbitrary code from executing on the computer by mediating access to system resources and preventing the program from loading or generating arbitrary code at runtime. Compare this to C or C++, which can read and write arbitrary values, issue arbitrary system calls, generate and execute arbitrary code, etc.

  4. Library-level safety of certain features. For example, String is immutable and final, so a function that receives a String can verify the string and not have to worry about another thread changing its value.

This isn't a complete list of Java's safety features, but it should give you a sense of some of the design considerations in Java that are not present in other languages.

Hope this helps!

Answer from templatetypedef on Stack Overflow
🌐
Quora
quora.com › Which-language-is-considered-to-be-more-secure-C-or-Java
Which language is considered to be more secure, C or Java? - Quora
Answer (1 of 6): Whether Java is more secure than C is a simple question to ask, but a hard question to answer well. When we began writing the SEI CERT Oracle Coding Standard for Java, we thought that Java would require fewer secure coding rules ...
🌐
Software Engineering Institute
sei.cmu.edu › blog › is-java-more-secure-than-c
Is Java More Secure than C? - Software Engineering Institute
October 5, 2015 - Most exploits that involve Java ... going back to the late 1980s (and probably earlier). For these reasons, Java is often considered more secure....
Discussions

.net - Why Java is secure compared with other programming languages? - Stack Overflow
We expect answers to be supported ... polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 12 years ago. Java vendor and community says that "Java is more secure than other languages"... More on stackoverflow.com
🌐 stackoverflow.com
What makes Java secure than C++?
No. It is the opposite. C++ is better than Java. But it could be not. Let explain me: which is better, a sedan car or a jumbo jet? If you want to go to a supermarket, your sedan is better. If you want to go to another country on the other side of the ocean, jumbo is better. The same thing happens, more or less, between C++ and Java. C++ is a jumbo jet and Java is a beautiful sedan. Which is better? Therefore, for an intermediate program on a cell phone, Java is better. For a very intense CPU program, on the same cell phone, or even more difficult, on a main computer, C++ is definitely better. Now a harder question, if you want to be a hobby programmer, which one would you learn? And, if you want to be an expert, what would you learn? Do you want to know how to drive a sedan or do you want to be a pilot? It's up to you. On the other hand, it might be possible, or not, to earn more money driving the sedan, excuse me, coding in Java, than coding in C++, but that's another story. Finally, yes, a good driver will say that learning to drive a jumbo is stupidly complicated and useless because everything is done with the sedan, but if you talk to a pilot, he will simply laugh at you. That said, my advice is: learn and use C++, you will enjoy it. And, no, it is not so complicated. Regards. If this answer was helpful, Please UPVOTE and consider following me-Mario Galindo Queralt [ https://www.quora.com/profile/Mario-Galindo-Queralt ]. More on quora.com
🌐 quora.com
7
1
May 6, 2019
security - Why is Java labeled as a "secure" language? - Stack Overflow
In Java, you cannot access out-of-bound arrays, and you don't have pointers, and thus several security flaws like stack corruption or buffer overflow is impossible to exploit in Java. But Java is not inherently more secure than any other language; it's just there is less chance to make mistakes ... More on stackoverflow.com
🌐 stackoverflow.com
C++ or Java for a career in Information Security - Information Security Stack Exchange
I wanted to know which language should i chose if i want to have a career in information security later on (about to get into college). I have even read that c dominates c++ and if that is the case... More on security.stackexchange.com
🌐 security.stackexchange.com
🌐
Hacker News
news.ycombinator.com › item
Is Java more secure than C? | Hacker News
October 14, 2015 - C is categorically less secure than Java · Almost every "rule" SEI CERT has for Java either applies directly to C, or is mooted by C's fundamental insecurity
Top answer
1 of 3
11

There are many reasons why Java is a safe language, and it's definitely safer than some languages, but I think it's a stretch to say that it's safer than all other languages.

Java has a variety of safety features in place:

  1. Automatic null-checking of references, bounds-checking of arrays, verification of casts, etc. to prevent the program from making type errors. Compare this to C or C++, where these same errors (with a few exceptions) cause undefined behavior.

  2. Verification of bytecode prior to execution. This makes it impossible for the program to jump to an undefined instruction, or to try to perform an operation on a nonexistent object, or to make a type error at the instruction level, etc. Compare this to C or assembly, where the program can jump to bad instructions, or try reading nonexistent parameters to functions (think va_args), etc.)

  3. Runtime security checks when loading in new code. The use of SecurityManager and ClassLoader make it easy for the Java runtime to prevent arbitrary code from executing on the computer by mediating access to system resources and preventing the program from loading or generating arbitrary code at runtime. Compare this to C or C++, which can read and write arbitrary values, issue arbitrary system calls, generate and execute arbitrary code, etc.

  4. Library-level safety of certain features. For example, String is immutable and final, so a function that receives a String can verify the string and not have to worry about another thread changing its value.

This isn't a complete list of Java's safety features, but it should give you a sense of some of the design considerations in Java that are not present in other languages.

Hope this helps!

2 of 3
3

You mention you read some where but can you please re-read it because I guess when it was written the author would be comparing the JAVA with C++ / Fortran / C etc.

Also there is an old post you can read about the testability of security in http://www.veracode.com/blog/2010/06/which-tastes-better-for-security-java-or-net/

you can see both are same almost....

Top answer
1 of 15
1826
No. It is the opposite. C++ is better than Java. But it could be not. Let explain me: which is better, a sedan car or a jumbo jet? If you want to go to a supermarket, your sedan is better. If you want to go to another country on the other side of the ocean, jumbo is better. The same thing happens, more or less, between C++ and Java. C++ is a jumbo jet and Java is a beautiful sedan. Which is better? Therefore, for an intermediate program on a cell phone, Java is better. For a very intense CPU program, on the same cell phone, or even more difficult, on a main computer, C++ is definitely better. Now a harder question, if you want to be a hobby programmer, which one would you learn? And, if you want to be an expert, what would you learn? Do you want to know how to drive a sedan or do you want to be a pilot? It's up to you. On the other hand, it might be possible, or not, to earn more money driving the sedan, excuse me, coding in Java, than coding in C++, but that's another story. Finally, yes, a good driver will say that learning to drive a jumbo is stupidly complicated and useless because everything is done with the sedan, but if you talk to a pilot, he will simply laugh at you. That said, my advice is: learn and use C++, you will enjoy it. And, no, it is not so complicated. Regards. If this answer was helpful, Please UPVOTE and consider following me-Mario Galindo Queralt [ https://www.quora.com/profile/Mario-Galindo-Queralt ].
2 of 15
3
Read the following all points, you will get to know that “What makes Java Secure than C++ and Other Programming Languages”. Java’s security model Java’s security model is intended to help and protect users from hostile programs downloaded from some untrusted resource within a network through “sandbox”. It allows all the Java programs to run inside the sandbox only and prevents many activities from untrusted resources including reading or writing to the local disk, creating any new process or even loading any new dynamic library while calling a native method. No use of pointers C/C++ language uses pointers, which may cause unauthorized access to memory blocks when other programs get the pointer values. Unlike conventional C/C++ language, Java never uses any kind of pointers. Java has its internal mechanism for memory management. It only gives access to the data to the program if has appropriate verified authorization. Exception handling concept The concept of exception handling enables Java to capture a series of errors that helps developers to get rid of risk of crashing the system. Defined order execution All the primitives are defined with a predefined size and all the operations are defined in a specific order of execution. Therefore, the code executed in different Java Virtual Machines won’t have a different order of execution. Byte code is another thing that makes Java more secure Every time when a user compiles the Java program, the Java compiler creates a class file with Bytecode, which are tested by the JVM at the time of program execution for viruses and other malicious files. Tested code re-usability The Java object encapsulation provides support for the concept of “programming by contract”. This allows the developers to re-use the code that has already been tested while developing Java enterprise applications. Access Control functionality Java’s access-control functionality on variables and methods within the objects provide secure program by preventing access to the critical objects from the untrusted code. Protection from security attacks It allows developers to declare classes or methods as FINAL. We all know that any class or method declared as final can’t be overridden, which helps developers to protect code from security attacks like creating a subclass and replacing it with the original class and override methods. Garbage collection mechanism Garbage collection mechanism aids more to the security measures of Java. It provides a transparent storage allocation and recovering unutilized memory rather than deallocating memory through manual action. It will help developers to ensure the integrity of the program during its execution and avoids any JVM crash due to incorrect freeing of memory. Type-safe reference casting in JVM Whenever you use an object reference, the JVM monitors you. If you try to cast a reference to a different type, it will make the cast invalid. Reference: GRAILS Accelerating J2EE Whitepaper I hope this information will help you.
🌐
Educative
educative.io › blog › why-java-is-more-secure-than-other-languages
11 reasons why Java is more secure than other languages
Many lower-level languages like C or C++ compile directly to machine code without an independent verification step, making them more vulnerable to buffer overruns or corrupt control flow. This verification layer is a key reason why Java is considered more secure than other languages.
🌐
Slashdot
it.slashdot.org › story › 05 › 10 › 10 › 110239 › java-or-c-is-one-more-secure
Java or C: Is One More Secure? - Slashdot
October 10, 2005 - The thing is though, C is still insecure as standard, while Java is still secure by design (and has shown to be in practice). Not that there's an idiot proof general purpose programing language/environment out there - being "secure by design" ...
Find elsewhere
🌐
Ksolves
ksolves.com › blog › java › why-java-is-more-secure-than-other-languages
Why Java Is More Secure Than Other Languages? | Ksolves
February 1, 2025 - With Java security features such as automatic memory management, private transmission, and corruption prevention, Java becomes a great option for anyone worried about security. The use of pointer values for managing application memory and protecting ...
🌐
SEI Insights
insights.sei.cmu.edu › library › is-java-more-secure-than-c
Is Java More Secure Than C? - SEI Blog
When researchers on the CERT Secure Coding Team began writing the SEI CERT Oracle Coding Standard for Java, they thought that Java would require fewer secure coding rules than the SEI CERT C Coding Standard because Java was designed with security in mind. They also assumed that a more secure language would need fewer rules than a less secure one.
Top answer
1 of 2
4

Don't choose; learn both.

If you want to make a career which involves programming (and most careers in information security do that), then you must learn programming, not programming languages. If you concentrate on a single language then you will be a very poor programmer, and your career will fail.

Programming is a state of the mind; languages are distractions.

2 of 2
3

Information security is a broad field. Depending on the branch you want to specialize you might find useful to learn C, C++, Java, python, shellscripting or neither. About the two you have mention:

  1. C++ will give you a lot of knowledge about how memory should be managed, and how to build secure code with these assumptions.
  2. Java will give you a lot of knowledge about how a virtual machine works and how to build secure code with these assumptions.
  3. Others will tell you that once you know how to program, selecting a language program is about knowing some small details.

Consider that even after mastering the two of them you will learn nothing about communications, cryptography, secret management... Securing is not about programming languages. Securing (well, a big simplification) is about information and how is it treated, stored, shared and by whom (confidentiality, availability, integrity and non-repudio).

But if you want a closer tech security approach...

I learnt a lot about security getting into the Debian (linux) world, I really believe that getting inside the linux administration world will give you big notions about security and security design. Then learning basic cryptography and how communications works will give you the rest. After you have managed all these concepts (and believe me, that is a lot to say) you will need to take into consideration thousands of regulations and security standards.

Is an arduous path, but it is a nice one =)

[Edit] Addendum: I belive the better place to learn about the topics you want is a forum, any hacking forum will do for a beginner level... You eventually will meet people and will find sources of information as you continue learning.

🌐
CodeSquadz
codesquadz.com › home › c++ vs java: key differences, similarities and benefits
C++ vs Java: Key differences, similarities & benefits
January 24, 2023 - Java is a high-level and object-oriented programming language having 1995 as its foundation year. It is a faster, more secure, and more reliable programming language with a broad application.
🌐
Security Journey
securityjourney.com › post › what-is-the-most-secure-coding-language
What Is the Most Secure Coding Language? Top Options in 2026
November 17, 2025 - The most secure programming languages (like Rust, Go, and modern Java) prevent entire classes of security vulnerabilities, such as buffer overflows and use-after-free exploits, before the code ever runs.
Top answer
1 of 8
124

If you use Java like most other programming languages, e.g. to write standalone applications, it is no less secure than other languages and more secure than C or C++ because of no buffer overflows etc.

But Java is regularly used as a plugin inside the web browser, e.g. similar to Flash. Because in this case the user runs untrusted code without having explicitly installed it, the idea is to have the code run inside a limited sandbox, where it should not be able to somehow act against the system or the user (e.g. read local files and send them to the website, scan the local network etc). And this is where Java failed in the recent years, e.g. new bugs popped up sometimes on a daily basis which allowed escaping from the sandbox.

Also, sometimes bugs in the byte code interpreter or native libraries lead to buffer overflows and could compromise the system, but in this regard Flash is usually considered worse.

And as for the other languages being better: these usually can't even run as untrusted code inside a sandbox (exception is JavaScript and maybe Flash), so they would be even worse because there is no inherent way to limit their interaction with the system.

2 of 8
83

The security vulnerabilites reported are not about Java (the programming language), which, by virtue of the JVM enforcing memory safety, is actually more robust than languages such as C or C++, where buffer overflows and buffer over-reads remain a threat, and can result in messes like Heartbleed.

Instead, the vulnerabilites reported are in the Java Sandbox, which attempts to enforce a priviledge model that permits safe execution of untrusted code, and is most famously used to permit the automatic execution of Java Applets in a browser. That sandbox is riddled with holes. Also, Oracle releases patches (the "critical patch updates") only 4 times a year. Needless to say to browser vendors are not happy about this. Firefox, for instance, is requiring user authorisation to launch a Java Applet since Firefox 26.

The reason the press reports do not make that distinction is that Oracle uses the "Java" trademark both for the programming language, and the browser plugin that runs applets. In fact, if an ordinary user encounters the Java trademark, it probably refers to the latter.

It is somewhat speculative why exactly the Sandbox remains vulnerable. If you ask me, one reason is that the same API is used both with and without the Sandbox, and most Java code runs without the Sandbox (because the code is trusted). As a result, it is quite possible for a developer to forget about that obscure feature when changing the Java API or its implementation, accidentally exposing things that should be protected (to illustrate how easy that is, behold the lengthy Secure Coding Guidelines for Java SE). Another but related reason is the sheer size of the Java API (5800 classes, and nearly 50,000 methods, for Java SE 6).

🌐
Sololearn
sololearn.com › en › Discuss › 1003134 › why-java-is-more-secure-than-c-c-
Why java is more secure than c & c++ ? | Sololearn: Learn to code for FREE!
I don't think java is very secure. Take a look at the list of security issues: https://www.oracle.com/technetwork/topics/security/alerts-086861.html ... Java - Automatic garbage collection. C++ - Manual memory management. I don't have 2 more points...
🌐
Coursera
coursera.org › coursera articles › computer science and engineering › software development › java vs. c++ comparison: what are the differences in these programming languages?
Java vs. C++ Comparison: What Are the Differences in These Programming Languages? | Coursera
September 10, 2025 - Lack of security: Experts say C++ isn’t as secure as other languages like Java. C++ has what experts refer to as “memory unsafety,” which refers to vulnerabilities in the memory codes. Many developers don’t consider security when they’re selecting a programming language, but it has become more prevalent as cyber threats evolve.
🌐
Mend
mend.io › most secure programming languages
The Most Secure Programming Languages
July 26, 2024 - Java shares Python’s top four CWEs: Deserialization issues (CWE-502) is one vulnerability type that while not the most prominent, is unique to this language, and saw a rise in 2017. Deserialization issues don’t appear in PHP, Ruby or Python. Should researchers start looking for Deserialization issues in those languages too, or is serialization inherently more secure ...
Top answer
1 of 3
5

First, the security issues are more a question of the implementation, rather than the language. Java does impose some security checks (bounds checking, etc.) that are optional (and very expensive in runtime) in C++. With regards to your specific issues:

  1. I presume this refers to the classical buffer overrun issue, which often was a problem in C. In C++, we use std::vector, which can (and usually does, at least when the correct compiler options are given) do the same checks as Java. If, on the other hand, it does refer to stack overflow (e.g. as a result of too deep recursion), then because the stack of the JVM is not the machine stack, Java can do extra checks, and also guarantee an out of memory exception in the case of stack overflow. (This is also possible in C++, but I don't know of a compiler which does it. And the operating systems don't always make it that easy.)

  2. This is an OS issue, not a language issue. Modern OS's doesn't allow programs to access memory outside their own process space, so neither Java nor C++ allow it.

  3. As above, this is an OS issue, not a language issue, and modern OS's enforce it relatively well, regardless of whether the program is written in Java or in C++.

In summary, both 2 and 3 are impossible, regardless of the language, and 1 won't occur in well written C++ (although it was a problem in the past with C).

2 of 3
5

Java is a reasonably secure language because of a few reasons, focusing mostly on your 3 points, Java is more secure than other languages, predominantly because it executes bytecode instructions in its own virtual machine, not native code. It does not allow out of bounds array access, and has no pointer access. This pretty much answers your first 2 points. As for reading and writing without permission I am not sure what you mean by that. Inherently file reading and writing is controlled at an operating system level. Without some exploit to gain more permission than it should, no matter what language it is written in, a program cannot write or read to files the OS prohibits it from. If you mean without permission from an application standpoint, from say a plugin system, then you would need to look into adding a security manager or your own vetting to prevent plugins or modules from altering files under your applications process.

🌐
Quora
quora.com › How-is-Java-more-secure-than-other-languages
How is Java more secure than other languages? - Quora
Answer (1 of 11): Bytecode is the key that makes Java language most secure and Portable. When you compile your java program then on successful compilation , java compiler (javac) generates a class file with .class extension which contains the ...