Structs in Java

Discussion in 'C Programming' started by Rick, Nov 3, 2003.

  1. Rick

    Rick Guest


    We all know that Java has classes but how about basic storage objects like
    structs? C and C++ have Structs, Pascal has Records, Visual Basic has Types
    etc. How about Java?

    Rick, Nov 3, 2003
    1. Advertisements

  2. Rick

    Rick Guest

    Sorry, posted in the wrong newsgroup per accident! Should be in the Java.

    Rick, Nov 3, 2003
    1. Advertisements

  3. Ask in
    Better yet, find the FAQ of
    Christian Bau, Nov 3, 2003
  4. No, don't. is an obsolete newsgroup. Use
    Joona I Palaste, Nov 3, 2003
  5. Rick

    Rick Guest

    Ok, I asked it a Java newsgroup. They told me something which made me doubt
    so I was thinking, the C guys here will probably know the absolute answer.
    Java didn't had structs, ok. But everyone on that newsgroup also said that
    Classes are just the same as structs... Call me Joe but this ain't 100%
    right is it? A class is probably for a huge part based on the good old
    struct but vice, versa, a struct ain't a class. Am I right?

    Sorry if this is off-topic.
    Rick, Nov 4, 2003
  6. You're right structs and classes are not the same thing. A Java class
    consisting only of fields, but not methods, can be seen as a C-style
    struct, but C structs don't have all the functionality Java classes can,
    for example polymorphism.
    Joona I Palaste, Nov 4, 2003
  7. Rick

    Chris Torek Guest

    In C, "class" is just an ordinary identifier:

    char *class = "1981";

    so this is indeed enormously different from "struct".

    There is another language that looks about as much like C as Java
    does that *does* have a "class" keyword, and in this other language,
    "struct" just means "class { public:". But the people who like to
    talk about this other language meet over in comp.lang.c++; there,
    you can get a much better answer about the similarities and
    differences between "class" and "struct".
    Chris Torek, Nov 4, 2003
  8. I believe that Java is somewhat more C like than C++ is. My guess is that
    C++ tried to be different from C, and Java intentionally tried to be more
    like C when it was possible. I especially don't like the << and >>
    operators in C++.

    -- glen
    Glen Herrmannsfeldt, Nov 4, 2003
  9. Rick

    DBTID Guest

    And you didn't post this in because ... ???
    DBTID, Nov 5, 2003
  10. Well, for one thing, because it's an obsolete newsgroup.
    Now, Rick didn't post this in because... ???
    Joona I Palaste, Nov 5, 2003
  11. Rick

    Rick Guest

    Damn it, the only thing I read on this newsgroup is
    "this is off-topic"
    "post it somewhere else"
    "you're stupid"
    "I'm a better programmer than you"

    Yeah yeah, I know there's lots of posting here and if everyone just postes
    what he wants it gets a huge mess. True! But come on, it's as if everyone
    first reads the messages to detect some word to bitch on. If it depends on
    some of you I can post my stuff nowhere because none of the 10 million
    newsgroups is exactly suitable. Stop that, don't be such nerds and stop
    saying to others that they are stupid because they missed one pointer or
    whatever. Helping each other is ment to be fun, but on this particular
    newsgroup most of the C gurus here seem to be grumphy all day?! If you don't
    really like to help, than don't.

    I posted that on the 'obsolete' java newsgroup indeed. So what? Noone cares
    there, I got helped, we had a little discussion about structs and shit and
    it was fun. Next time I help one of them. I use lot's of newsgroups and of
    course I just don't post anything but this is ridiculous. I've always been
    helped friendly everywhere except here. In almost every post someone is
    bitching (and not only my own posts). And then it get's repeated 100 times.
    Well wiseguys, that's even more off-topic in my eyes. Their are nicer ways
    to tell someone is wrong. Here I often get the feeling that the elite C
    gurus are laughing at the rookies and are trying to 'bully' them away with
    silent hints. Come on man, help the poor guys. Here I'm a total newbie in C
    comparing to most others. But on some other newsgroup I obviously know more
    than the average user. Instead of calling them stupid I always love to help
    them, no matter what their question is, damn it's almost as in doctor Phill.
    So what if it's a little bit off-topic? The world is larger then C right?

    Ok, I said my word. Nevertheless, I appreciete all the help. And by the way,
    I'm not picking specificly on you Joona, it's just my overall impression
    about this newsgroup. Let's say a friendlier athmosphere would be good for
    this group. Make love, not war.

    Have a nice day,
    Rick, Nov 6, 2003
  12. We say this.
    And we say this.
    But we don't say this.
    And we don't say this either.
    You seem to be in need of a sever attitude readjustement. We don't
    think we're better programmers, or better people, because we only
    discuss standard C. It's simply what this newsgroup is all about.
    Do you yourself think comp.lang.c is for discussing Java? Which part
    of "comp.lang.c" mentions Java anywhere?
    If you still think we said we're better programmers than you, or that
    you are stupid, please point out the exact place we've said that.

    (Rest snipped)
    Joona I Palaste, Nov 6, 2003
  13. Rick

    Rick Guest


    Well, the examples are not directly said. I'm not a genious reader but just
    from reading lot's of messages here I notice it. I never noticed it in
    newsgroup before so I'm not talking crazy crap. Of course they don't say it
    like "case: I am > you;" and I'm not saying you're doing that as well. But
    there certainly are some examples. I'm not going to copy paste or throw
    names but
    here's a simulation:

    "Hi, my name is Timmy, I'm 7 years old and I'm new to C. I need to program
    a rocket defense system. It's almost done but now I'm stuck with <blabla>
    here's a code snippet : ...>"
    Most answers are seriously trying to help the poor kid but often I also see
    reactions like these :
    "It's really obvious, what do you think?!"
    // Damn, if I knew it I wouldn't post it wiseguy!
    "Sigh, here we go again, post it at rocket.lang.c"
    // I really readed that 'sigh' stuff before (not your reaction)! Don't
    do that!
    "That's what seperates the REAL programmers from the amateurs..."
    // Yeah yeah, so you must be mister Miyagi at C? (context reading)
    "Using function xyz is not too smart!" and then it get repeated 10 times
    // ok, thanks for pointing but I knew it after this is already the sixth
    time somebody said it

    There's nothing wrong with the sentences on it self but among with the
    I detect some...cockyness(shit, I don't know the right englisch words :[,
    englisch is not
    my native language (neither is C)). As I said, there are nicer ways to help.

    Another example, when I posted my first thing I was using C for 2 weeks. So,
    no wonder
    that I have some dumb questions then, pointers and stuff are not easy if
    used to do Delphi or something! Anyway, I placed a simple question and then
    I get
    a dozen of answers. Most of them are good but there are also a few people
    who had
    to add that I should know this and are explaining the problem in Techno
    Then there's also some wiseguy who tries to prove I didn't copy paste my
    snippet from the internet. Who cares?! Does it really matter if it's copy
    or not? I typed it over so there was a tiny error inside. That's no big deal
    the guy keeps pooping ( "did not!", "did too!" etc. etc. "STOP!" ).

    Hey, and here some copy pastes! :
    "A random Google sample shows him to be a thoughtless, boorish troll,
    attempts to elevate repetition into a virtue, and who clearly doesn't
    understand C. Sorry, but I don't share your apparent "admiration" for
    // don't know exactly where it's all about, maybe the guy is right but
    man, please let the
    // "and who clearly doesn't understand C" away

    Here's something about the repeating, a 'newbie' asked something and get's
    as a first (friendly) answer he'd be better off in another newsgroup. But
    then some other dude feels he just had to post it again, right after the
    previous answer.
    "again, as you were told, you will have much better help in a
    MS Windows newsgroup or a newsgroup about your compiler."
    // And this was the only stuff in the post so it didn't add much. If you
    care about heavy
    // internet traffic then messages like this shouldn't be placed again
    and again.

    Or take a look at the "ANSI C compliance" post. It was a bit off topic so
    here we go again, a dozen of 'angry' men picking at each other. Really cozy
    newsgroup this is.

    Some of you are reading the posts too precisely. If there's a wrong
    because I spelled my name wrong or the post isn't 100% alt.lang.c, 1 or 2
    are feeling they need to start about it. And not one post, nononoo, it often
    get's repeated as if the other guy has a IQ of <32. Enough examples, and
    I'm a little bit whining myself but the point is, posting something here is
    fun, especially when you are a newbie. I sure can take critic, I'm happy if
    is trying to help me out. But here you'll have to watch on every digit you
    One wrong thing and there's an army of nerds yelling! How the heck was I
    to know that xyz<>abc! On other newsgroups I can post 'whatever' I want and
    they keep friendly. And if it's a little bit off-topic, no problemo, a
    little variation can be fun as well.

    Of course I know there are boundaries, I won't post pictures of my naked but
    and grandpa's stories
    about WO1 here but please don't pick out every wrong detail or 'misplaced'
    post. It's ruining
    the mood in my opinion. Maybe I'm spoiled and I shouldn't complain but I
    just have seen much
    nicer newsgroups than this one. Too bad, because I know there are talented C
    people hanging
    around here. I hope it's a little bit clear now.

    Rick, Nov 7, 2003
  14. At least some of the repetition is caused by the fact that this is an
    asynchronous medium. It takes time for articles to propagate.
    Someone asks a question with a more or less obvious answer. Multiple
    people reply before seeing that everyone else is doing it. (And I,
    for one, have a big enough ego that I'm not always willing to sit back
    and wait for someone else's answer, especially if I think I have some
    insight that someone else might miss.)

    Another factor is a general unwillingless to let misinformation,
    deliberate or otherwise, go unanswered.

    As for the copy-and-paste issue, a lot of the questions asked here are
    about subtle errors in source code. We take a look at the posted code
    and find errors in it; how are we supposed to know whether those
    errors are in your original code or were introduced when you re-typed

    For example, if you post something like

    if (x = 0) {
    printf("x is zero\n");

    and ask why x is never zero, I'll tell you that it's because you used
    "=" instead of "==". If you reply that of course you had "==" in your
    original program, you just mis-typed it, I'll remind you to
    cut-and-paste the exact code next time so we can tell you what the
    real problem is.

    Cut-and-paste is easier than re-typing anyway.

    The dynamics of this newsgroup are such that it's easy to keep a
    discussion going, but very difficult to stop one. There are oodles of
    regular readers, and dozens who post regularly. Stopping a discussion
    requires all of them to agree to stop posting about it. It does
    happen sometimes, but probably not as often as it should. Threaded
    newsreaders help.

    Rick, I'm not saying you don't have some valid points, I'm just trying
    to help you understand why things are the way they are.
    Keith Thompson, Nov 7, 2003
  15. You can have methodless (except for the constructor) classes. There is a
    difference, though, between Java and C++ in this case. If you reference a
    class from inside another class you get Object reference variables:

    class Point {
    int x,y;

    class Line {
    Point one, two;

    A C struct, or, as I understand, C++ class, will allocate memory for two
    Point's in a line. Java will allocate two Point reference variables. The
    Point objects will have to be created separately.

    -- glen
    Glen Herrmannsfeldt, Nov 7, 2003
  16. Rick

    Rick Guest

    I feel much better already :) Let's contineu C.

    Rick, Nov 10, 2003
  17. Rick

    Nudge Guest

    Once you realize your mistake, you can cancel a post, you know...
    Nudge, Nov 10, 2003
  18. You can try. Many servers don't recognize cancels.
    Keith Thompson, Nov 10, 2003
  19. Rick

    nobody Guest

    Do you mean that some *do* ?
    nobody, Nov 11, 2003
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.