• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Strcuture in Java?

 
Greenhorn
Posts: 4
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
is there any data type in Java similar to Structure in VB.NET?
Or defining a class is the only option? Please help....
Thanks.


Regards,
Saurabh
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you'll have to define a class.
 
Ranch Hand
Posts: 110
Google Web Toolkit Java Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can define a class inside another, or inside a method to create something like this. You can use enums too, i believe they(classes/enum/inner classes) have the same semanthic/power/flexibility as a structure since they're his sons. :P
 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jayr Motta wrote: . . . enums too, i believe they have the same semantic/power/flexibility as a structure since they're his sons. :P

An enum as the son of a structure? Please explain; that looks very peculiar to me.
 
Jayr Motta
Ranch Hand
Posts: 110
Google Web Toolkit Java Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Campbell,

Let me explain while i tell you a history, ok?

Once upon i time developers figured out that they need a way to make data structures to use lot's of times without boiler plate and to improve maintainability, etc. So they build struct (i know this since C), a simple way to put lots of data of lots of types inside a single structure. Once one of those developers was eating chocolate cake and he had a vision, that all cars have a single model but they all share lots of common characteristics of cars and he decide to do this in his code, implementing some kind of inheritance, From there classes born, now we can play god and create new objects and etc. Years a go the son of this same developer reads a code of his dad and think that's so inapropriate and badly written, lots of constants spread for the whole systems and they have no structure. So he think that he could use this nature of classes/structure combined with an elegant way to write constants and build the enum, they can have lots of constants and each of them can have constructors and methods and variables, etc.

Happy history huh? It doesn't finished yet .. there is a lot to happen .. but i really think that would clear you doubt/whatever you have.

Feel free to ask for more advices or tips or histories .. i'll be pleased to help SHERIFF!
 
Stephan van Hulst
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wow, and I *bet* you were the son of the guy who invented classes? Weren't you?

Come on, tell us!
 
Jayr Motta
Ranch Hand
Posts: 110
Google Web Toolkit Java Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nopz, i'm not .. not that i don't want to .. but you're missing the point notepad boy :P
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you have convinced me; I ought to move that post to this forum The bit about chocolate cake gives it away; no real programmer eats cake while working. They only drink coffee and more coffee and yet more coffee. That is why all code is written on keyboards; our hands are too shaky to write with a pen

The structs found in C predated Visual Basic by nearly 20 years. They are completely different, because structs are designed to contain variables, as opposed to constants. That isn't the origin of inheritance, because object-orientation was invented about 5 years before C.
The enum in Java™ is developed from the enumerated type in languages like C, C++ and Eiffel, but (from what I remember from the Java5 tutorials) Java™ enum members are full-blown object, not like enum members in other languages which are simply glorified integers. They have withdrawn that spectacular sentence from the Java6 version of the tutorials.

So classes are much better than structs and Java™ enums are better than C enums.
 
Jayr Motta
Ranch Hand
Posts: 110
Google Web Toolkit Java Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll accept your appologies sheriff, and you're right about what you've mentioned .. but you're gonna deny that they have a parenthood?
 
Attractive, successful people love this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic