473,785 Members | 2,714 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 25915
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******@hotma il.com> wrote in message news:<3f******* *************** *@news.xs4all.n l>...
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*******@yaho o.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
3471
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 "proves" something) to consider the next time the "Python makes developers more productive" thread starts up again. Background ========== An employee who left our company had written a log processor we use to read records from text files (1...
18
30272
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
1642
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 in C# will be the same - i was wrong.... or if in C# is the same as in java please tell me ;-) I have an ArrayList names ls : // Point is a class System.Draw....
61
3782
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 (myBranch + x) = new Branch(i); // it doesn't x is a loop iterator, i is an int for the constructor to define an array. What am I doing wrong here.
11
2642
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. This works without any problems. I now would like to filter "duplicate" records. They aren't really duplicate, I can't just qsort as is and eliminate the matching rows. I have number of fields that will be the same, but some of the fields will...
19
2558
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 functions for manipulating a Date. However, it does not specify that those functions should be the only ones to depend directly on Date ’s representation and the only ones to directly access objects of class Date . This restriction can be...
4
7973
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
2353
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 move on two either Java or C++, but I'm not sure which. Which one do you think is a softer transition for a Python programmer? Which one do you think will educate me the best?
0
9643
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10319
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10147
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10087
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9947
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6737
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5380
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2877
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.