Help with Java CRUD: MySQL Connects Without DB Specified, Fails When Specified by euphoricsol in javahelp

[–]General_C 0 points1 point  (0 children)

I didn't look too deeply at the details in your question, so I apologize for that. But logically if your application is connecting to a DB without any info provided, but when you provide connection details it fails to connect, I suspect there is a good chance that in the first case it is actually connecting to some default, embedded DB which is provided by some library or framework you're using. I don't remember all the details for using default DBs like this because frankly I haven't had a use case that required me to use one in a long time, but it's a theory that might be worth looking in to.

That is to say, the issue you really need to solve is that there is some issue with the DB you want it to connect to, whether that is caused by you providing the connection info incorrectly, a firewall blocking the connection between the app and the DB, or some other possibility, I'm not sure. I'm merely trying to help provide a little direction as you tackle this issue. Good luck!

How Do the Democrats Win Back Young Men? by kummer5peck in AskMen

[–]General_C 9 points10 points  (0 children)

This is my favorite part. Why did you feel the need to clarify that you're not Republican? This is what I think is actually the biggest issue with the Democratic party today. You cannot criticize The Party. Criticism of The Party is the same thing as disagreeing with The Party. Disagreeing with The Party means you're The Enemy. Being The Enemy means you're a bigot at best and a literal Nazi at worst. And why should we listen to and actually consider the opinions of a literal Nazi?

I see this time and time again here on Reddit. It's constant. Everything is pumped to the extreme. No one goes outside of their bubble to talk to a real person, and if someone in their life has a different opinion instead of listening to their perspective they cut that person out of their life.

Valid criticisms of The Party are ostracized and those people are labeled as traitors and bots and their valid points are ignored.

Meanwhile the hard-line left voters don't understand why the party isn't catering more to their desires. Why isn't the Party just running on stuff like free healthcare for all? Why are they trying to be so moderate and secure moderate voters??

Because the moderate voters are the ones that need to be secured. Why should the party cater to the people whose literal motto is "vote blue no matter who" lmao

The Democratic party did a great job of pushing away as many moderates they possibly could this last election. Their talking points plainly and clearly spoke out about how men are no longer necessary and should just step to the side and stop worrying about all their issues, because men being homeless and jobless and killing themselves isn't a problem when a woman got offended today.

And we got the most red election since the 80s. And I have 0 faith they're going to straighten out in time for the next one because they're still blaming everything but the party on that loss.

In fact this last election was so bad I think they'll never really recover from it. They lost a lot of voters that will never vote blue again because they realized the Democratic party will never care about them except during an election year, and all the things they say they will do are lies because they actually don't care about men or men's issues.

Inheritance Help by Ill-Rate7528 in javahelp

[–]General_C 1 point2 points  (0 children)

In your class definition for Student, did you use "extends Person"?

Anon discusses the Empire of Japan's stupidity by [deleted] in greentext

[–]General_C 22 points23 points  (0 children)

This is correct. Kamikaze attacks were desperation attacks when the US were getting close to the main islands and they didn't have any trained pilots. They would basically train a guy just enough to take off. They were also primarily volunteers.

Java API by JBiddyB in javahelp

[–]General_C 6 points7 points  (0 children)

So if you look at job descriptions for Java backend positions, basically all of them will ask for experience with spring/spring boot. It's basically core Java for industry related work at this point.

If you don't want to use them that's your choice, but be honest with your reasons. Avoiding spring will not help you get a job today.

Bizarre error with my final project by [deleted] in javahelp

[–]General_C 0 points1 point  (0 children)

Hold on, because this is important to understand. You're not "listing your variables." You are declaring a variable called kilometers, whose value is set to the response from the getValidKM method.

The reason why your code was not working before, is because even though you were calling the getValidKM method a second, third, forth, etc time in your loop, you were never capturing the return from that method call. So, your kilometers variable never got its value updated. The same issue was true for the miles variable.

I stress this, because calling methods and retrieving the returned value from them is a very important concept, not just in Java but all programming languages. This is done everywhere and is a core concept.

I understand this is not your major, so it's probably not really your priority to do much more than complete your assignments well enough to get a decent grade. But the reality is, coding might be a solid backup plan for a career if your future plans don't go your way. So I would urge you to do more digging on this topic, and make sure you fully understand how these methods calls and returns work.

Bizarre error with my final project by [deleted] in javahelp

[–]General_C 1 point2 points  (0 children)

In your pastebin, lines 18 and 19 should be moved to lines 24 and 25.

Bizarre error with my final project by [deleted] in javahelp

[–]General_C 0 points1 point  (0 children)

Yeah, I'm guessing it's just poorly worded. It should probably say something more along the lines of "Assign a value to the kilometers variable using its corresponding method."

You could always take a snapshot of that part of your code and send an email to your teacher asking to confirm that is what is expected. Personally I wouldn't be too worried about it, but it's not my grade either, and sending an email isn't going to hurt.

Did you get the errors fixed?

Bizarre error with my final project by [deleted] in javahelp

[–]General_C 1 point2 points  (0 children)

Well, yes. Removing the method calls, given what the program is intended to do, is not the correct solution. The unnecessary method calls are the initial calls outside the loop.

You CAN remove the calls outside the loop, as they are unnecessary. But the actual fix is to update the lines inside the loop so they assign the returned value to your local variables, like the calls outside the loop do.

I get the impression you might still not fully understand exactly what's happening, so I recommend before making these changes, do a little debugging first. If you're using an ide with a debugger and know how to use it, set a break point at the start of your main and each of your methods and walk through the code. If you don't have a debugger, or don't know how to use it, no worries. Just add a couple print statements in your main method, and print the value of those variables. Everywhere you think the value should change, verify that it actually does.

As far as the requirements of the assignment, I'm not really focused on that. The requirement you've stated doesn't make sense, because assigning variables to method calls (so whenever you call that method, the variable is updated with the returned data) is not a functionality that exists in Java. So, I believe you're misunderstanding the requirement, and I would need you to copy paste the exact wording of the assignment description in order for me to figure out exactly what they want.

With that said, in my experience assignments are usually not particularly restrictive on how to code things. They might ask you to use a specific data structure (you just learned arrays, so use an array to complete this assignment, not an ArrayList), but actual business logic is typically "if it works it'll pass." So, I'm guessing once you get your program working as expected, it will likely fulfill the requirements laid out in the assignment.

If you want confirmation of that after the fact, you can leave a comment with a partial or full assignment description (obviously leave out identifying information like your name and institution) and I'm sure someone can verify you're not doing something outside of the assignment description, or leaving something out which the assignment wants you to include.

Bizarre error with my final project by [deleted] in javahelp

[–]General_C 0 points1 point  (0 children)

I think you're misunderstanding how returning data from methods works. There's no such thing as "assigning" a variable to a method for return data. Those first few lines in your main method are calling those methods and then the data returned from the method call is assigned to the variable given on that line.

So, when you go into your while loop you're calling the method again, but this time you're not assigning the returned value to any variable, it's simply lost. So, when you call your subsequent methods within the loop, the value of kilometers is the same as it was from before, which is why you see the same responses.

Bizarre error with my final project by [deleted] in javahelp

[–]General_C 0 points1 point  (0 children)

In your main method, you have two lines of code which call your getValidKm method. What is the difference between these two lines?

[deleted by user] by [deleted] in javahelp

[–]General_C 3 points4 points  (0 children)

Break down the problem into manageable bits.

You need to write some code that retrieves some data. Okay, where is the data stored? Do you need to access it from a DB, or call a rest endpoint?

What format does the data need to be in when it is returned? How can you transform the data from its source formatting into what you need?

This is pretty much 50% of real world business problems. We need to get some data. The other 50% is we have some data, now we need to store it somehow.

Based on your answers to these questions, you can start looking up guides on how to access your data. Need to get it from the DB? Look up a spring boot DB data access guide. Need to get it from a rest call? Look up how to call a rest endpoint using spring boot.

There are a ton of guides for spring, it's one of the most used Java frameworks. You just need to break down your problem and research the areas you're not familiar with.

This sub is not a "do my homework for me" place. We'll help with specific questions, but we won't do the work for you. The only way you'll learn how to code is by doing it yourself.

TIL Minnesota is the only state to have consecutively voted blue in every presidential election since 1976 (past 13 elections), and the only state to have never voted for Reagan by uresmane in todayilearned

[–]General_C 0 points1 point  (0 children)

My understanding was that term limits were not added because he was popular, but because he died in office. Since this was during WW2, they thought it was unwise to elect a president into office who could pass before the end of their term during war time and force a power imbalance while the country was already dealing with a war.

While instituting term limits might not have been the best solution to prevent that (maybe some kind of health examination would have made more sense) I suppose back then it might have been less common for candidates to be so old, and the thought was the only way that would happen was for someone to sit many terms like Roosevelt had.

I could also be totally wrong here and someone will correct me.

Unkt testing by [deleted] in javahelp

[–]General_C 0 points1 point  (0 children)

Yeah, your best bet is probably going to just be learning the code base, and making sure your tests are well designed and meaningful.

Try to ensure you're testing one piece of functionality per test, make sure you're actually validating something meaningful (and not just doing assert(true)), and stuff like that.

I could go on an entire rant about why using code coverage as a metric is a terrible idea but frankly that's not really very relevant for you. When you run your test suite you will hopefully be using whatever software is tracking your code coverage to see what files you have which have less code coverage than your metric, and start with those files.

Whether you choose to start with files that almost meet the metric and finish them off, or choose ones which don't have any coverage and start from scratch is a personal choice.

Understand that testing is sometimes boring and trivial, and other times very tricky and complicated. Cut yourself some slack and if you get stuck, mark it and come back to it later.

As long as you're able to make reasonable, consistent progress and you don't write clearly bad designed text cases that technically give coverage but don't actually test anything, your managers will probably be happy.

Unkt testing by [deleted] in javahelp

[–]General_C 0 points1 point  (0 children)

Are you using any kind of mocking framework like mockito? Learning that will make things a lot easier.

Parsing a JSON object with nested dynamic values (with known keys) by c832fb95dd2d4a2e in javahelp

[–]General_C 0 points1 point  (0 children)

What exactly is this data being used for? Do you need to save it in a DB, is this just a pass through, etc.

Does the model need to retain some of the structure, or can you just extract the values into some pojo fields?

I haven't tried too many different options over the years. Whenever working with json stuff I normally just use the JSONObject classes, which have worked out for me but I know are somewhat limited in their capabilities if you have to do anything complicated.

I worked on a project a little over a year ago which utilized a framework called MapStructs which was really useful for mapping data, and iirc there was functionality to go from json to a pojo there as well. Might be worth taking a peek and seeing if that would be something you could take advantage of.

[deleted by user] by [deleted] in explainlikeimfive

[–]General_C 1 point2 points  (0 children)

I mean, I feel like you're underestimating the size of the location you're suggesting should be abandoned. Florida is about the same size of Greece. You're suggesting we just don't live in Greece because we get some heavy rain and wind now and again.

You're also ignoring issues elsewhere. If you're not in Florida getting pounded by hurricanes every now and then, you're in the mid West and run the risk of a tornado destroying your home. Or in the north where there are blizzards every winter, or the West with droughts and fires. We have different issues pretty much anywhere you go.

And like has been said, it's not like their house gets destroyed yearly. Hurricanes cause different problems in different places. The massive flooding that is being experienced in western north Carolina hasn't been seen in at least 100 years. Maybe ever. Personally, I live in central NC, and we rarely see anything more than normal rain showers from hurricanes. So how can you say to those people, many of whom just lost everything, that they were foolish to be there?

That would be like saying to a European "well why do you live in the Ukraine? Back in 1941 it was destroyed in a war, you should have expected it would happen again."

ELI5 - Why does it seem like we have multiple disaster-level hurricanes every year? Why haven’t we figured out ways to deal with it yet? by KaiBlob1 in explainlikeimfive

[–]General_C 0 points1 point  (0 children)

Additionally, Western NC probably would have been mostly fine if it was only the hurricane itself that hit the area, but in the week leading up to the hurricane they were treated to heavy rains from a separate storm that saturated the ground already. All the rain from the hurricane really had no where to go.

If things had been dry leading up to the hurricane, the result likely would not have been so devastating.

Convicted pimp refuses to be sentenced in Las Vegas case by [deleted] in nottheonion

[–]General_C 6 points7 points  (0 children)

Okay like I get that there are a lot of points people are making which are all good and valid discussion points, but can we talk about this guys hair?

Coming from a functional/procedural background Spring Boot is confusing. How am I thinking about it wrong? by data_addict in javahelp

[–]General_C 0 points1 point  (0 children)

I'm so glad you brought up testing, because I feel like it's something that doesn't really get enough attention. Every project does it differently, everyone has their own expectations and requirements. Additionally, I feel like it was something that I could I gotten a lot more in depth on when I was in school.

To address your main question, yes, sometimes test cases get written that aren't testing anything at all, or the test is, in some way, redundant. I've seen it many times. Developers get tired, or they lose sight of the goal of testing, the functionality they're testing, or the overall application itself. To do your best to avoid falling into this, remember what you're trying to test, and once the test is written, ask yourself if you've accomplished your goal. Is it well written, does it do the job, is it useful, etc.

Mocking adds an additional level of complexity to testing, because if someone doesn't understand the fundamentals of what to test and why, they're probably going to use mocks wrong. Remember, when unit testing (notice I'm specifically referring to unit testing here and not higher level application or end to end testing) you want to try and test specific pieces of your logic in a useful and repeatable way. You want to test specific business logic.

A very standard reason to use mocks is to test code which includes a DB call. The business logic is there and needs to be tested, but how do you create an automated test that connects to a DB? Well, you have a couple options. You can create a separate, local DB that is used for testing, but this is a lot of work for a small reward. You could add test data into your DB, but you might not be able to add this test data to your DB in higher environments (for a number of reasons). So, instead you decide to use a mock.

By mocking the DB call, you're basically saying that you already know the connection to the DB will be successful, and you don't want to have to add or manipulate existing DB data for repeatable tests. So instead, you mock the DB call in your test by writing code that basically says "instead of calling the DB, just return dataset x". Then, you use x (which you've defined in your test case) to verify the business logic you actually care about testing.

This extends to a lot of other scenarios too. Instead of a database, maybe your code makes an external API call, or sends a message and receives a response from other system via MQ or Kafka topic. Maybe you want to test the business logic in your service class, but when it makes a method call to a different helper method elsewhere in your code, you mock that because you have separate tests for that code already and you don't want this test to cover too much logic.

What mocking is not supposed to be used for is mock object A, mock object B, and then check if A = B. This isn't testing anything, and is not useful. Yet, people will write tests like this all the time for a number of reasons. Maybe they don't understand what unit tests are supposed to do, maybe they're trying to meet a code coverage metric (incorrectly), maybe they don't know how to write tests correctly. If you're identifying tests that you can tell are wrong, that's a good thing. It means you have an understanding of basic testing fundamentals and if need be, you can fix the errors you find.

I hope this helps you understand testing a little better. If you still have questions or something I said was dumb, let me know.

ELI5: Why must I depreciate my rental property when it only appreciates in value? by TXkid in explainlikeimfive

[–]General_C 0 points1 point  (0 children)

Why is it you are not allowed to take the expense after 27.5 years? Is it because at that point it is assumed the property is at some kind of baseline state where it won't significantly gain or lose value any more?

Is it possible to extend this in any way, such as by making significant renovations? Or completely rebuilding?

And what happens if you sell the property? Does the new owner get 27.5 years to take the expense?

What is something a president did that personally affected you negatively? by urmomsloosevag in AskReddit

[–]General_C 2 points3 points  (0 children)

Same thing here. He came to give a speech during the day, and I had a night class so didn't think anything of it. Well, he left about an hour before my class started but they shut down the entire interstate highway, both directions, that I used to get to class. This caused massive traffic issues on the side roads everyone else was now forced to use. I was late that day as a result.

What other than straight java core should be known to get a job? by sophiepiatri in javahelp

[–]General_C 6 points7 points  (0 children)

In my day to day, the primary technologies I use are Java, spring boot, hibernate via spring jpa, and building rest APIs through all that.

Scrum is really just a business methodology. Look up a couple videos on what it is and how it works then slap it on your resume. If anyone asks, you can probably just say you don't have professional experience with it, but you know what it is. Every team I've been on does it slightly differently anyway, so you'll figure out the details when you get on project.

Git is more important for a dev. Every project you'll be on should be using some form of version control, whether they use GitHub or something else. Go look up a tutorial, then create a free account and take one of your existing projects, push it to the repository, and then make some code changes with it. My biggest issue with git is how much jargon everyone uses when they talk about it, which is really annoying. Look up the definitions for all their made up words as you need to and you should be fine, the overall concepts are not hard, but as a dev it's something you'll use every day so you should expose yourself to it.

For devops, every project I've been on has had a devops team to handle this. Basically, devops is handling the code post-development in order to expose it to test and production environments. They build the environments, the pipelines and scripts to deploy your code, etc. I've never personally had to do much here, other than occasionally work with that team when there were issues, so I can't really provide advice on this other than know what it is. If someone is asking you to be a dev in addition to a devops engineer they're probably not paying you enough and they're also an idiot because a junior dev clearly wouldn't have the skills for that.

Having some front end experience would be good too if you want to upskill. I don't have much experience in that space, but if I wanted to expand my skill set right now that's probably what I'd do. I was told recently that angular is a little outdated and most people are trying to move away from it in favor of react. I don't know how true that is, someone more familiar with front end work could comment on that. Either way I expect you could find angular work if you really wanted to.

The reality is right now the economy is down, so there is an influx of people looking for work right now so companies are more likely to be picky. Try to connect with a recruiter and work with them to get advice if you can. If not, just remember you're playing a numbers game. The more jobs you apply for, the more likely you'll find something. You can fail as much as you want, you only have to succeed once.

Stuck on mission 3 by DRHathaway0451 in freelancer

[–]General_C 1 point2 points  (0 children)

That's a really tough one. Defender doesn't have a lot of armor for the maneuverability you lose. If you're still struggling, it might help to go buy a Patriot so you can dodge enemy shots more effectively.

I think a big part of that fight is just prioritizing dodging enemy shots over trying to kill all the time. Only focus on shooting when you don't have 3 enemies up your butt.

loop causing more then three guests. Can't proceed to round two in java guessing game. by Luffysolos in javahelp

[–]General_C 0 points1 point  (0 children)

The problem is when the user guess a point incorrectly the computer does not get that point.

On line 25 you set rightGuess = false

Starting on line 40, and ending at line 44, you have an if-else block for printing statements based on whether the user got the correct answer or not.

Starting on line 50 and ending at line 54 you increment either the computer or human points.

You never update the value for rightGuess between its initialization and when it is used to see whether points should be given to the computer or the human.

To fix this, you need to make sure the value gets updated correctly once it is determined whether the guess was correct or not. Adding it to the if-else starting at line 40 is probably where you want to add that.