Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Advantage of classes in Java

 
Krishnaveni Hanuman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
Linux Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic