Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Pedestrian Xing
Jul 19, 2007

Any recommendations for a printing library? I want to take an image file, a dynamic printer address, and have it print with minimal configuration.

Adbot
ADBOT LOVES YOU

Pedestrian Xing
Jul 19, 2007

Anyone have strong opinions on Mac vs Windows for java dev? New job is asking which I want. I've always used Windows but if there's some tool that works better on Mac I'm not opposed to switching.

Pedestrian Xing
Jul 19, 2007

I like NetBeans, I think most people use IntelliJ.

Pedestrian Xing
Jul 19, 2007

That sounds like something you should let the DB handle as long as it's indexed properly. If it has to be done in memory, make some kind of Map structure so you're not searching over and over. Also possibly Streams if it doesn't have to be done in a specific order?

Pedestrian Xing
Jul 19, 2007

Trip report: Mac pretty good so far, having a lot harder time adjusting to IntelliJ from Netbeans. My macros... :qq:

Pedestrian Xing
Jul 19, 2007

Java Readers intentionally ignore the existence of a BOM in a string/file which is annoying. Commons-io has a BOMInputStream that will deal with it.

Pedestrian Xing
Jul 19, 2007

Can't remember who recommended Key Promoter X but it's helped a ton in switching to IntelliJ.

Pedestrian Xing
Jul 19, 2007

I have a friend who has done a Java bootcamp and wants to learn more OO stuff. What's a good mid-beginner Java book/course?

Pedestrian Xing
Jul 19, 2007

Commons FieldUtils is great for any reflection stuff.

Pedestrian Xing
Jul 19, 2007

Work has asked me to start doing technical interviews for Java developers. Has anyone encountered any good basic Java language questions? For example, in one interview another dev asked how the candidate would implement a queue style interface using two stacks. Looking for 5-15 minute questions that can be done with a whiteboard.

Pedestrian Xing
Jul 19, 2007

Sorry, I should have been more specific. At this stage, we know they have at least FizzBuzz-level coding ability. This is more about seeing their problem solving abilities in action. Questions with no one best answer are great as well as more straightforward implementation ones.

Ola posted:

And don't punish wrong answers over right attitudes and a keen, problem solving mind.

We're allowed to give hints and getting it wrong isn't a DQ.

Pedestrian Xing
Jul 19, 2007

Custom message parameter in the annotation?

Pedestrian Xing
Jul 19, 2007

I like the fluent pattern for POJOs with a lot of fields. Lombok and IntelliJ can both generate them.

Pedestrian Xing
Jul 19, 2007

Splinter posted:

I would think a Builder would be the way to go if you have that many constructor parameters. Fluent setters is an improvement over trying to get the ordering of that many constructor parameters correct, but that leaves open the possibility that a client won't set everything that needs to be set before the object is used. Builder gives you the fluent benefit of not having to get the constructor parameter ordering correct, and can ensure an object is in a valid state before it can be used. It also allows for making the object immutable, which isn't possible using a fluent setter approach.

This is very true - fluent pattern does tend to make state validation difficult.

Side note: I've started using JSR 305 annotations in all my new code and really like them. Specifically, I'm using Spring's @Nullable/@NonNull meta-annotations.

Pedestrian Xing fucked around with this message at 20:35 on Mar 19, 2020

Pedestrian Xing
Jul 19, 2007

Anyone have experience with Project Reactor and Netty? I'm trying to write a proxy that can do streaming decryption + download of large files to avoid buffering them. Netty's HTTP client gives me a Flux of ByteBuf's of arbitrary size and I need to turn that into a Flux of byte[]'s of a fixed size for decryption. Not sure what operation I'm looking for - it needs to consume every ByteBuf like map(), but each input could result in 0-N outputs. This is my first foray into reactive programming, so I might be missing something simple.

Pedestrian Xing
Jul 19, 2007

Pedestrian Xing posted:

Anyone have experience with Project Reactor and Netty? I'm trying to write a proxy that can do streaming decryption + download of large files to avoid buffering them. Netty's HTTP client gives me a Flux of ByteBuf's of arbitrary size and I need to turn that into a Flux of byte[]'s of a fixed size for decryption. Not sure what operation I'm looking for - it needs to consume every ByteBuf like map(), but each input could result in 0-N outputs. This is my first foray into reactive programming, so I might be missing something simple.

I did finally figure this out, the answer is Flux<T>'s flatMapConcurrent(Function<T, Flux<T>>) method. It has to return a Flux, but it can have 0..N members.

Hughlander posted:

No but I have experience with Netty, and I'd just use a Pipeline to decrypt the stream before it got to Project Reactor, unless you must use their encryption.

Thanks, I did look into this. Ultimately, since I'm building on Spring Cloud Gateway, I'm not the one constructing the HTTPClient and processing the output separately seemed easier.

Pedestrian Xing
Jul 19, 2007

Kilson posted:

Use a thread pool (ExecutorService or something like that - there are several different versions of the class depending on what you need exactly)

That way you can queue the tasks and make sure too many don't run at once, etc.

If you want to go a little farther, you can have the API call trigger a Spring ApplicationEvent, a JMS message, or something like Kafka. The first two are doable purely within Spring and the latter two allow you to scale out more easily.

Pedestrian Xing
Jul 19, 2007

smackfu posted:

This is nonsense, right?
code:
Optional.ofNullable(value.trim()).orElse(null)
What were they even thinking?

Yes, it will either return a trimmed string or throw an NPE. I assume they meant to do this:
code:
Optional.ofNullable(value).map(String::trim).orElse(null);
which is functionally identical to this:
code:
return value != null ? value.trim() : null;
but involves an extra object allocation.

Pedestrian Xing
Jul 19, 2007

Anyone have experience with event sourcing in Java? Looking at using it as the data model for a new project. Biggest draw is the built-in audit functionality since the data is legal stuff.

Pedestrian Xing
Jul 19, 2007

Tony Danza posted:

I just finished up a project using Axon framework. The reason we were using it was not for the auditing benefits but the letting our project listen to events happening in other projects and then reason out an understanding of it's own. It was nice to do something different.

Thanks for the recommendation! After evaluating a few options, I think I've decided to write my own simple framework. Realistically, we don't need full-blown event sourcing so much as snapshot functionality. Took some inspiration from Axon's Spring integration about how to do the API.

Pedestrian Xing
Jul 19, 2007

I know Spring supports it through JDBC/Redis but it wouldn't be terribly hard to do yourself.

Pedestrian Xing
Jul 19, 2007

Guildenstern Mother posted:

code:
			if (phonebook[i].getPhoneNum() == phoneNum) {

You probably don't want to use == on Strings (or Objects in general).

Pedestrian Xing
Jul 19, 2007

Yeah, Spring and Micronaut and similar frameworks abstract REST stuff away to nothing. Had to refactor some legacy Servlet code recently and it was painful.

Pedestrian Xing
Jul 19, 2007

You can create static internal classes if you want.

Pedestrian Xing
Jul 19, 2007

256 in production? Yikes. I think our dev env services run on 512 heap and 2-4GB in prod but we also use AOP heavily which has significant heap usage impact. If you're really memory constrained, something like micronaut might be better.

Pedestrian Xing
Jul 19, 2007

i vomit kittens posted:

Putting a unique constraint on the keys was my first thought, and probably something I should have done in the first place. I guess I'd have to be pretty careful about how I handle the error it would generate though because I don't want:

a) Duplicate records to still be added to the usersVotedIn array anyways (while this shouldn't actually affect anything in practice it will still annoy the gently caress out of me to know that it's happening).

b) If it tries to add a duplicate and the request "fails" (despite their vote actually being recorded) the user will think that their vote did not count and the front-end would also not allow them to attempt to vote again.

Unfortunately, trapping constraint exceptions in Spring is a massive pain in the rear end - if you're using @Transactional, you can't catch them inside your service class, they have to be caught and turned into the appropriate HTTP response at the controller level.

Pedestrian Xing
Jul 19, 2007

Argyle Gargoyle posted:

We have a JSP-based website and we've wasted days trying to connect it properly, via servlet, to our individually locally-hosted Oracle databases.

Are you using raw JDBC or an ORM? Are there any logs coming out of the driver?

Pedestrian Xing
Jul 19, 2007

Paul MaudDib posted:

had some potentially leaking connections that we think might be related to it (it’s either that or hikaripool it seems - we have threads that wait and can’t get connections until after timeout)

Is this related to the "clock skew detected" error messages?

WRT @Transactional, if you need fine-grained control you might be better using a TransactionTemplate. Does the same thing but let's you control the boundaries instead of them being fixed to the entry and exit of a proxied method.

Pedestrian Xing
Jul 19, 2007

Maybe experiment with a larger buffer size on your Reader? Default is 8kb which might be triggering a lot of new HTTP connections.

Pedestrian Xing
Jul 19, 2007

Guildenstern Mother posted:

So I'm trying to write a spring controller that will add a recipe to my sql db. Ingredients are unique and don't contain a recipeId and its all tied together in a junction table that looks kinda like this:
code:
junction table

idJunction	idRecipe	idIngredient	idUnits	amount
1		1		1		3		1
2		1		2		2		16
3		2		3		2		8
4		1		3		2		4

Assuming I've got all my entities set up correctly how much of the work can I expect spring to do wrt to populating the junction table? Will I need to save to the junctionRepository?

Is this using Spring Data JPA? If so, I think you would set up your IngredientJunction (entity) class with the id field as a standard ID and then recipe/ingredient/unit would each be a field of that entity type. Things like amount and prep notes would be standard @Column fields. You would set the relation up using @ManyToOne/@OneToMany annotations. At save time, it might look like this:
code:
var junctionsToSave = new ArrayList<IngredientJunction>();
for (IngredientRequest ingredient : recipeRequest.getIngredients()) {
	junctionsToSave.add(new IngredientJunction(newRecipe, ingredientEntity, ingredient.getMeasurement(), ingredient.getAmount(), ingredient.getPrepNotes()));
}
ingredientJunctionRepository.saveAll(junctionsToSave);

Guildenstern Mother posted:

If each ingredient is coming back from the form with notes about measurement, quantity and prep notes could I make those transient properties in ingredients so that while they're there to be entered into the junction table they're not stored as part of the main ingredient entry or is that going to screw everything up?

A general best practice is to use DTO classes for things like requests and responses - you don't want to pass entities around. It can break in a lot of subtle ways as well as setting you up for unintended data disclosure.

Pedestrian Xing
Jul 19, 2007

Somebody in this forum (can't remember which thread) once said that all recursive algorithms can also be expressed as a while(true) loop with a manual break condition and it really made them way easier to approach.

Pedestrian Xing
Jul 19, 2007

Anyone have strong opinions on getting the Oracle Java 17 cert? Is it worth it if I already have a strong resume (aiming for senior/principal level)? If anyone has taken it, how much study should I plan to do?

Pedestrian Xing
Jul 19, 2007

H2 also has a handful of weird incompatibilities with T-SQL that make it a pain in the rear end to use as a test DB. Thankfully there's testcontainers now.

Pedestrian Xing
Jul 19, 2007

Janitor Prime posted:

I really dislike teaching newbies the streaming APIs, what was wrong with doing it the old fashioned way with for loops. I feel like stuff was so much simpler to reason about.

They definitely lead to some antipatterns at times. I see stream-filter-findFirst to get an entity by ID (inside a loop) frequently instead of building a Map<ID, entity> once.

Pedestrian Xing
Jul 19, 2007

I don't know VSCode specifically but most IDEs allow you to right click a dependency and download sources/docs. Most libraries also have their Javadocs and use guides online if you search.

Pedestrian Xing fucked around with this message at 21:37 on Apr 22, 2023

Pedestrian Xing
Jul 19, 2007

LostMy2010Accnt posted:

Still having issues with my maven pom file; it's new to me but I've not had luck building it, just importing dependencies for the project. Also working on why log4j2 isn't logging either; I think it might have something to do with where I have it in the project directory. If any of these are causing you issues, then don't sweat looking into this. Appreciate it, thanks.

Your log4j2.xml should be under src/main/resources. What errors are you seeing with the pom?

Adbot
ADBOT LOVES YOU

Pedestrian Xing
Jul 19, 2007

LostMy2010Accnt posted:

Ah I just had in source, thank you for catching that. Not seeing errors with pom more that: 1) I'm just trying to learn how to use it; 2) Eclipse is acting really odd whenever I try to modify it at times (Weird spacing, freezes, etc.).

Turn off any kind of auto-import or sync your IDE might be doing on pom.xml modification and trigger it manually when you make a change.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply