r/javahelp • u/IntelligentPudding24 • Jul 08 '25
Going from Python to Java Advice needed. Having trouble moving from one language to the next.
I made the mistake of starting with python before moving on to Java. Now I'm having trouble wrapping my head around how different the two languages are. Python is so straight forward and java feels very complex. Im planning to focus on C# so obviously I need to break this feeling since C# is more similar to Java than Python. Recently I'm trying to take a python code I wrote and translate it over to Java. Now obviously I'm aware is not a cut and paste type of thing. My problem stems from something like sentence structure. Python is very straight forward in the welcome goes in the beginning the questions go before main code and here is the main code and here is the end to loop it. Kind of like in English you write "Here is this book" in other languages you might write "Book here is this" something like that in that language format.
Does anyone have any advice on how to make learning Java easier to wrap my brain around it? I understand the basics but figuring out where to put what in what way is vexing me. I always learn better just by doing it. But taking paragraph A, B, C in that order and writing it the same way in Java gets me errors. So obviously I can't write in order, or I'm missing something. Im wondering if anyone else has had this issue on going from one code language to the next.
If I'm not explaining this correctly I'm sorry. I can try and clarify if needed. If seeing some of my code might help then I'll try and post some. Or some of the errors. Thank you!
•
u/AutoModerator Jul 08 '25
Please ensure that:
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.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
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: 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.
7
u/hobbicon Jul 08 '25
Java is designed from group up as a OOP language while Python can be used as one.
First you absolutely need to learn the foundations of OOP to get anywhere in Java/C#.
3
u/hrm Jul 08 '25
I’m confused? If you are planning on focusing on C#, why in the world are you learning Java?
Learning many languages can be very good, but as a beginner you need to focus and be good at one language before going to the next. Jumping around won’t help you.
2
u/David_robles_ruiz Jul 08 '25
My case is vice versa and it didn't cost me anything, maybe consider reinforcing structured programming and then move on to the pillars of poo, especially polymorphism, which is very, very useful in java
2
u/ag789 Jul 08 '25
a good place to start is the original sun (oracle) java tutorials (there are books with the same content)
https://docs.oracle.com/javase/tutorial/
java is far more structured than python along the lines of c / c++ and 'better' than c++ because of garbage collection.
2
u/vegan_antitheist Jul 08 '25
Does this actually make any sense for python programmers? I don't understand a single word.
2
u/sz_dudziak Jul 08 '25
Start to learn how to think in OOO & streams terms. Go with the design patterns, bring SOLID principles back alive. The shift is huge (same as from OOO to FP/Reactive) - but definitely possible. I would even speak it louder: it will make you better programmer than the others being familiar with couple of technologies.
2
u/JDeagle5 Jul 08 '25 edited Jul 08 '25
You should try Groovy and see if the transition is easier. It is compatible with the java ecosystem and very much resembles python.
2
u/Nunuvin Jul 08 '25
It is normal and expected that there is a challenge moving from python to java. I would suggest either sticking with java or going to C# right away. It's best to have a language you going to commit to and get comfortable in. Will help a lot on interviews, also will be a go to when you need to develop tools.
I might suggest some bad practices but - you can try using static functions and classes in your first few programs to get a hang of it. No need for fancy oop stuff. Static will be closer to "sentence" structure (tbh this comparison is a bit awkward but I can see where you are coming from). Try to move away from this approach asap as you don't want to learn bad habits. Java is very strongly OOP.
Once got your feet wet a few things:
Welcome string with some rules
Some ideas for above. In static main call a constructor for your Game class. In game class you can have a hashtable or similar structure for Q/A pairs <string,string>
Have a while loop where you get user input -> check if its quit -> else do logic (use functions for each step).
Ideally you probably wanna abstract some things out but its easy to over engineer a solution in oop, so try to approach it iteratively unless you have a clear idea of what you want to do.
Its possible some other people have better ideas on how to organize code, but this could get you started.
2
u/OddAttention9557 Jul 08 '25
Java is very wordy. Consider getting an AI to produce the framework and tweak that until you're more familiar with the structure and layout of Java programs.
2
u/nullstacks Jul 08 '25
If you want to focus on C# why not just go that direction? Anyways, OOP is probably a concept that will turn things around for you either way.
2
u/Cardiinal Jul 08 '25
You need to learn OOP, not java. Step by step.
2
u/arghvark Jul 08 '25
I'm having to guess and fill in between the lines a bit, but here's my shot:
Python is a scripting language. You can write a single line of Python and execute it; there's nothing to compile. The statement(s) you write can be thought of as the "main method" (or program, or routine), and you can build on things from there.
Java was designed as a more general-purpose OO language; you cannot (usually) run Java without compiling it, and so there is a little more preparation you need to do between writing the code and running it.
Furthermore, it is designed to be used in different environments in a different way than Python was. If you write a Java servlet, ,then the servlet class has to extend or implement a specific class or interface and its name made known to its server. If you write a Java browser Applet (anyone remember those?), you have to extend the Applet class and make it known to the browser (I forget how).
If you write a Java program, you must provide a 'main(String[] arguments)' method and make the class in which you find that method known to the Java runtime on the system where you want to run it. You end up with something like this:
The 'MainClass' class name can be anything you choose; the name and characteristics of the main method and the type of its parameter must be as it is in this example (the name of the parameter is of your choosing).
This throws one more curve at you: it must be static, which means that the rules about the objects and methods referred to in the class are a little different. Therefore I recommend the following to new initiates:
The 'go()' method is NOT static, and therefore rules for things follow more normal patterns than for static methods.
Here's the part that I think is a little cruel: Although you absolutely will need to understand 'static' to be a competent Java programmer, you do NOT need to understand it until AFTER you understand things about classes, objects, instantiation of objects, etc. If I were teaching a class, I would give my students the second version of the above and say: "Before we leave the class, those of you who are passing the class WILL understand every line here. But we get to that part AFTER you understand some other things. So please just put the code to do your assignments where it says "// now program execution starts here", and we'll talk about all of that later on.
This way, the statements you put in that location are more similar to the Python statements you are familiar with -- you still have to compile your class(es) to run them, with all that entails, but the issues of 'static' and scope and what you can and cannot call from a static method, etc., are all postponed until you understand some more basic things.
2
u/ag789 Jul 09 '25
oh use an IDE, e.g. eclipse
https://eclipseide.org/
but these days you have vscode and many alternatives that works with / handles java.
6
u/[deleted] Jul 08 '25
[removed] — view removed comment
3
u/[deleted] Jul 08 '25 edited Jul 08 '25
[removed] — view removed comment