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. :confused:
Printable View
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. :confused:
I would say No too...
.
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. ;)
That rules out the possibility of structures in Java. :o
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.
.
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
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.
I would have to say no. :pQuote:
Posted by ccoder
Does this mean that a class that contains only variables would be identical to a UDT or struct?
I suspected as much.:( Nothing's ever that easy!Quote:
Originally posted by Dilenger4
I would have to say no. :p
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.
You got that right. :pQuote:
Posted by ccoder
I suspected as much. Nothing's ever that easy!
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?
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.Quote:
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
The only way around this would be to declare total and subtotal as a value type or the followingCode:'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
Code:total = subtotal.Clone()
total = tax + shipping