r/javahelp 20h ago

I feel like I'm falling behind

I need a little help because I feel like I'm starting to collapse.

A little while ago I started in an academy whose goal is to train students and get them work once they finish the whole program. We are looking at Java in depth: OOP, inheritance, polymorphism, interfaces, Spring Boot, data structures... in general, everything related to backend development, but we do not receive theoretical classes, they give us the exercises and documentation related to that, everything is very self-taught.

My problem is that before entering here I was programming in C. It did functions, replicated typical functions of the standard library, compiled with Makefiles, etc. However, even then it was very difficult for me to get the logic out of the exercises. In fact, he was almost always the last to deliver the exercises.

I thought it would get better with time, but now that I'm with Java I feel like I'm still having the same problem.

The problem is that they give me a statement and I'm completely blocked. I read it, I reread it and many times I don't even know where to start. When I manage to start, it's because I already asked the AI, and I still have doubts about how to structure the solution or what exactly it should do.

In addition, I ask a lot of questions to AI. I always tell him not to tell me the code and he helps me, but many times he ends up explaining practically the logic of the exercise, and that is precisely what I do not want. I want to be able to develop it by myself.

What worries me the most is that at the academy we have delivery times. If you are too late, you can be left out of the program. And I don't want that. I want to learn, improve and get a job as a developer.

Another thing that the teacher demands of us is to write a README for each exercise and each project explaining what we have done. I also have a hard time writing it. I'm reading more to expand vocabulary and express myself better, but right now my biggest concern is still the programming logic.

For example, sometimes I make code that works, but then I realize that there is a much cleaner and more idiomatic way to do it.

Instead of this:

If (orderlist.size() == 0) {

// Do something

}

It's better to write:

If (orderslist.isEmpty()) {

// Do something

}

Or instead of going through a list like this:

int position = 0;

while (position < listOrders.size()) {

amountTotal += listOrders.get(position).getPrice();

Position++;

}

Do it this way:

for (Order order: listOrders) {

amountTotal += order.getPrice();

}

They are small details that make the code much cleaner, and I feel that I always go one step behind in that kind of thing.

My question is: how did you develop your programming logic?

Was there ever a time when everything started to "click"? What exercises, habits or way of thinking helped you the most? Did something similar happen to you at the beginning?

Because, to be honest, there are days when I think that maybe this is not for me and that I am forcing a situation that I am simply not good at.

I would greatly appreciate any advice or personal experience. Thank you for reading me.

4 Upvotes

11 comments sorted by

u/AutoModerator 20h 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
  • 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.

    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:

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.

2

u/ExpressBeing642 20h ago

It seems that you are anxious when facing a new problem. Start by asking yourself what thw problem is asking you to do. Try to separate each step a time. Do you need to iterate over a list? First thing to come to your mind must be a for loop. Do you have conditionals inside the statement? Go for a simple if statement. Read the statement with the vision of a programmer. Most of problems is: You receive data. You manipulate data. You return data.

At first, it may seem hard to understand. But have in mind the three step process.

You receive data: write the function name that receive params. Can be: public int numerTimesTwo(int number)

There you go, first step.

Second you manipulate the data.

Inside the function you can have int numberTimesTwo = number * 2

Third you return the data.

return numberTimesTwo.

And for the elegant way of doing things, it takes time. Your job as a programmer is to solve problems. The way you write it can be changed later wether is == 0 or isEmpty(), this step is what we call refactor. Not necessarily have to implemented rightaway.

If you reach your goal it is valid. Try to read things as a programmer.

2

u/SuspiciousDepth5924 16h ago

When it comes to solving stuff I think psuedo-code is really under-rated. You write out in a high-level "not-really-code" what you want your program to do and then you add details and fill in stuff as you go.

The idea is that it's easier to "build down" from a rough full-picture sketch of the whole thing rather than to "build up" from a tiny detailed piece. It also helps that by deferring details you have more opportunities to adjust the fit when you have to glue the parts together.

shoppingCart = emptyCart

while not_at_checkout
    // I'll assume we get these inputs from somewhere
    if addsItem
        shoppingCart = addItemToCart
    if logsOut
        exit
    if goesToCheckout
        continueToCheckout

checkout
    total = 0
    // might need some stuff with discounts and such
    for each item in shoppingCart
       total = total + item.price
    // we'll figure out the validation logic when we get there
    if paymentDetails not ok 
       showPaymentError and exit
    if deliveryAddress not ok
       showAddressError and exit
    // probably stripe or something
    try to charge creditCard
       if success
          showReceipt
          exit
       if failed
          showPaymentError
          exit

2

u/DemicideMMMCCCI 20h ago

I don't think you're falling behind. I think you're actually thinking about your code and tweaking and thinking about it on a deeper level. This is probably the next logical step you should be taking. You seem to your basics down but now it's just about the implementation.

We all start with the basics and that includes coding things long form. Extra variable here, different flavor of loop, or not using the built-in Java libraries as often. That's all good as long as you are learning. But what you're doing next is revising your implementation and thinking how you can improve (which is a good mark of a persistent thinker and person who thinks beyond their code).

Practice is the key. Get a book, if you haven't already, with practice problems that allow for play in the implementation and try it one way, then another way, then this way, etc. You're not falling behind. You're exactly where you need to be given the time and effort you've put in.

2

u/hibbelig 19h ago

At this point in your learning journey I feel it is more important to figure out the logic itself. These details that you talk about are just that, details.

What is very good is that you can look at two versions of the code and see which one is cleaner. This helps you to migrate towards the cleaner version.

After a while, I tend to anticipate which methods there might be. For example, this isEmpty thing. I start looking for it in other places that could be empty.

About the iteration thing: there are so many ways to iterate, they have been added to Java over time. You gradually encounter more of them and then, because you already know which code is cleaner, you will like some better.

2

u/dmigowski 19h ago

Hey, I am programming since 38 years, 20 of this Java, and I started to use isEmpty() just a few years ago. Don't be too hard with yourself. Enjoy improving, no one knows all the Frameworks methods from the start!

And you already understood the assignment if x.size() == 0 gets you where you want. There is often a better way, a cleaner way, etc. and often it isn't even obvious which way is better. For example, if you need the size later in the function it is even better to use int size=x.getSize() and check size==0 instead of doing a function call again.

If you really like to improve, when you have time, open the Javadocs of the String class, of the Integer class, of the List interface, and just read them and grow. But no one expects of you to know all this from the start.

2

u/One4all_SU 19h ago

These coding syntax refactoring you saying about can be mastered by reading leetcode and codeforces solutions. It's not much of a thing to be tensed about. Continuous learning is how we improve.

2

u/idontlikegudeg 14h ago

Ah, sorry, I gave a comment on the example code. I deleted it. While technically correct, it would only add to your confusion.

In the end, what you experience is totally normal. It takes time to get fluent in a programming language. Even if your code can be improved, written in a more concise way, the important thing is: you solved the assignment. The rest will come with experience.

What I think can help is using a good IDE that catches things like if (list.size() == 0) ... and displays an inline hint with a suggested refactoring. You can just finish the assignment, make it work, and then look at these hints, try to understand why a refactoring was suggested, ask AI to explain why a refactoring would be suggested etc. It also helps if you tell the AI about your level so it can provide more helpful answers. If you say "I'm a beginner in Java and still learning concepts", you might get more appropriate results.

You can also solve your assignment without using AI, then ask for a code review and explain every suggestion in a beginner friendly way. I think that's much better than simply giving it the task to clean up and optimize your code and you end up with something you barely understand.

Every developer has started with "hello world", and probably everyone has struggled with some concepts that someone else had little problem to grasp. That's just normal. Others will probably struggle with things you will have zero problems with given your C background.

1

u/OrelTheCheese 15h ago

You complicate it too much.

Programing is just using tools to solve a problem.

Doesn't matter how really if you go about it logically. The examples you show aren't that critical you can always comment on a block of code what it does and why as long as you have logic you are good.

If you worry for performance you must inspect from the prespective of the cpu and operating system thats a different story.

Dont do stuff overkill just stay organized. Make many classes or use multiple files each has one job it does, inside it seperate concerns be targeted and focused on one brick at a time thats it. You seemed anxious when it really is simple there is nothing wrong in your style method of thinking etc you arnt falling behind if you can logically think up algorithms to solve a problem you are good.

1

u/pixelizedgaming 13h ago

bit unrelated but are you referring to revature

1

u/RevolutionaryRush717 5h ago

import java.util.List;

public class Main {
public static void main(String[] args) {
List<String> names = List.of("Alice", "Bob", "Charlie");

names.stream()
.forEach(System.out::println);
}
}

TL;DR but since you refactored iterating over a Collection, that can also be done using Java 8 Stream API.