473,507 Members | 3,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Structs in Java

Hi,

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?

Greetings,
Rick
Nov 13 '05 #1
18 30243
Sorry, posted in the wrong newsgroup per accident! Should be in the Java.
Sorry!

Rick
Nov 13 '05 #2
In article <3f***********************@news.xs4all.nl>,
"Rick" <as******@hotmail.com> wrote:
Hi,

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?


Ask in comp.lang.java.
Better yet, find the FAQ of comp.lang.java.
Nov 13 '05 #3
Christian Bau <ch***********@cbau.freeserve.co.uk> scribbled the following:
In article <3f***********************@news.xs4all.nl>,
"Rick" <as******@hotmail.com> wrote:
Hi,

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?
Ask in comp.lang.java.
Better yet, find the FAQ of comp.lang.java.


No, don't. comp.lang.java is an obsolete newsgroup. Use
comp.lang.java.programmer.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"To know me IS to love me."
- JIPsoft
Nov 13 '05 #4
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.
Greetings,
Rick
Nov 13 '05 #5
Rick <as******@hotmail.com> scribbled the following:
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?


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 Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"It sure is cool having money and chicks."
- Beavis and Butt-head
Nov 13 '05 #6
In article <3f***********************@news.xs4all.nl>
Rick <as******@hotmail.com> wrote:
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?


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".
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://67.40.109.61/torek/index.html (for the moment)
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 13 '05 #7

"Chris Torek" <no****@elf.eng.bsdi.com> wrote in message
news:bo**********@elf.eng.bsdi.com...
In article <3f***********************@news.xs4all.nl>
Rick <as******@hotmail.com> wrote:
(snip)
Java didn't had structs, ok. But everyone on that newsgroup also said thatClasses 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?


(snip) 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".


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
Nov 13 '05 #8
Rick <as******@hotmail.com> wrote:
Hi, 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? Greetings,
Rick


And you didn't post this in comp.lang.java because ... ???
Nov 13 '05 #9
DBTID <db***@nospam.dbtid.is-a-geek.org> scribbled the following:
Rick <as******@hotmail.com> wrote:
Hi, 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? Greetings,
Rick
And you didn't post this in comp.lang.java because ... ???


Well, for one thing, because it's an obsolete newsgroup.
Now, Rick didn't post this in comp.lang.java.programmer because... ???

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"O pointy birds, O pointy-pointy. Anoint my head, anointy-nointy."
- Dr. Michael Hfuhruhurr
Nov 13 '05 #10
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 13 '05 #11
Rick <as******@hotmail.com> scribbled the following:
Damn it, the only thing I read on this newsgroup is
"this is off-topic"
We say this.
"post it somewhere else"
And we say this.
"you're stupid"
But we don't say this.
"I'm a better programmer than you"
And we don't say this either.
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.


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 Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"This is a personnel commuter."
- Train driver in Scientific American
Nov 13 '05 #12
Hi,

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
another
newsgroup before so I'm not talking crazy crap. Of course they don't say it
directly
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
context
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
you're
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
Language.
Then there's also some wiseguy who tries to prove I didn't copy paste my
code
snippet from the internet. Who cares?! Does it really matter if it's copy
pasted
or not? I typed it over so there was a tiny error inside. That's no big deal
but
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,
who
attempts to elevate repetition into a virtue, and who clearly doesn't
understand C. Sorry, but I don't share your apparent "admiration" for
this
character."
// 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
character
because I spelled my name wrong or the post isn't 100% alt.lang.c, 1 or 2
guys
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
maybe
I'm a little bit whining myself but the point is, posting something here is
not
fun, especially when you are a newbie. I sure can take critic, I'm happy if
somebody
is trying to help me out. But here you'll have to watch on every digit you
type!
One wrong thing and there's an army of nerds yelling! How the heck was I
supposed
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.

Greetings,
Rick

Nov 13 '05 #13
"Rick" <as******@hotmail.com> writes:
[...]
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 you're 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 Language. Then there's also some wiseguy who tries to prove I
didn't copy paste my code snippet from the internet. Who cares?! Does
it really matter if it's copy pasted or not? I typed it over so there
was a tiny error inside. That's no big deal but the guy keeps pooping
( "did not!", "did too!" etc. etc. "STOP!" ).


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
it?

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 (The_Other_Keith) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #14

"Rick" <as******@hotmail.com> wrote in message
news:3f***********************@news.xs4all.nl...
Hi,

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?


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
Nov 13 '05 #15
I feel much better already :) Let's contineu C.

Greetings,
Rick
Nov 13 '05 #16
Rick wrote:
Sorry, posted in the wrong newsgroup per accident! Should be in the Java.


Once you realize your mistake, you can cancel a post, you know...

Nov 13 '05 #17
Nudge <de*****@kma.eu.org> writes:
Rick wrote:
Sorry, posted in the wrong newsgroup per accident! Should be in the Java.


Once you realize your mistake, you can cancel a post, you know...


You can try. Many servers don't recognize cancels.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
(Note new e-mail address)
Nov 13 '05 #18
"Keith Thompson" <ks***@mib.org> wrote in message
news:ks************@nuthaus.mib.org...
Nudge <de*****@kma.eu.org> writes:
Rick wrote:
Sorry, posted in the wrong newsgroup per accident! Should be in the
Java.
Once you realize your mistake, you can cancel a post, you know...


You can try. Many servers don't recognize cancels.

Do you mean that some *do* ?
Nov 13 '05 #19

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
25895
by: Rick | last post by:
Hi, 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? Greetings, Rick
5
2050
by: Grant Austin | last post by:
What would be the correct syntax for setting up a dynamic array of structs? Suppose you have a struct declared: struct relation { FILE * binFile; unsigned int numAttrs; struct attrList *...
10
1955
by: Patricia Van Hise | last post by:
Is it possible to access a field of a struct which is a field of another struct? Ex. struct subStr{ int num1; int num2; }; struct myStr { int num3; subStr *lock; };
289
1805
by: napi | last post by:
I think you would agree with me that a C compiler that directly produces Java Byte Code to be run on any JVM is something that is missing to software programmers so far. With such a tool one could...
19
1624
by: Xandau | last post by:
hello all, i wotk with java every day but last time i have interested in C#. everything goes great except one thing... in java everything is a reference (except plain types) so i thought that...
61
3690
by: Marty | last post by:
I am new to C# and to structs so this could be easy or just not possible. I have a struct defined called Branch If I use Branch myBranch = new Branch(i); // everything works If I use Branch...
19
2532
by: desktop | last post by:
There is a lot of info on this topic on google. But in Bjarne Stroustrup 's book page 225 he writes: "The declaration of Date in the previous subsection (declared as a struct) provides a set of...
4
7906
by: Jazi | last post by:
Hello All, I have a function in C++ that takes an array of struct. I want to convert this function to java using SWIG. Here what I have structs.h typedef struct myStruct{ char name;
29
2312
by: s0suk3 | last post by:
Hello, I was hoping to get some opinions on a subject. I've been programming Python for almost two years now. Recently I learned Perl, but frankly I'm not very comfortable with it. Now I want to...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7110
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7482
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.