I'm just starting Java and have read about source code, compilers and the JVM, but I'm getting stuck on branching and loops. Should I keep going with my book or try something else first?
I'm new to Java and loops aren't making sense yet. How should I learn them?
Answers
Keep the book, but put it down regularly and write tiny programs. Start with an if statement that checks whether a number is positive. Change the number and predict what will print before you run it.
For a loop, print the numbers from 1 to 5. Then trace the counter on paper: its starting value, whether the condition is true, what gets printed, and how the counter changes. Try changing one part and see what happens. Reading and practice work together here.
Reply to this answer
A quick distinction might help with the setup: Java is a programming language, while your source code is the text you write in a file. The Java compiler turns that source into bytecode, which the Java Virtual Machine, or JVM, can run.
To write and run programs locally, install a Java Development Kit and use an editor such as Visual Studio Code. A beginner course with setup instructions can walk you through the details. You can also try an online Java environment if you want to experiment before setting things up.
Reply to this answer
There's no need to force your way through one explanation. Try a beginner Java course with exercises, or a short visual tutorial that traces a loop step by step. You can come back to the book when the terms feel more familiar.
Give yourself some time, too. After a day or two, understanding only part of a new concept is perfectly normal.
Reply to this answer
If Java is the language you want to learn, stick with it. If you picked it arbitrarily and the syntax is getting in the way, trying Python first is another option. Conditions and loops carry over conceptually, though the syntax will be different.
Reply to this answer
When code fails, don't just replace it with a solution. Read the error, find the line it points to, and work out what Java expected there. If you use a search or an AI tool for help, ask for an explanation of the problem and try the fix yourself.
Reply to this answer
Add your answer
Answers are reviewed before publication.
s352!idxmode_7:
Small exercises are useful because there's less code to inspect when the result surprises you.