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
Janitor Prime
Jan 22, 2004

PC LOAD LETTER

What da fuck does that mean

Fun Shoe
I sent you a PM, hit me up if you want to do a live debug over GChat

Adbot
ADBOT LOVES YOU

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
I recently left my last job because I couldn't take working with Scala anymore. It was so bad, and is such a garbage language and ecosystem filled with functional weiners, I just straight up quit one day. The company got acquired and I took a buyout package.

Looking to transition back to Java for my next role, but not sure what to expect to get asked around 8 language features. I'm familiar with the Streams API and some of the functional interfaces, but less so on any sort of concurrency stuff they've added since I wrote Java in 2014 and we weren't on 8. Obviously since I'm more Senior now, I'll probably be asked harder questions but since most of my expertise is in Scala APIs and nuances there.

What kind of Java things would you ask or expect of someone (particularly around concurrency and parallel processing) who has ~6 years experience in a JVM language that isn't Java and more importantly, what's a good practical way to even prepare for something like this? I'm just used to everything being a Future and passing an execution context and functions around everywhere at this point with minimal exposure to anything at a lower level than that.

Good Will Hrunting fucked around with this message at 20:59 on Apr 8, 2021

Volguus
Mar 3, 2009

Good Will Hrunting posted:

I'm just used to everything being a Future and passing an execution context and functions around everywhere at this point with minimal exposure to anything at a lower level than that.

This is Java pretty much. I hardly doubt anyone makes plain threads, and locks poo poo with mutexes and go medieval on concurrency anymore. It's been a while for me too since I touched Java, but we had the executors, with thread pools and futures and promises just so that we can avoid doing the dirty work.

Deffon
Mar 28, 2010

Thanks to Project Loom, I feel like the async ecosystem with Future, RxJava etc. will lose followers.
It's still useful for dividing up tasks among threads with more precision that you can't achieve otherwise.

Project Loom adds green thread support to the JVM, so you can write seemingly synchronous code that doesn't block a kernel thread.

Votlook
Aug 20, 2005

Good Will Hrunting posted:

What kind of Java things would you ask or expect of someone (particularly around concurrency and parallel processing) who has ~6 years experience in a JVM language that isn't Java and more importantly, what's a good practical way to even prepare for something like this? I'm just used to everything being a Future and passing an execution context and functions around everywhere at this point with minimal exposure to anything at a lower level than that.

I'd ask about common java.util.concurrent classes (Executors, ConcurrentHashMap, BlockingQueues, some different lock types), and about synchronized and volatile.

hooah
Feb 6, 2006
WTF?
I'm going through Effective Java and ran across this operator that I've never seen before: >>=. It's used as one of the two increment parts of a for loop. What is this thing? It's like a bit-shift, but what's the equals doing there?

Edit: figured it out thanks to symbolhound. It's the right bit shift assignment operator, like +=.

hooah fucked around with this message at 02:49 on Apr 19, 2021

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE
I have an ExecutorService that I’m using to process work items that I’ve divided into chunks. The chunks share a lock that is created during setup so they can share an output file writer. When all the chunks are finished I need to do some cleanup like closing the output file and so on.

Right now I am starting up and shutting down the executor service for every work item (the soft shutdown allows all chunks to complete). That’s obviously wasteful. Next I will pivot to keeping the thread pool open and using the futures or a countdown latch to track when the work item is actually complete so I don’t have to shut it down every work item.

It would be desirable to allow multiple work items in flight on the thread pool at a time. Obviously there are some ugly solutions to that like a separate thread that does the coordination for a work item but is there a pattern I can use here so that the chunk worker threads themselves can see that they’re the last chunk remaining and just close the file?

What I am thinking is using the countdown latch and having the await() inside the chunk worker thread... but I don’t want every thread to await since that would deadlock the pool. In fact even having one thread per work item block could potentially deadlock the pool.

Is the pattern I’m looking for to decrement the countdown latch, then afterwards check the value of the latch and if it’s 0 then you’re the last one and close the file? Not quite sure how to do that without adding a race where two threads decrement it at nearly the same time and both try to close the file. I don’t think closing a file that is already closed is an error for this specific case, but as to the more general question, is there a way to make sure the cleanup block is executed exactly once? Ideally without resorting to a synchronized block?

What I really want is for the countdown latch’s countdown() method to return the value of the latch after the call... which would prevent the possibility of a race condition letting two threads run it.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Since you're not actually wanting to synchronize threads with each other or control access to a shared resource, using a CountDownLatch is way excessive for what you need. Just use an AtomicInteger.

Java code:
AtomicInteger chunksRemaining = new AtomicInteger(numberOfChunks);

// At the end of each task
if (chunksRemaining.decrementAndGet() == 0) {
  doFinalCleanup();
}

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
Alternatively, especially if you're already exposing a ListenableFuture to whatever code is consuming this, you could just use the future transformation stuff:

code:
return Futures.whenAllComplete(individualChunkFutures).call(this::doFinalCleanup);

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
hello0 java goons i've been going thorugh jetbrains academy which should be renamed brokebrain academy because I am enjoying Java alot, as it reminds me of C# compared to the javascript and php I write in.

That said, I am wondering if any of you know of a better learning resource preferably book form to learn this wonderful(?) language? I feel like i'm learning more about obtuse logic problems with jetbrains than the actual programming language itself

Thanks :)

RandomBlue
Dec 30, 2012

hay guys!


Biscuit Hider

Empress Brosephine posted:

hello0 java goons i've been going thorugh jetbrains academy which should be renamed brokebrain academy because I am enjoying Java alot, as it reminds me of C# compared to the javascript and php I write in.

That said, I am wondering if any of you know of a better learning resource preferably book form to learn this wonderful(?) language? I feel like i'm learning more about obtuse logic problems with jetbrains than the actual programming language itself

Thanks :)

https://www.baeldung.com/ is really good and has a lot of good basic tutorials and guides for "how do I do X". Start here for basic Java stuff: https://www.baeldung.com/java-tutorial

Effective Java is a good book that gets recommended a lot but it's less a java tutorial and more about specific solutions/patterns/best practices.

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
Sweet i'll check those out, thank you!

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
Hey I have another quick question since Googling is giving me like ten answers...

What framework should I look into if I want to dabble with GUI programming? I know "no one uses GUI's anymore" seems to be reddit's take, but I have a soft spot for them in my heart ever since VB.net and would like to atleast mess around with it.

Also, if you know of a good tutorial for that framework (is that the right word?) i'll take that too. Thanks :D

Andohz
Aug 15, 2004

World's Strongest Smelly Hobo

Empress Brosephine posted:

That said, I am wondering if any of you know of a better learning resource preferably book form to learn this wonderful(?) language?

I used Head First Java and it worked for me. Caveats include: it's from 2005 so uses Java 5, the style doesn't jive with some people, some of the examples were kind of hard to follow and some didn't work because I was using Java 14 and didn't know better.

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
I usually enjoy the head first books I should check that out.. I've been plowing through jetbrains academy still. I think i'm learning stuff which is good. Java is a cool language.

1337JiveTurkey
Feb 17, 2005

As far as Java GUIs go, Swing has been updated somewhat so that some of its classes use generics and single method interfaces. That's actually a nice feature that makes it a little bit more nice to use but is long after Java's heyday on the desktop. As far as using it goes, I'm not a big fan of GUI builders and suggest writing well-structured code to actually organize stuff rather than one big autogenerated block.

Something that makes a difference is that there's default models that can be used to back GUI objects but they are mainly useful for demos and other stuff where you don't have real data. Making your own implementations of those interfaces that directly reference your data are much, much easier than trying to cobble together some other classes that manipulate your real data to match the model object.

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
Yeah that makes alot of sense. I started dabbling with the Swing and it's fun. It's a shame I guess that web apps killed most desktop apps but I guess I just have a weird nostalgia for software

1337JiveTurkey
Feb 17, 2005

It's not exactly GUI but if you want another sort-of GUI framework that's Java-based look at GWT or Google Web Toolkit. Like all great Google projects it's technologically mindboggling in some ways (at least for the time) and no longer supported by the company. It's making a UI in Java with most everything working the same as on desktop, but then transpiled into optimized javascript and run in the browser. It's very good at making single-page apps but can also do multi-page webapps.

edit: I'm also a big GUI nostalgia fan.

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
I didn't know that existed, I'm going to check that out for sure.

When I worked for Disney in their ticketing department , their entire ticketing system was a Swing application IIRC which is kinda cool in retrospect.

I guess if I want to take this seriously I should learn Spring but dammit let me make fake GUIs!!!

Paul MaudDib
May 3, 2006

TEAM NVIDIA:
FORUM POLICE
you obviously shouldn't use this for anything serious but lanterna is kinda lol, it's basically curses for java, lets you do text-mode interfaces on the console

https://github.com/mabe02/lanterna

Empress Brosephine
Mar 31, 2012

by Jeffrey of YOSPOS
Lmao that rules. Java is cool.

RandomBlue
Dec 30, 2012

hay guys!


Biscuit Hider
JavaFX is the current GUI framework for Java: https://openjfx.io/

Objective Action
Jun 10, 2007



I'm actually working on a project right now that uses JavaFX's WebView as an Electron alternative where the widgets are all Angular/HTML5 and bind back to Java processing code via the JSObject bindings. But then again I am a crazy person.

If you are interested in GWT there is a community maintained fork on GitHub but there is also a fork that still has free usage options and some more modern features in Vaadin that is maintained and used by a social network company in Germany.

RandomBlue
Dec 30, 2012

hay guys!


Biscuit Hider

Objective Action posted:

I'm actually working on a project right now that uses JavaFX's WebView as an Electron alternative where the widgets are all Angular/HTML5 and bind back to Java processing code via the JSObject bindings. But then again I am a crazy person.

If you are interested in GWT there is a community maintained fork on GitHub but there is also a fork that still has free usage options and some more modern features in Vaadin that is maintained and used by a social network company in Germany.

Interesting. Why did you opt for this over Electron with a Java back-end? That's what I'm working on primarily right now.

Objective Action
Jun 10, 2007



For that project they already had a large existing GUI codebase in Java. 1M+ lines with copyrights 1987-2021. By taking the JavaFX path we could use the Swing panel interop to start transitioning pieces and parts in the existing deployment without needing to do a greenfield re-build.

That project also has some specific deployment requirements around packaging, runtimes, and target OSes that made it much easier to stay entirely in the Java ecosystem so we could keep the same footprint.

Overall it was actually quite a bit less painful than I feared. The only notable problem vs. electron, other than missing all the nice integration and tooling, is that the Webkit engine JavaFX uses doesn't compile with WebGL support. If we ever need to use that I will either have to compile and build the bridges myself or, more likely, switch to the Java Chromium Embedded Framework.

smackfu
Jun 7, 2004

Everyone makes fun of Java UIs than works in IntelliJ all day and says how awesome it is.

Splinter
Jul 4, 2003
Cowabunga!
I'm working on a Spring REST API (with Spring Data as well) and am wondering if there's any "best practice" approach for securing PATCH routes, in terms of limiting which fields for a given Entity are able to be PATCHed. I don't want to completely limit the field from being updatable (which can be done via an Entity's @Column annotation), just which fields are updatable via the PATCH route (as some fields need to be updatable internally by the app, but shouldn't ever be touched by a user of the API). We're using the JSON Patch format to define PATCH operations if that's relevant.

The 2 main ideas I had for how to approach this are:
- Use a DTO that only exposes user-updatable fields, apply the JSON Patch ops to the DTO (which will do nothing if a field not present in the DTO is attempted to be patched), then convert to an Entity and save.
- Have the Entity maintain which fields are user-updatable (e.g. via a Set of fields or perhaps custom annotation), and validate all PATCH operations against those fields before applying them.

Thoughts on which will work best long term? Any other options to consider, or built-in ways of handling this that I'm missing?

Love Stole the Day
Nov 4, 2012
Please give me free quality professional advice so I can be a baby about it and insult you

Splinter posted:

I'm working on a Spring REST API (with Spring Data as well) and am wondering if there's any "best practice" approach for securing PATCH routes, in terms of limiting which fields for a given Entity are able to be PATCHed. I don't want to completely limit the field from being updatable (which can be done via an Entity's @Column annotation), just which fields are updatable via the PATCH route (as some fields need to be updatable internally by the app, but shouldn't ever be touched by a user of the API). We're using the JSON Patch format to define PATCH operations if that's relevant.

The 2 main ideas I had for how to approach this are:
- Use a DTO that only exposes user-updatable fields, apply the JSON Patch ops to the DTO (which will do nothing if a field not present in the DTO is attempted to be patched), then convert to an Entity and save.
- Have the Entity maintain which fields are user-updatable (e.g. via a Set of fields or perhaps custom annotation), and validate all PATCH operations against those fields before applying them.

Thoughts on which will work best long term? Any other options to consider, or built-in ways of handling this that I'm missing?

What I've seen in companies is the first of the two ideas you mentioned, except instead of updating they just replace (delete and create a new one). Though, the internal ID is meaningless for those things in the situations I've seen it done so it's okay to replace instead of update.

Brain Candy
May 18, 2006

smackfu posted:

Everyone makes fun of Java UIs than works in IntelliJ all day and says how awesome it is.

JetBrains products run on a modified JRE callled the JBR because they were that mad at the font support. It's still bad OP.

Data Graham
Dec 28, 2009

📈📊🍪😋



Yeah PyCharm's got some goofy-rear end ideas of how keybindings and such are supposed to work in macOS. Scrolling and searching in the Terminal pane feels like I'm having a bad dream where I scream but nothing comes out and every button I try to press gets further and further away

FateFree
Nov 14, 2003

Well I'm at the end of my wits here, trying to create Java classes from a WSDL file using wsdl2java. Its complaining about : Two declarations cause a collision in the ObjectFactory class, which I understand is some sort of conflict in the way these elements are named. Unfortunately the stack trace doesn't tell me where this collision happens, and the WSDL is giant. I don't really know what to do to get past this. Does anyone have any ideas?

Here is the wsdl file if you want to try it out like a psychopath:
http://api-apiint.brinkpos.net/Settings.svc?wsdl

adaz
Mar 7, 2009

FateFree posted:

Well I'm at the end of my wits here, trying to create Java classes from a WSDL file using wsdl2java. Its complaining about : Two declarations cause a collision in the ObjectFactory class, which I understand is some sort of conflict in the way these elements are named. Unfortunately the stack trace doesn't tell me where this collision happens, and the WSDL is giant. I don't really know what to do to get past this. Does anyone have any ideas?

Here is the wsdl file if you want to try it out like a psychopath:
http://api-apiint.brinkpos.net/Settings.svc?wsdl

I'm not 100% sure this is it but i'm.. reasonably certain that your import here:

<xsd:import schemaLocation="http://api-apiint.brinkpos.net/Settings.svc?xsd=xsd0" namespace="http://tempuri.org/"/>

Pulls in this file: http://api-apiint.brinkpos.net/Settings.svc?xsd=xsd0 which has almost all the ops duplicated _and_ in the same namespace

FateFree
Nov 14, 2003

adaz posted:

I'm not 100% sure this is it but i'm.. reasonably certain that your import here:

<xsd:import schemaLocation="http://api-apiint.brinkpos.net/Settings.svc?xsd=xsd0" namespace="http://tempuri.org/"/>

Pulls in this file: http://api-apiint.brinkpos.net/Settings.svc?xsd=xsd0 which has almost all the ops duplicated _and_ in the same namespace

Well I gave it a shot by removing that and it complained about some missing types.. HOWEVER if you check out that file it is importing this:
<xs:import schemaLocation="http://api-apiint.brinkpos.net/Settings.svc?xsd=xsd2" namespace="http://schemas.datacontract.org/2004/07/Pos.Web.Service.Data"/>

which is already in the original file. So maybe they are double importing everything? I guess I can try changing these imports to file based and remove them?

EDIT - I got it. When I converted the xsds to files, I got a line number from the codegen plugin. It was some EmployeeJobs element on like the 4th import that caused the problems. Thanks for giving me some direction!

FateFree fucked around with this message at 01:04 on May 21, 2021

Harriet Carker
Jun 2, 2009

Hey ya'll - I just accepted a new job offer and am making a transition from five years of React/JS front-end development to Java. The OP is super old - are there any recommended resources for Java beginners with programming backgrounds? I like physical books and structured courses the best. I obviously need to learn the syntax but I'm also curious about best practices, directory structure, testing, etc.

smackfu
Jun 7, 2004

If you don’t like super old, Java might not be the best choice for you.

Twerk from Home
Jan 17, 2009

This avatar brought to you by the 'save our dead gay forums' foundation.

dantheman650 posted:

Hey ya'll - I just accepted a new job offer and am making a transition from five years of React/JS front-end development to Java. The OP is super old - are there any recommended resources for Java beginners with programming backgrounds? I like physical books and structured courses the best. I obviously need to learn the syntax but I'm also curious about best practices, directory structure, testing, etc.

What environment are you doing Java in? Is it maintenance + extension of applications from the same era as the OP, because keeping those projects internally consistent is probably what you'll be doing. Are you doing Android development? Android Java got stuck somewhere between Java 7 and 8, so Java for Android is similarly out of date.

If you're doing modern small services with a widely-used framework (Spring Boot, Dropwizard, Quarkus, Micronaut), then you could just stand up one of those from any of their project initializers and explore your way around that.

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.

Twerk from Home posted:

If you're doing modern small services with a widely-used framework (Spring Boot, Dropwizard, Quarkus, Micronaut), then you could just stand up one of those from any of their project initializers and explore your way around that.

I'd go this route. Spin one up and create an endpoint or two, do some serde, mess with ORM of your choice, pull in a few free AWS service libraries to toy around with even maybe? Wire it all together with Guice or another DI framework of your choosing (maybe Spring Boot includes DI? I've never used it).

Twerk from Home
Jan 17, 2009

This avatar brought to you by the 'save our dead gay forums' foundation.

Good Will Hrunting posted:

I'd go this route. Spin one up and create an endpoint or two, do some serde, mess with ORM of your choice, pull in a few free AWS service libraries to toy around with even maybe? Wire it all together with Guice or another DI framework of your choosing (maybe Spring Boot includes DI? I've never used it).

Spring boot, Quarkus, and Micronaut all include a perfectly acceptable DI framework, and I'd use the out of the box solution as much as possible. If you want an actual small project to do that's motivating, you could use Spring Boot, Quarkus, or Micronaut to make a slack bot: https://slack.dev/java-slack-sdk/guides/supported-web-frameworks

If you want to take something primitive and make it better, you could give me a hand on the Somethingawful Slack integration that I've been toying with, PM me for details. It's spring boot and at 3 hours in, I considered it "shipped" because it can expand the text of SA posts in slack.

Good Will Hrunting
Oct 8, 2012

I changed my mind.
I'm not sorry.
Good to know! I've been in Scala world for 4+ years now, and use Finatra + Guice. Used to use Dropwizard with Guice but I think DW has out of the box DI now too.

Thanks for those suggestions though. I'm
Interviewing soon and will have some take-home assignments I'm sure.

Adbot
ADBOT LOVES YOU

Harriet Carker
Jun 2, 2009

Twerk from Home posted:

What environment are you doing Java in? Is it maintenance + extension of applications from the same era as the OP, because keeping those projects internally consistent is probably what you'll be doing.

Good question! I'll be on the AWS S3 team, so I suppose it could quite possibly be from the OP era.

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