File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Advantage of classes in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Advantage of classes in Java" Watch "Advantage of classes in Java" New topic
Author

Advantage of classes in Java

Krishnaveni Hanuman
Greenhorn

Joined: Feb 18, 2013
Posts: 10
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.


Thanks in advance,
Krishna Venu

Mack Wilmot
Ranch Hand

Joined: Jul 27, 2011
Posts: 88

The failure of your friends answer is the fact that you can have class members and they do not require an instance to access them -- you access them by class name, not an object variable.

Members marked "static" are class members.

Access Control Modifiers have more to do with security of class and object members. (public, protected, private, no modifier)
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
Hi Krishnaveni Hanuman,



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++.

Regards,
James
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40029
    
  28
Welcome to the Ranch

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Advantage of classes in Java