473,434 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

Structs / Records 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

Jul 17 '05 #1
8 25889
Rick 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?


Java does not support structs and records. Use classes instead.

--
Jonas Kongslund
Jul 17 '05 #2
Ok, thats clear. Thanks!

Rick
Jul 17 '05 #3


While it was 3/11/03 10:10 am throughout the UK, Jonas Kongslund
sprinkled little black dots on a white screen, and they fell thus:

<snip>
Java does not support structs and records.

<snip>

Yes it does. It just calls them classes, and greatly expands upon their
functionality.

Even in C++, a struct _is_ a class. There, the struct keyword just
serves for backward compatibility and/or syntactic sugar depending on
your point of view.

Stewart.

--
My e-mail is valid but not my primary mailbox. Please keep replies on
on the 'group where everyone may benefit.

Jul 17 '05 #4
"Rick" <as******@hotmail.com> wrote in message news:<3f***********************@news.xs4all.nl>...
Ok, thats clear. Thanks!

Rick


hey
structs in C++ are just classes with default access specifier as
public (otherwise there is no differnec in class in C++ & a struct in
C++)
thus if you need to store only data, java does not force you to have
methods in class
for eg-: while creating data structures you can create class for Node
class Node
{
int data;
Node next;
}
this is equivalent to structs .... isnt it ?

regards
amey
Jul 17 '05 #5
Amey Samant wrote:
class Node
{
int data;
Node next;
}
this is equivalent to structs .... isnt it ?


Nope... default access for instance variables is protected, not public.
Should be:

class Node
{
public int data;
public Node next;
}

/<en

Jul 17 '05 #6
I'm not 100 % sure but I don't think you may say a struct is the same as a
class. Of course, they both can be used for storing data. Classes are some
sort of advanced struct types, based on structs (since OOP languages like
Java and C++ languages came after non-object-orientated languages like C
which already had structs that time). So, they won't differ that much but
it's the same as :
"A lion is a beast but a beast is not a lion." (what a stupid example :| ).

It doesn't matter really much, I can live with the Java classes, but I was
just curious. Or maybe I was lazy because using structs if a little bit
simpler because you don't have to create them like classes.

Greetings,
Rick
Jul 17 '05 #7
Stewart Gordon <sm*******@yahoo.com> wrote in message news:<bo**********@sun-cc204.lut.ac.uk>...

hi stewart
Even in C++, a struct _is_ a class.
There, the struct keyword just
serves for backward compatibility and/or syntactic sugar depending on
your point of view.


no structs in C++ are different than class (the only difference is in
class by default access specifier is private whereas in structs it is
public)
otherwise they are same
regards
amey
Jul 17 '05 #8


While it was 4/11/03 10:01 am throughout the UK, Amey Samant sprinkled
little black dots on a white screen, and they fell thus:

<snip>
no structs in C++ are different than class (the only difference is in
class by default access specifier is private whereas in structs it is
public)

<snip>

I didn't say that the C++ keywords 'struct' and 'class' were synonyms.
I merely meant that by defining a struct, you are defining a class, and
it just saves having to put public: at the top.

Although it isn't enforced by the language, it remains common practice
(IINM) to use 'struct' for C-style structs, and 'class' when you want to
use the functionality of a class.

Basically,

struct Qwert {

means exactly the same as

class Qwert {
public:

and would compile to precisely the same.

Stewart.

--
My e-mail is valid but not my primary mailbox. Please keep replies on
on the 'group where everyone may benefit.
Jul 17 '05 #9

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

Similar topics

2
by: Dave Brueck | last post by:
Below is some information I collected from a *small* project in which I wrote a Python version of a Java application. I share this info only as a data point (rather than trying to say this data...
18
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
19
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
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...
11
by: Cliff Martin | last post by:
Hi, I am reading a fairly large file a line at a time, doing some processing, and filtering out bits of the line. I am storing the interesting information in a struct and then printing it out....
19
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
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
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.