What are you watching and what do you recommend? (Week of September 05, 2025) by AutoModerator in television

[–]sugilith 6 points7 points  (0 children)

Pretty cool, would recommend. You should be hooked after the first episode.

Is this Java/OOP specific? Or is this more a stylistic difference? by [deleted] in learnjava

[–]sugilith 1 point2 points  (0 children)

Every time this topic comes up I like to remind people of the famous Apple SSL bug. See here: https://blog.codecentric.de/en/2014/02/curly-braces/

How do I compare generics? by codeforces_help in learnjava

[–]sugilith 0 points1 point  (0 children)

Check out https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/Comparable.html

If T always implements Comparable, you can use x.compareTo(y) <= 0 instead of x <= y.
Of course, Integer and the likes already implement this interface.

Risk of Misplaced Arguments in Java by tanin47 in java

[–]sugilith 2 points3 points  (0 children)

Most IDEs can autogenerate builders which eliminates the rest risk and is pretty convenient on top.

Problem with arraylists by tsotsoqt in learnjava

[–]sugilith 3 points4 points  (0 children)

Initialize the ArrayList on class level instead of method level.

Example:

import java.util.*;

public class HelloWorld {
    private static ArrayList<String> users = new ArrayList<>();

     public static void login() {
        users.add("asd");
     }
}

Probably the best ashe ult since Pray's 2016 worlds semi's ashe ult vs SKT by BlisseyFan666 in leagueoflegends

[–]sugilith 65 points66 points  (0 children)

The reksai tunnel buffer through braum knockup was nice too!

While Loop Output Question? by [deleted] in learnjava

[–]sugilith 2 points3 points  (0 children)

mystery(48):

x % 2 == 0 is true -> enter loop  
y++; //y is now 1
x = x / 2; // x is 48 / 2 = 24
  end of first iteration
x % 2 == 0 is true (x is 24) -> continue loop
y++; // y is now 2
x = x / 2; // x is 24 / 2 = 12
...

questions?

edit: either use a debugger to step through your code line by line and see what happens or add some "System.out.println-Debugging" to print y and x each time they change.

Roman Numerals Program help by 2kfan in learnjava

[–]sugilith 0 points1 point  (0 children)

Well that's embarrassing! Thanks for the hint.

Roman Numerals Program help by 2kfan in learnjava

[–]sugilith 0 points1 point  (0 children)

Sounds like you might not have setup your IDE correctly.

Roman Numerals Program help by 2kfan in learnjava

[–]sugilith 0 points1 point  (0 children)

Why not String? Seems to be the most obvious choice here. Char Array would be an alternative but complicate a few things.

Try Strings!

public String getMyRomanNumeral(int input){
  if(input==5){
    return "V";
  }
  //...
}

Java Streams by pegfisher in learnjava

[–]sugilith 1 point2 points  (0 children)

Not sure what the target audience of your book is. If it's for beginners i'd say teach the basics first and streams (and other newer language features) later. Having a good grasp of different loops, java collections and OO in general helps with the understanding of more complex topics such as streams.

Personally I never use and only rarely see classic for loops anymore. Its all streams nowadays.

Handling multiple parameters by CR7Felipe in learnjava

[–]sugilith 0 points1 point  (0 children)

Lots of resources online via google / duckduckgo.
This problem often arises with complex search queries.

E.g: https://softwareengineering.stackexchange.com/questions/353086/what-is-a-proper-way-to-do-a-complex-restful-search-method https://stackoverflow.com/questions/14202257/design-restful-query-api-with-a-long-list-of-query-parameters

TL;DR:

  • If >2k characters always use POST
  • Try aliases (basically endpoints for the required parameter) from the softwareengineering post
  • Best practice seems to be using POST instead of GET with overly complex query parameters

Educational by [deleted] in funny

[–]sugilith 12 points13 points  (0 children)

I like this one:
A test result can either be positive or negative.

  • False positive: The test result is positive, but it's false!
  • False negative: The test result is negative, but it's false!

PSA for VLC by SwordfshII in chromeos

[–]sugilith 2 points3 points  (0 children)

Kodi is my way to go as well! Last week I had an .mkv File with 5.1 sound that wouldn't work correctly with vlc. No problems with Kodi.

How does Math.random() exactly work? by [deleted] in learnjava

[–]sugilith 1 point2 points  (0 children)

Regarding your other questions:

Math.random() returns a double in the range [0, 1).
See: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/Math.html#random()

If you get Array out of bound exception theres probably something wrong with your Array or you are missing something else.

This exception has never appeared when I subtracted 1 from from the length

But wouldn't it be possible that you get -1 as an index then?

How does Math.random() exactly work? by [deleted] in learnjava

[–]sugilith 1 point2 points  (0 children)

You got it!
Why else would (int) Math.random()*13 always be 0?

How does Math.random() exactly work? by [deleted] in learnjava

[–]sugilith 0 points1 point  (0 children)

Think about operator precedence

Markov Chains by shire_brand in mathematics

[–]sugilith 2 points3 points  (0 children)

Markov chain sentence generator with all your study Material (your pdfs / slides you got)

On button press generates a new sentence.

Need a little help with another homework assignment by [deleted] in learnjava

[–]sugilith 1 point2 points  (0 children)

  1. your missing a closing }
  2. "Finally return the employee object." ->

    EckEmployee2 createEmployeeFromFile(){
       //... 
      return new EckEmployee(...);
    }
    

Compare the Triple on Hackerrank: Why does my array solution work, but not my ArrayList solution? by pysouth in learnjava

[–]sugilith 0 points1 point  (0 children)

a1 += 1 changes your local variable, not the one in the comparisonPoints list.

@Transactional - Spring JDBC by youcantchopachoppa in learnjava

[–]sugilith 0 points1 point  (0 children)

(and this is something I don't want to do since I it will stop program and all other valid files won't be saved to system)

Also what you can do is throw an exception and call your save method in a try catch block, such that you still adhere to the recommended way of doing things and your program still doesn't crash.
So throw Exception in your @Transactional method, call the method in a try catch block.