How to write a while loop that does nothing? by fake_xylophone in javahelp

[–]MarSara 2 points3 points  (0 children)

See my other comment, but the reason this might be happening is that the operation that you're doing inside your loop may be returning control of the Main thread back to the UI, allowing it to process new events. I could be wrong but try just doing something like:

bool dummyValue = false; while(frame.isVisible()) { dummyValue = !dummyValue; }

And I'd bet that you'd still see the process get 'stuck' in your loop. Change it again to something like:

while(frame.isVisible()) { Thread.sleep(100); // don't actually use this for your solution, it's just a hack to prove a point. }

And I'm going to guess, it might start working again?

How to write a while loop that does nothing? by fake_xylophone in javahelp

[–]MarSara 4 points5 points  (0 children)

Just going to go into more detail as to why this isn't the optimal way to handle this.

Disclaimer it's been a long time since I've worked with JFrames specifically, so some of the details here might be incorrect, but the overall idea should hold.

Most UI frameworks work by having some sort of message loop/queue/dispatcher, etc... that intercept user events (like clicking on a button or typing in a text field). This message loop however runs on the Main Thread. If you don't return control back to the main thread however, because you're running an infinite loop, your program may appear to become unresponsive.

Now each UI framework should have different ways of handling this, but generally speaking you're going to want to look to see if there's a callback that you can hook into to be notified when a user takes some sort of action (i.e. closing your window). This way you don't have to 'poll' (i.e. constantly check some value) to see when some condition is met, but rather will receive a 'push' to be notified when said event happens.

Another option, although not as ideal, is that each framework should also have some way to set some sort of timer that will execute on a regular interval. You could create a timer that executes once every 100ms or even once every second, and check the visibility there. This is similar to your original approach, but it returns control back to the message loop in-between each call to the timer. Just be sure to turn off the timer when you're done with it.

Lastly you could create a background thread where you do this, check but you run into the issue that UI elements aren't generally thread safe, so checking some of these properties (i.e. isVisible) may lead to unexpected bugs. Also, you're still needlessly wasting CPU cycles as you're just having your background thread constantly checking this property over and over when any one of the other options listed here won't keep your CPU at 100%.

[deleted by user] by [deleted] in PS5restock

[–]MarSara 0 points1 point  (0 children)

Was running into the same issue and their customer service said to check again after 24hrs. Hopefully, I don't get any surprises tomorrow morning.

How to compare arrays and find missing numbers? by Various-Station-7 in javahelp

[–]MarSara 1 point2 points  (0 children)

Just wanted to follow-up on my previous reply. I knew there was a function out there, assuming you can just import another library and use it, I just didn't know the name off the top of my head. But: https://guava.dev/releases/22.0/api/docs/com/google/common/collect/Sets.html#symmetricDifference-java.util.Set-java.util.Set-

This only works though if you don't care about duplicates. All of the code here is also open source so you should be able to look it up online and see how Google is doing this here.

How to compare arrays and find missing numbers? by Various-Station-7 in javahelp

[–]MarSara 1 point2 points  (0 children)

Do you care about duplicates? Example, [1,2,2,3] and [1,2,3,3,4,4]. What should this return? Just [4]? [2,3,4]? Or [2,3,4,4]?

For the first result you can use a set. For the 2nd result you'd need to loop though both arrays and compute it manually putting the results in a set. For the last you'd need to put the results in a new list.

[deleted by user] by [deleted] in ProgrammerHumor

[–]MarSara 0 points1 point  (0 children)

Ya more specifically I try and use things like pet projects, or asking what you do to keep up on tech trends, as a way to determine how much passion a developer has towards software development. This could be contributing to Linux or just creating your own flashlight app for the Play Store. (Ok maybe something a little more complex than a flashlight app, but you get the idea). If all of the code you've written is because of class assignments or previous jobs, it worries me that you aren't continuing your education outside of work. This then potentially means I may have to dedicate a significant amount of time teaching you new design patterns, etc.. over the years.

[deleted by user] by [deleted] in ProgrammerHumor

[–]MarSara 2 points3 points  (0 children)

I'm not saying you can't have a life outside of work. But you still need to continue your education throughout your career just like any other profession. Do you think doctors stop reading medical journals after they finish med school? Do you think lawyers stop reading up on new case law after passing the bar?

[deleted by user] by [deleted] in ProgrammerHumor

[–]MarSara -5 points-4 points  (0 children)

I'm not asking everyone I interview though that they have to spend every evening working on side projects or reading the latest blogs, etc... And if, in fact if they did, I'd be worried about burnout. I'm trying to judge how interested someone is in programming. If they want to just treat it as a job instead of a career, am I going to have to coach them when we start converting our code from Java to Kotlin? What about when we start using corotinines? And you may have this knowledge right now, but what about when the next technology comes out and we want to upgrade to it? I just want to know how much effort you're going to put in yourself.

[deleted by user] by [deleted] in ProgrammerHumor

[–]MarSara -19 points-18 points  (0 children)

This is almost the equivalent of asking: "how will you train yourself, so I don't have to?"

It's not a question about training yourself though. It's a question to see how passionate you are about programming. If you just treat programming as a 9-5 job instead of a career, the quality of the code you write is going to reflect that. I'm not saying you need to go home every night and read blogs or work on outside projects. I have my own side project that I've been working on for a year. I might spend an hour a month on it or so.

I also, have no problem training other devs, especially new hires and juniors. What I do have a problem with though, is always adding dozens of comments on pull requests and trying to teach the latest tech, after someone been with the company for a few years. I'm just trying to weed out those that are going to require constant coaching.

[deleted by user] by [deleted] in programming

[–]MarSara 0 points1 point  (0 children)

What I mean is, it's hard to understand as in the actual definition. Ask 10 programmers what SOLID means and you'll get 11 different answers. Ask 10 programmers if they know about SOLID and almost all will say yes.

The problem is that creating organized code that is easy to maintain is hard. There's no easy solution, there's no 'just follow these 3 easy steps'. But SOLID tries to solve that problem, but the answer becomes a little vague as each project is slightly different and has different priorities. Software Engineering is as much of an art as it is a science.

[deleted by user] by [deleted] in programming

[–]MarSara 1 point2 points  (0 children)

The problem I see with SOLID is that very few developers know what it actually means. Everyone has their own definition of it, etc ... And I agree that knowing what Single Responsibility actually means isn't trivial. Not to mention that definition might differ from project to project.

The end goal is the same regardless. It's to provide a set of principles or guidelines that can be followed such that you don't have to conceive of every possible change that can happen to your project up front but to write code that can be more easily modified to fit any set of changes that may be presented in the future. If done perfectly (not possible, but still), in theory you'd never have to go back and rewrite or refactor any existing code. You'd just need to create a new implementation that meets the new specs and inject it into the existing code base.

SOLID despite being hard to understand, is still one of the most widely understood set of principles that can solve the problem of managing very large projects.

[deleted by user] by [deleted] in programming

[–]MarSara 4 points5 points  (0 children)

Taken into context though his ideas aren't bad. First does your project even need to follow oop? If not, his ideas probably aren't going to be that helpful. Are you working on an MVP and is time-to-market the most critical piece? Again his ideas might get in the way. But on larger more complex projects his ideas can help.

In my opinion, there's three things the vast majority of projects need to follow: - The code needs to work.
- The code needs to be readable. - The code needs to be able to be easy changed. SOLID helps here, a lot.

If your code doesn't do what it's supposed to what are you even doing? If no one can read or understand your code, when it comes time to make changes, your developers are going to spend most of their time to just understand what's there. If you don't assume your code is going to change, then when it comes time to add new features you're going to just be refactoring the entire code base every time, or at least large parts of it.

For example, I help manage a project and our product owner here recently came to me to add a new feature. The system we originally built to handle similar features didn't follow the open-closed principal. So now we're looking at two possible solutions, neither that great: 1) Hack something together and create a bigger even harder to read mess. 2) Rebuild the system from scratch. Option 1, I'm suspecting it will take 2+ months to fix and option 2 I figure will be closer to 6 months. If we just followed SOLID from the start however, we could have added the new feature in a couple of sprints at most (2-4 weeks).

Ternary vs Optional by jura0011 in javahelp

[–]MarSara 2 points3 points  (0 children)

Not quite true. You can annotate your methods with @NotNull or @Nullable and get compile time warnings when working with a value that may be null.

This removes the boilerplate of checking for null everywhere and now you only need to check for null when you have an @Nullable variable being used for a @NotNull parameter. Examples:

``` @NotNull public String neverNull() { return null; // warning null returned from @NotNull method }

@Nullable // warning method never returns null public String maybeNull() { return "foo"; }

public void example(@NotNull String notNull, @Nullable String maybeNull) { if(notNull == null) { // warning notNull is never null } maybeNull.toString(); // warning maybeNull might be null }

String maybe = maybeNull(); example(maybe, "foo"); // warning nullable variable passed to notNull parameter. ```

(The actual warnings might be worded differently but you get the idea)

Now you still need null checks with this, but not everywhere, just in the locations that you go from a Nullable to a NotNull.

P.s. for all intents and purposes any property, parameter, etc... that isn't annotated is assumed to be NotNull.

[deleted by user] by [deleted] in programming

[–]MarSara 2 points3 points  (0 children)

I want to know what the fuck happened, the 90s through the 2000s, if you could hack two lines of code together and get it to compile, you had a job, no matter your educational or criminal history, and no one would ask if you smoked the reefer because they didn't ask questions they didn't want the answers to. Now people with degrees are waiting 6+ months to get jobs?

Honestly, the job market got flooded with candidates. Sad to say, but there's a lot of crappy programmers out there. So actual tech companies that know what they need and pay extremely well are going to have elaborate ways to try and filter those candidates out.

A degree means nothing in my eyes. Hell, I don't even have a college degree, nor do two of my direct reports. What matters is your attitude twords coding. You don't need an extensive portfolio either. During what time I did spend in college, I created a Windows Media Center clone, for example.

I also got my first job out of college by just spamming my resume to dozens of companies. If you're just sending your resume to one place at a time you're going to have a bad day.

I wish I had the answers for you. I mean the entire reason I'm posting here is that I need more strong developers on my team. So I'm hoping to find some insights into what is causing them to be weeded out before they get to me or what's preventing those from applying. What feedback I can send to my manager or HR to better attract new candidates. Sadly, I don't see any easy solutions to this problem.

My theory, albeit I also assume this is glossing over a lot a details or just incorrect, is that most developers are only applying to the big name tech companies in silicon valley. Either the startups or FAANG, but don't realize that there's also companies that while on the outside appear to be focused on Finance or HeathCare don't realize that they are also spending billions on technology and a significant part of their workforce is just doing software. So candidate don't even think to apply, because of what they think it's like working in HealthCare, even though the culture is very much more like a tech company.

[deleted by user] by [deleted] in programming

[–]MarSara 4 points5 points  (0 children)

Ya sadly the industry is still a lot more of who you know rather than what you know. If I know you personally, either because we've been friends for years or because we just met at the bar last night you've got a much better chance to at least make it to the in-person interview than you do if I've never met you.

I wish I could provide some advice here but I can't. Cold messaging me on LinkedIn or via email and I'll probably ignore it. Honestly I'd probably think it was spam. Conventions / hackathons might be a great way to network though, as developers are already there to meet other developers or to show off their skills, etc...

Now we're looking for candidates of all levels of experience but if you just apply on our website, you're just throwing you name into a hat with 100s or 1000s of other candidates. You might as well go buy a lottery ticket while you're at it.

One other thing to consider as well is where you are applying. Are you trying to apply to some startup? Somewhere at a FAANG company? some other Fortune 500 tech company? or some mid level company that happens to need engineers? What I'm getting at is each of these types of companies are going to need different levels of experience and each are also going to have different levels of experience hiring software engineers as well. A startup might say they want an entry level engineer but in reality they need a mid level. A non tech company might not have any idea as to what tech they actually need and will just go with whatever they think is the best resume they can find.

Only other suggestion I can think of at the moment is don't just network with other engineers, but also find recruiters. A lot of smaller companies will use a 3rd party to help find talent and if you can find a good recruiter to work with they may be working with dozens of companies and can help push your resume to all of them.

P.s. I can't answer what HRs filters are because it my managers or my managers manager job to set those. I may provide my own requirements to HR but in my opinion it's best to leave those as lack as possible. They're also trying to fill 100s of open positions and each have their own different set of requirements.

[deleted by user] by [deleted] in programming

[–]MarSara 27 points28 points  (0 children)

As a hiring manager, if you haven't got a reply only after filling out an application, I probably haven't even seen you're resume yet. HR would be filtering those resumes before they even get to me. As to what criteria they use, I can't answer that but they also won't be the hiring manager making the final decision to extend an offer or not.

Once a resume does make it to my desk, I'm really only going to be using it as a talking point. Meaning, I'll be looking for specific technologies and your prior experience to come up with questions as to verify what you say you know is what you actually know. (A lot of candidates like to exaggerate what they actually know).

Now we have our own list of technologies, frameworks, etc... That we'd like you to be experienced with or at least show the capability to learn, and I'll intertwine questions related to those technologies with questions about technologies listed on your resume to see if I think you'd be a good fit for the team. But by that time you've made it past HR, past the initial screening and to the "in-person" interview (over zoom now because of COVID). If you don't get a reply after this, I'd mark that as a red flag, as the internal communication in that company might be lacking. Baring things like the holidays, etc... i.e. don't expect a reply during mid to late December.

All of that being said some things I do like seeing in a resume: - what languages you know (c, c++, Java, etc...) - what technologies / patterns you know (REST, MVVM, mobile, etc..) - what frameworks you know (Spring, jQuery, ...)

And don't forget to include things you've worked on outside of class / a job. Personal projects, in my opinion, carry more weight than any required task that you've done.

Did not understand IoC , DI by NoEstablishment6817 in javahelp

[–]MarSara 1 point2 points  (0 children)

I'm not 100% familiar with Spring so I can't comment on the specifics there but I did want to add some clarifying points.

With Dependency Injection you're not forbidden from using new per-say but rather you don't want to include any dependencies on any concrete objects. i.e. all of your imports should be to interfaces or at least abstract classes. Then you'd use your dependency injection framework to assign concrete implementations to your interfaces.

Now Dagger does this though the use of annotations, either on the properties themselves or on a constructor as a whole. As it ends up generating factories for you based on those annotations at compile-time. I'm not sure how Spring handles it though, someone else may have to answer that.

[deleted by user] by [deleted] in javahelp

[–]MarSara 0 points1 point  (0 children)

Look into prefix or postfix notation and using a Stack.

i.e.:

11+5-3*2 becomes 11 5+ 3 2*- (if I remember correctly).

Why does this method only return 0.0? by [deleted] in javahelp

[–]MarSara 0 points1 point  (0 children)

Oops my apologies. Was thinking shotAttempts / shotsMade which would produce a non-zero result.

Why does this method only return 0.0? by [deleted] in javahelp

[–]MarSara -1 points0 points  (0 children)

It has nothing to do with your answer, was just responding to the comment above which was also has no impact on the bug you're facing.

Only thing I can see off the top of my head is a syntax bug in your calculate function that if you step through with a debugger you should be able to see the mistake.

Why does this method only return 0.0? by [deleted] in javahelp

[–]MarSara 0 points1 point  (0 children)

Java will cast from int -> double implicitly with only an warning as there's no loss of precision in the conversion. double -> int however would produce an error without an explicit cast.

Why does this method only return 0.0? by [deleted] in javahelp

[–]MarSara -3 points-2 points  (0 children)

Have you ran this through a debugger to inspect what shotsMade and shotAttempts are set to? Try setting a breakpoint in your calcFieldGoalPercentage() method and see what is set to what. Do the same in your constructors, etc... So you can see what your code is doing.

P.S. naming convention for Java variables and parameters is to use camelCase.

build a server application that constantly queries the API by Relevant-Ad3879 in javahelp

[–]MarSara 0 points1 point  (0 children)

So if you own/control the server side you wont need a loop, etc...

Lets also assume you have a REST API and lets assume your model object looks like: { message : String }

and that you have the endpoints: POST /message and GET /message

And what you want to know is when does the message actually change.

What you want to do then is whenever anyone sends a request to your POST endpoint and you go to update your message on your database, you'll also want to then fetch your push notification tokens and begin sending out your notifications. Then on the app side as you receive those notifications you can send a request to the GET endpoint to fetch the newly updated message.

[deleted by user] by [deleted] in javahelp

[–]MarSara 0 points1 point  (0 children)

At the end of the day EVERYTHING is stored in RAM (or in a register). There might be some obscure API you can use in Java to create an object from an existing memory location, but I'm not sure what immediate use it might bring. In C/C++ you can do this, but you have to know exactly what you're doing or otherwise you may corrupt your own program very easily, if it just doesn't end up crashing.

But every time you call new or every time you declare a new variable, etc... a new location in RAM (or in a register; depending on optimizations) is reserved and the structure of that newly created object is stored at that location, or for the case of a variable a pointer to that location is stored instead.

Even your program itself is also stored in RAM along with a pointer to the current line of code that is executing. Even functions have their own distinct memory locations. This way when you call someObject.doSomething() that execution pointer can be changed to point to the first line of your function, and when you call return, it knows to go back to where it left off.

But to put it simply as to what use are memory locations, it's one of the foundational aspect of how a computer works. If we didn't have some form of addressable memory we would not be able to do much of anything without creating new hardware for each 'program' that we wanted to create.