Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Data Structures Exploring the Java Collection Framework Meet the JCF

Lukasz Walczak
Lukasz Walczak
6,620 Points

JCF vs DataBase...

Do we store ArrayLists, HashTrees etc. in the databases? Or are they just like temporary (in-memory) database?

Or do we just store the bits and than ask (query) the database to show us the data base on the query?

Thanks in advance

1 Answer

The JCF has nothing to do with databases. HashSet, ArrayList etc. are data structures, not databases. They exist only at runtime. They exist to organize data, not to store it. There is no persistence happening (when the program ends, the data is gone).

Databases are there to persist data (to store it). Databases speak their own language (for example SQL), and have their own structure (tables and rows).

When a Java app works with a database, the Java app needs to send queries to the database in a language the database can understand. When the database sends data back, the Java app needs to translate the rows back into Java objects. There is a specification on how to deal with this called the Java Persistence API (JPA). There are a lot of tools you can use that help with this.

Here on Treehouse you can learn about one of those tools called Hibernate in this course: https://teamtreehouse.com/library/hibernate-basics I recommend taking it if the topic interests you. But there are many other tools out there that take different approaches. For example jOOQ is pretty interesting, but it requires you to have a better understanding of SQL than an ORM like Hibernate.

Lukasz Walczak
Lukasz Walczak
6,620 Points

Great answer! Much obliged! Have a fantastic day!