Skip to content

References and _using_ existing classes can be introduced earlier, to make programs more interesting #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hallvard opened this issue May 27, 2025 · 2 comments

Comments

@hallvard
Copy link

My experience as a lecturer is that students get bored if we focus too much on primitive types. Some of Java's build in classes can be introduced earlier, without having to explain how to declare them. This will require explaining the concept of references and state, which is complex, but pretty important to get a grip on early.

String can be used to some extent, but instances with mutable state are also needed. In Python-based courses, lists are introduced early, and my experience is that Java's lists are intuitive enough to come pretty early, and easier to explain than arrays.

@bowbahdoe
Copy link
Collaborator

So while I do agree the primitive section plods along - what specific examples do you have in mind?

Is it just ArrayList?

@hallvard
Copy link
Author

hallvard commented May 27, 2025

String, LocalDate and LocalDataTime are good examples of immutable objects. They have state, but no way of changing it. Although immutable objects are preferable in many cases, they are not necessarily easier to understand.

StringBuilder (mutable string, which is easier to work with than String for some purposes), (Array)List and (Hash)Map are generally useful, are easy and intuitive enough and illustrate state well. All have a nice (to)String representation, so it's easy to show how sequences of method calls change the state. Lists will be useful for loops, foreach with lists are easier to understand than index-based looping (without explaining in terms of iterators).

It's a bit problematic that the modern way of working with lists and maps often make use of immutable variants created with List.of and Map.of. I wouldn't introduce them, because you would need to explain what List and Map are, as opposed to ArrayList and HashMap, and that quickly becomes far to complex.

A lot about objects can be explained, before needing to explain how they are programmed with classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants