r/learnjava • • Feb 27 '22

How can I practice Java Generics, Collections Framework, File I/O, Streams and Multithreading

I'm currently reading Java Complete Reference and have been trying it's Example Codes but I'm not getting how can I use them in real world Programming or how can I practice above mentioned topics.

Are there any online resources or assignments that could help me to work more on these topics. I've tried using Online Coding Sites but I'm still finding it hard that how can I leverage these while writing Java Code.

42 Upvotes

9 comments sorted by

•

u/AutoModerator Feb 27 '22

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions

  • You include any and all error messages in full - best also formatted as code block

  • You ask clear questions

  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

14

u/[deleted] Feb 27 '22

So the problem with generics is that there are not the things one would use generally in any small application.

And Streams can be replaced by extra code, they just minimise the number of lines required and are honestly quite awesome once you understand where to use streams insted of lengthy code.

My current project requires me to have deep knowledge of both. So the only advice I can give is to work on a LARGE project.

5

u/Tanuj7250 Feb 27 '22

Is there any resources or sites where we can get idea on how to develop these projects. Because I wanted to learn by working on big project I just dont know what to use and when to use. If there is any hint on how to leverage these things would we a great learning for me

3

u/humoroushaxor Feb 27 '22

I think it's pretty easy to contrive a small application with heavy usage of genetics.

One of my final college projects was implementing a custom ORM and use it to build an ecommerce store. Probably scratches a lot of OPs itch

4

u/Bibliophile5 Feb 27 '22 edited Feb 27 '22

I started with the The Complete Reference and realised it is actually a very good book. However, as the name suggests it is more of a reference book which you can keep on your bookshelf so you can refer to it from time to time in your career as a Java Developer.

So I scoured for books and eventually found "Introduction to Java programming" by Liang, which explains Java, even the small bits along with programming examples in the chapter. The most important thing is the exercises at the end of the chapter which are numerous and grouped by difficulty.

4

u/Tanuj7250 Feb 27 '22

Thank You for this.... I will surely look into this book because I wanted ro solve some exercises also. Will help me retain what I've learned

10

u/MRH2 Feb 27 '22

File I/O:

  • Read in a book from Project Gutenberg (either by downloading it and then reading it in, or reading it directly from the URL)

  • find out how many of each letter there are, print out the top 5 most common letters.

  • Now do it with words (you'll need a hashmap). Find the 5 most common words (ignore a, an, the). And you'll have to handle punctuation, so that "Hooray!" is seen as the same word as hooray .

  • Now rewrite it using streams.

3

u/[deleted] Feb 27 '22

Start by writing the code given in the book examples, and then keep on adding the topics you've learnt. For example, start with the File I/O example, add some exception handling, add some GUI code using Swing or JavaFX, make some modular classes for handling different types of files, create a hierarchical type using abstract classes, interfaces. Try to use functional interfaces, write some methods that use Stream API and /or lambda expressions. Do all of this, without using the main() method, you're only allowed to call 1-3 methods in the main.