How exactly is a class responsible for security in Java?
I had a friend answer me as :
"In Java, all methods, variables are stored inside a class. So when you want to access those methods/variables, you cannot do that unless you have created an instance of that class.That makes Java secure."
Is the above answer correct? if yes, could someone explain it with much clarity? If not, please explain with a suitable example.
java is a secure language because of ByteCode. A bytecode is a just like as machine code, whenever we compile a source program in java, compiler creates a .class file this .class file is called as bytecode. Then with the help of this byte code java application runs the program .java doesn't provide acess to memory directly .Java doesn't allow direct access to memory like C/C++.
In this context security means security against daft things done by the programmer, not against malicious things done by other people.
If you look for encapsulation on Google or Wikipedia, you find that you want to mark all fields private (except for global constants) to maintain the integrity of an object.