Results 1 to 11 of 11

Thread: Structures?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Structures?

    Does anyone know off-hand if java allows the creation UDT's or structures similar to what Visual Basic 6 or Vb.Net has now? Im going to say no because ive never seen a structure declared in java code but maybe someone else has.

  2. #2
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    I would say No too...

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Well, this is a timely thread!

    I just started looking into the feasibility of writing a Java socket applet to send structured messages from a web page to C programs running on our Himalaya Non-stop servers. I have done some VB sockets apps that send UDTs to the same type of C programs with no problems, so I know that it is possible to create UDTs that are structurally identical to a C struct.

    With limited JavaScript experience and no Java experience, I picked up a copy of Learning Java from O'Reilly. On page 88, it reads "In C, you can make a new, complex data type by creating a struct. In Java (and other object-oriented languages), you instead create a class that defines a new type in the language.".

    Does this mean that a class that contains only variables would be identical to a UDT or struct? If I am off base, now would be the time to let me know, before I get too far down the wrong path.

  4. #4
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    That rules out the possibility of structures in Java.

    UDT can be called pseudo-classes, i.e. very similar to classes but not exactly classes. If Java advises you to use classes in place of UDTs, then it does not support structures.

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  5. #5
    Addicted Member Mrs Kensington's Avatar
    Join Date
    Sep 2001
    Location
    Dorset, UK
    Posts
    144
    to ccoder...

    I don't know whether a class with just variables is the same as a UDT. I don't believe it would (but i'm not sure and can't logically argue it at the mo).

    But i have an idea how to get it to work... but it is v complex.
    You could get your vb app to send a java app your UDT using sockets and then look at the data with a byte output stream. Try sending different UDT's with different amounts of variables in to see if you can work out the layout your UDT would have to take.

    You could then try and recreate it in Java. Perhaps try doing the same but sending objects from a java program to a java program and analysing that in a byte input stream.

    It is pretty complex tho, and would require a lot of work, but i believe you could fool the C program into thinking that the bytes you are sending is really a UDT.

    Good Luck

    Mrs Kensington
    Ford? Theres an infinite number of monkeys outside that want to talk to you about a script of hamlet they've produced!

  6. #6

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Well lets first define what the main difference is between a class(which is a refrence type) and a structure(which is a value type) is. For instance an integer or byte has a fixed number of bytes regardless of the actual value held by the variable. So these are normally stored on the stack. For refrence types such as vectors
    memeory is allocated dynamically so they are commonly stored on the heap.


    As i understand it, the main reason for this seperation is that when a process needs to retrieve a variable it has to search the stack, looking for the variable specified. Now even with complex algorithms the search might take a long perod of time if the stack included large dynamic items such as collections and sets. So a refrence(or pointer) is just stored in a memory address that resides on the stack which points to where the dynamic type resides on the heap.

  7. #7

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Posted by ccoder
    Does this mean that a class that contains only variables would be identical to a UDT or struct?
    I would have to say no.

  8. #8
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    Originally posted by Dilenger4

    I would have to say no.
    I suspected as much. Nothing's ever that easy!

    It looks like I started some good dialog though. It should get me pointed in the right direction. I have been kind of thinking that I may have to 'string' my values into some sort of contiguous memory, like a byte array or a byte stream (if it is different) as Mrs Kensington mentioned.

    Well, back to the books. I have a lot to learn.

  9. #9

  10. #10
    Hyperactive Member CaptainPinko's Avatar
    Join Date
    Jan 2001
    Location
    London, Ontario, Canada
    Posts
    332
    easily, just create a class with every data member beign public and don't give it any methods and there you go

    if someone can think of ANY differences then please do tell, hell if you wanted to you could overide all your inherited public methods with private ones couldn't you?
    "There are only two things that are infinite. The universe and human stupidity... and the universe I'm not sure about." - Einstein

    If you are programming in Java use www.NetBeans.org

  11. #11

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    posted by CaptainPinko
    easily, just create a class with every data member beign public and don't give it any methods and there you go
    That wouldn't do. The class would still be stored on the heap not the stack as UDT's or structures are. For instance take following block of VB.Net code.
    Code:
    'use a decimal refrence type
    
    Dim total as DecimalRef = New DecimalRef()
    Dim subtotal as DecimalRef = New DecimalRef()
    
    'calculate the subtotal
    'set the total equal to subtotal and apply tax and shipping 
    
    total = subtotal 
    total = total + tax + shipping
    'Oops
    ' we just applied tax and shipping to subtotal as well
    The only way around this would be to declare total and subtotal as a value type or the following
    Code:
    total = subtotal.Clone()
    total = tax + shipping

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width