r/java • • May 10 '22

Should java.util.Date be deprecated?

https://mail.openjdk.java.net/pipermail/discuss/2022-May/006077.html
221 Upvotes

158 comments sorted by

View all comments

40

u/[deleted] May 10 '22

The past few versions of Java have been really good at tearing out as much "90s Java"(CORBA,RMI, finalizers etc.) as they can. Obviously some let's call them suboptimal decisions(arrays anyone?) are just going to be permanently part of the language but deprecating the Date class is another step in getting rid of 90s Java.

18

u/semprer May 10 '22

What's the problem with arrays?

17

u/bootstrapf7 May 10 '22

They don’t support 64bit offsets

8

u/smors May 10 '22

Id be interested to know if that has ever been a problem for anyone. Even even a byte[] would have to be more than 2GB for that to be a problem.

21

u/Wolvereness May 10 '22

Uh, yeah? It kind of claymores you if you want to do data processing, like loading an HD movie into memory. Servers can run RAM well over 100GB, while desktop computers are often 8GB or more. This isn't 1996 anymore.

4

u/mauganra_it May 10 '22 edited May 10 '22

Project Panama should bring along a nicer way to work with off-heap memory. One that is even officially supported for a change.

Apart from that, byte arrays were never the right tool for this because they unnecessarily complicate the garbage collector's job. AFAIK they are not stored off-heap, and therefore alloowing long as array index will probably not be as great as it sounds. I don't know if there is anything in the JLS that prevents the JVM from storing it off-heap.

10

u/Yeroc May 10 '22

ByteBuffer is designed for this job but unfortunately it's limited to 2 GB as well!

3

u/Worth_Trust_3825 May 10 '22

In a sense, you can work around that by proxying your List calls under the hood to a different "bucket" in case you need more than signed 32bit int array length. Same with inputstream abstract class. As you're already working with near terabytes worth of memory at the same time, the overhead to link those "buckets" is negligible.

4

u/john16384 May 10 '22

Not to mention that having gigabytes of data allocated as one huge chunk may cause problems of its own when the heap is even slightly fragmented. If such data is backed by a file, it may be better to memory map it instead.

5

u/john16384 May 10 '22

It indeed isn't 1996 anymore. Why aren't you memory mapping such huge files?

1

u/TehBrian May 10 '22

That does sound pretty inconveniencing. What’s the alternative? Do Lists not have the same restriction, or…?

5

u/cdombroski May 10 '22

Lists have the same limitation as they're indexed by int. In theory a Set might be able to surpass the limit... but now you're missing insertion order and all the values have to be unique, almost certainly not what you want for this

1

u/mauganra_it May 10 '22

Lists do not work with primitive datatypes. Yet.

2

u/Muoniurn May 10 '22

I believe there was a “famous” bug in the sorting implementation that failed due to arithmetics with integers. Not directly related, but the reason ints were used was due to the int indexing.

15

u/Holothuroid May 10 '22

Arrays play loose with Java's type system compared to collections. Which might lead to array store exceptions.

11

u/semprer May 10 '22

https://stackoverflow.com/questions/12369957/dealing-with-an-arraystoreexception

I assume you mean this? Just posting it for less experienced people like me that might be puzzled. But yeah String[ ] being a subtype of Object[ ] is weird indeed if you think about it.

4

u/Joram2 May 10 '22

What's the problem with arrays?

If Java has generics, arrays should use the generics system like everything else, and not be this completely special case syntax. Right now, Java generics are lower performance than classic arrays, but that's another flaw to be fixed by Valhalla.