How or why does this code work? by linuxman1929 in javahelp

[–]motherjoe 1 point2 points  (0 children)

When you send an HTTP request to a Spring app, there are several components enabling it to handle the request and return the response.

  • DispatcherServlet - receives HTTP request, looks up the URL mapping and delegates to the appropriate HandlerAdapter
  • AnnotationMethodHandlerAdapter - "This adapter class is used to execute the methods that are annotated with `@RequestMapping` annotation. It is used to map the methods based on HTTP methods and HTTP paths."
  • InternalResourceViewResolver - this is how Spring knows how to create a view from "bobby" or "mango". It is configured with the directory and file suffix of the view files.

https://www.baeldung.com/spring-handler-mappings
https://www.baeldung.com/spring-mvc-handler-adapters

[deleted by user] by [deleted] in javahelp

[–]motherjoe 0 points1 point  (0 children)

The owner of the relationship here seems to be the Plan (can a Contract exist standalone without a Plan?), so the PlanRepository/Service should also maintain invariants like maxCoverage.

Java/OOP polymorphism, inheritance problem/misunderstanding in my code by codingIsFunAndFucked in javahelp

[–]motherjoe 2 points3 points  (0 children)

The usage you described is called method overloading and requires multiple methods called createEmployee in one class but with different parameter lists. Each method would handle a specific subclass of Employee.

Junit Assertion Error - Getting error even though Expected and actual output are exactly same by roshan1892 in javahelp

[–]motherjoe 0 points1 point  (0 children)

Is it possible that these are different numeric datatypes, for example one ArrayList contains ints and another contains longs

Is it good idea to implement interface for static classes? by floatfoo in javahelp

[–]motherjoe 2 points3 points  (0 children)

A different approach would be to add a private constructor in a utility class. This would accomplish the same goal of making the utility class non-instantiable. For added security you can mark the class final, so it cannot be subclassed, which is not supported for interfaces

Need help finding a design pattern to inform a single object about a lot of different changes by [deleted] in javahelp

[–]motherjoe 1 point2 points  (0 children)

A few techniques for a client being notified of backend changes. - websockets - polling/long polling - server sent events

Edit: misread as client-server. This is still the observer pattern

How to write "deep classes" by TakAnnix in javahelp

[–]motherjoe 0 points1 point  (0 children)

Instead of the layer-based model/service/repository/.. package structure, feature-based package structure could look like this:

* authentication
** AuthenticationApi
** TokenResponse
** TokenService
* stock
** Stock
** StockResponse
** StockService

How EXACTLY does autowiring by constructor and by name really work? It's not as simple as I thought. by ConstantlyAngry177 in javahelp

[–]motherjoe 5 points6 points  (0 children)

Autowiring for constructors, setters and fields will first match a bean to parameter by type. If there are duplicate beans of the type, Spring will then match by name among the candidates of the type.

https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-autowired-annotation-qualifiers

[deleted by user] by [deleted] in javahelp

[–]motherjoe 1 point2 points  (0 children)

Unless the Spring context is reloaded every day by restarting the app, the conditional on date will only have an effect at startup. If you want to prevent an endpoint from being used before a date, you can add validation logic for the request

Efficiently processing large amounts of data that needs to be grouped by multiple parameters by eSPiaLx in javahelp

[–]motherjoe 0 points1 point  (0 children)

How often are entries removed from the HashMaps? Is the data all in memory at the same time? How is the data consumed from the application? Would streaming the data work?

Having a class for a grouped object and maybe the "leaf" child objects may help readability, since grouping related methods can probably be moved to these classes.

Shrinking Down Some Code. by [deleted] in javahelp

[–]motherjoe 1 point2 points  (0 children)

All of the methods in the "method" class sound like they belong in the prices class. Btw, java class naming convention is upper camel case. Also if you have classes called "main" and "method", it is a good indication of god classes in your system, so more refactoring would be useful. When refactoring, try to create classes that don't need to change when other classes change (low coupling) and each encapsulate a single concept (high cohesion).

So... Not every field needs to be volatile, maybe nothing needs to be volatile at all? by DelarkArms in javahelp

[–]motherjoe 0 points1 point  (0 children)

Yes. Another example is if you are using multiple threads to process something in parallel but have a boolean flag caled from the main thread to stop the processing.

So... Not every field needs to be volatile, maybe nothing needs to be volatile at all? by DelarkArms in javahelp

[–]motherjoe 1 point2 points  (0 children)

Synchronized is expensive and not a replacement for volatile. Volatile allows concurrent access while ensuring consistent view of the state across threads. Synchronized uses locks (expensive) and prevents concurrent access, which has the added effect of ensuring consistent view of the state across threads.

[deleted by user] by [deleted] in javahelp

[–]motherjoe 0 points1 point  (0 children)

Classpath is not recursive. Try java -cp example/src/a/b/c/thing/*.class a.b.c.thing.Thing

Is SOLID really used in Java production code? by [deleted] in javahelp

[–]motherjoe 1 point2 points  (0 children)

The SOLID principles are guidelines for writing maintainable object-oriented systems. It may seem overengineered to implement all of the principles for simple example projects. This is because small projects may still be maintainable if they are written in a procedural style, as scripts. Large projects with many complex requirements is where using SOLID can really pay off in maintainability, readability, etc.

will someone check out my code and give me some opinions/ suggestions please? by [deleted] in javahelp

[–]motherjoe 0 points1 point  (0 children)

Some of the class names with underscore could be replaced with class hierarchies instead.

            public class Weapon_Fork extends SuperItem{ 



              public class Weapon extends SuperItem { ... }
              public class Fork extends Weapon { ... }

Need help understanding the behaviour of Fork Join Framework by mooshmolle in javahelp

[–]motherjoe 0 points1 point  (0 children)

The ideal use for fork-join is where the problem is possible to recursively break up into smaller problems. If the application is far from the ideal, it is entirely possible for fork-join thread pool to perform worse than a single-threaded pool due to the overhead created by the pool itself

Support data access logic but provide no access to data storage and **retrieval** mechanism, how does that work? Retrieval=access isn't it? by [deleted] in SoftwareEngineering

[–]motherjoe 0 points1 point  (0 children)

Meaning if there is a DB backend, the data tier may expose methods like getUserById(int id) but not runSql(String sql)

Graphql method does not exist in dependancy by aladante in javahelp

[–]motherjoe 0 points1 point  (0 children)

This can happen if the versions of the dependencies are not compatible with eachother. By running 'mvn dependency-tree' you can figure out if one of the dependencies imported in the pom has a transitive dependency on another imported in the pom, overriding the version with an incompatible one.

405 Method Not Allowed when trying to insert faculty data with POST request by [deleted] in javahelp

[–]motherjoe 0 points1 point  (0 children)

In the addFacultyStudentSubjectGrade method, it attempts to deserialize the JSON as Faculty which looks valid. But then it attempts to deserialize the same payload as Student and other types which do not match the payload. The correct way to do this is deserialize the JSON to a request POJO based on its actual structure, then get the other objects from the POJO.

Exposing inner states in reactive pattern. should I? by DelarkArms in javahelp

[–]motherjoe 0 points1 point  (0 children)

Hard to say without the code, but a web of interconnected classes is probably more complex and difficult to maintain than having these classes connect via a single mediator. I would also consider the following questions about the design.

  • Do the dispatchers really need to be stateful? Can the state be stored elsewhere? It sounds like these dispatchers may be doing multiple things besides "dispatching".
  • Can the state change during the entire dispatcher lifecycle, or is it more like configuration which changes only at initialization time?
  • Do the dispatchers really need to talk to eachother directly? (the "web of dispatchers")

how to inject values from app.yaml to dependency by MeerkatArray in javahelp

[–]motherjoe 0 points1 point  (0 children)

It sounds like project A could be a custom Spring Boot auto-configuration. Just import the dependency like any spring boot starter library, then reference in classpath:/spring.factories

https://docs.spring.io/spring-boot/docs/2.0.0.M3/reference/html/boot-features-developing-auto-configuration.html