Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Diego

[java] A couple general Java questions

This topic is 6174 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m somewhat new to Java but I''m trying to put together a fairly basic game. First off, is there any equivalent to structures in Java? (or is that a complete no-no in OOP?) Also, what exactly is an interface? I tried to read up on it in the Java docs but the explanation gets a bit complicated. Thanks -Diego "What is wrong with the world today, the government, the media, or your family?"~Papa Roach

Share this post


Link to post
Share on other sites
Advertisement
I don''t think java has anything like structures.
Use classes instead.

As for the interface:
interfaces are almost the same thing as abstract classes. You often use interfaces instead of abstract classes when the classes implementing the interface (deriving the abstract class) don''t have any implementation to inherit (variables etc).

Hope that clarifies.


/Mankind gave birth to God.

Share this post


Link to post
Share on other sites
Hi,

I try to answer to your questions somehow:

I would "translate" structures as classes. Structure contains usually just data - that you can do with a class. Class can offer you also means to manage the data (functions or methods).

Interface (abstract idea of it):
Imagine that you have lots of code (classes) implementing e.g. IP communication. To your actual application this would look like a mess (lots of classes, one handling the sockets, one handling socket listening, some class for threads, etc.). With an interface you can hide the mess from the other parts of your application.
In interface (class) you define ALL high-level methods + variables which are needed for the IP activity. Inside the interface class methods you call further the other classes (in the mess) as needed. This way you could modularize your code into modules with clear interfaces, thus allowing modules being developed separately (you can change the module contents/classes almost as much as you want as the interface hides them from the rest of the code).

Interface in java means that you declare certain variables and methods into a class. When you create a new class which "implements" the interface class, all definitions from the interface class are "added" into the new class. In addition you need to implement (in the new class) the declared methods found from the interface class...
This way you could also create an interface class containing all enums/definitions you need to "include" into all other classes in your application - similar to e.g. #include "constant.h" being added to all classes in C/C++.

Cheers,
Spec

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
There isn''t an exact equivalent of structures, as classes will have vtables.

Share this post


Link to post
Share on other sites
Thanks guys, that cleared things up. I''m in the middle of taking a class here at school, and hopefully they will cover interfaces and abstract classes as that seems to be a real key piece of Java.

-Diego
"What is wrong with the world today, the government, the media, or your family?"~Papa Roach

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
in C++, structs are exactly the same as classes, except that the default visibility is public in structs, and private in classes

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!