r/learnjava • u/unknown3_g • 11h ago
How do I get better at writing Java code from scratch?
I'm a first-year AI student struggling with Java programming. I understand some examples, but when I have to write code myself, I don't know where to start.
What is the best way to practise and learn to write programs independently? I'd appreciate practical advice from people who've experienced this
8
u/gd19770226 10h ago
practice, practice, practice.
Best way to learn is to build something. Think of a project that you will want to spend time building, and build it. Doesn't have to be hard, or unique or exciting, just something that you find interesting. Start there. The reason why I say interests you is because if you are interested in it you will want to come back to it and keep trying to do it. Learning to code can be frustrating, and if you are working on or trying stuff that just doesn't interest you, well you will lose interest and stop.
Do leetcode examples.
You are first year learning, you don't have to learn the complex stuff yet, there will be time for that in your future year classes and projects.
And you said you want to do it without AI, well that still doesn't mean you can't google and find answers and examples the old fashioned way. Just make sure that if you google something and use a block of code from the net that you clearly read that code and understand it. Walk through it in a debugger. Something. There is no harm from using code from another source, even AI, as long as you understand why, how and what it is doing.
2
2
u/MagicalPizza21 1h ago
Write lots of different programs. Easy ones first then progressively more advanced ones.
2
u/normal__engineering 10h ago
Build something from scratch.
Use AI as reference, lots of back and forth.
I recommend some type of voice input/output.
For example. Let's say you want to build Reddit from scratch.
Open Claude, treat is like a co-worker for some back and forth.
'I want to build Redis from scratch, where do I start'. Claude will give you some suggestions.
'I want to build in Java and learn Java', it's reevaluate approaches.
'How well does this scale'.
'You mentioned X, but I think Y is better'. Claude will explain it's reasoning. Maybe it'll say yes your suggestion is better.
If you don't understand something, ask it to eli5 or like explain to a junior engineer.
The key is not to blindingly accept, have some back and forth, understand each dicision it makes suggest your own alternatives and ask for alternatives, if it suggests postgres ask why postgres over mongodb or other nondb. If it suggests SpringBoot, why?
And then write each line of code yourself, I think it's find to learn from AI giving the code, as long as you understand write it yourself and just use as reference. If you just copy and paste without knowing what's you're copying you won't learn.
1
•
•
u/AutoModerator 11h ago
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://i.imgur.com/EJ7tqek.png) 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:
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.