DEV Community

Discussion on: Java interview prep: 15 Java interview questions

Collapse
 
aminmansuri profile image
hidden_dude • Edited

Q14: memory usage

A big one in web applications is to prefer streaming over storing everything in RAM.

For example:

str = readEntireFileIntoString()

vs

outputStream.write(readAnotherLine())

Huge huge differences in RAM usage (O(N) vs O(1) ). Streaming is by far preferable.

In XML for example, SAX parsers are far preferable over DOM parsers because the later store everything in RAM. If your file is huge you'll hog a lot of RAM.

Another source of horror is careless use of relations in Hibernate. If you're careless you can end up storing the entire database for each object and hogging the RAM like mad.

Collapse
 
aminmansuri profile image
hidden_dude

I mention these.. because sadly, I've seen them in the wild.