Good Hash Function for Strings

Usually hashes wouldn’t do sums, otherwise stop and pots will have the same hash. and you wouldn’t limit it to the first n characters because otherwise house and houses would have the same hash. Generally hashs take values and multiply it by a prime number (makes it more likely to generate unique hashes) So you … Read more

paint() and repaint() in Java

I’ve spent maybe the last two hours browsing and reading up on these methods and the Graphics class, and maybe I’m stupid, haha, but I’m just not understanding them. What are they for? I understand that they’re supposed redraw or update components on the screen, but I have never understood why this is required (I’m … Read more

java code is showing error. ( ‘;’,expected)

You can’t have statements in the class body (z=x*y;). You have (at least) two options: int z = x * y; use initializer block{ z = x * y; } These are virtually the same. I’d prefer the first option (cleaner) See here

Web server failed to start. Port 8080 was already in use. Spring Boot microservice

If you don’t want the embedded server to start, just set the following property in you application.properties (or .yml): If your classpath contains the necessary bits to start a web server, Spring Boot will automatically start it. To disable this behaviour configure the WebApplicationType in your application.properties Source: https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html If you application really is a Web application, then you can easily … Read more

How to sort an array of objects in Java?

You have two ways to do that, both use the Arrays utility class Implement a Comparator and pass your array along with the comparator to the sort method which take it as second parameter. Implement the Comparable interface in the class your objects are from and pass your array to the sort method which takes only one parameter. Example Output

Could not resolve placeholder in string value

In your configuration you have 2 PropertySourcesPlaceholderConfigurer instances. applicationContext.xml infraContext.xml By default a PlaceholderConfigurer is going to fail-fast, so if a placeholder cannot be resolved it will throw an exception. The instance from the applicationContext.xml file has no properties and as such will fail on all placeholders. Solution: Remove the one from applicationContext.xml as it doesn’t add anything it only breaks things.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)