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
poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
My professor has me doing his sweat shop programming to help his 120 class that are using GameMaker (long story/school sucks). Basically, he wants me to write the chapter examples in the gamemaker book in java. The last one he's given has a guy that runs around an environment top/down style and what you see in the screen is relative to the position of the character.

Is it possible to have a JFrame the size of the screen with a JPanel the size of the level and just have the JPanel repainted in the JFrame to a certain point? It's hard to describe what I'm asking, but if you think about a roguelike, the character approaches the side of the screen but the level shifts over so you can see more to one side. I'm basically trying to recreate this in Java but am not sure how to do the moving environment thing with JFrame/JPanel/JWhatever.

Adbot
ADBOT LOVES YOU

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
I assume all of this is within a for loop?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Aleksei Vasiliev posted:

:stare:

you're accessing an array here, so this is where I assume you're going outside the index

and if I understand you right: You're checking to see if the given number, i.e. 9, is equal to array[9].getId(), which should be 9?

Also, Aleksei has a point. If you only have 0-9 and someone puts in 20, your if statement will actually try to access the accounts[20] and throw an out of bounds error.

Maybe:

code:
int userInput = theirNumber;

if (userInput <= accounts.length) {
do your code
}

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
If someone puts in 20 as their account, you are still getting array out of bounds errors. Do:
code:
if (accnum <= accounts.length && accnum > -1) {
   logics...
}
This will in fact get rid of the need for:
code:
if (accnum == accounts[accnum].getId()) {
   logics...
}
As long as accnum is 0 or greater up to the length of the array, you will always get a legit account.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
Yah, accounts with unique ids are just begging for a hashtable to be used.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Brain Candy posted:

It’s been said that there are only two hard problems in Computer Science: cache invalidation, naming things and off-by-one errors

Do you not like the names of my variables?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

chippy posted:

Guess again :)

What's sad was that I was right the first time I offered code and then later on in the thread changed it. :pwn:

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
Alternatively, you can use a java decompiler to decompile the class file and just copy/paste the method into your own code.

http://java.decompiler.free.fr/

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Zewle posted:

Is there a way to read all serialized objects in a file at once?

EDIT:

Serialized an array of objects, but... I don't know how to get them out of the array after I deserialize it.

When you say you deserialized it, do you mean you actually have an array of objects at the end? If that's the case, you can just loop through the array and grab each object.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

baquerd posted:

Something like this:

code:
for (Student currStudent : studentArray) {
  System.out.println(currStudent.getName());
}

Do this. If you're not familiar with the syntax, all this is is a for loop that loops through each Student object in the array.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Blacknose posted:

I need a good Spring MVC book. Any ideas?

This got skipped over, but I recommend:

http://www.amazon.com/Spring-Action-Craig-Walls/dp/1935182358/ref=sr_1_1?s=books&ie=UTF8&qid=1311350259&sr=1-1

I have the second ed. The third just dropped last month I think.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

MonsterUnderYourBed posted:

simple question with the JDBC hooking into MySQL.

Is there a way I can insert an entry, and at the same time return the automatically generated key that entry is now using?

I am aware that I can insert an entry, stating the automatic key should be returnable, and then get the key for the final entry in the database, but if multiple processes are accessing the database, this could return an incorrect result due to a second entry being added in before the key is returned.

Shouldn't this be handled in the DDL for the table? Some column is the auto incrementing key?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Bob Morales posted:

Book recommendation? I don't want to sludge through 122 pages and there isn't one in the OP/first page.

I have some creaky old 'Learning Java' from 10 years ago but I'll just buy something new. I know C and Ruby (and did -some- basic Java a long, long time ago) so I don't need anything geared toward complete beginners.

Strangely enough there are only a few Java books at the local Barnes and Noble for me to look through and they are all 4 years old, and there are so many books on Amazon I don't know which to begin looking through.

http://www.deitel.com/Books/Java/JavaHowtoProgram7e/tabid/1191/Default.aspx

I know there's some mixed feelings but I've gone through 2 editions of this book and if you like looking up a topic and seeing code examples EVERYWHERE as well as detailed explanations as to what's going on, then this is the book for you.

The latest editions took away those stupid rear end covers with bugs doing dumb poo poo, but I kinda liked them.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Janitor Prime posted:

Look at Spring Boot guides should get you rolling

Seconded. Spring Boot and latest Spring framework in general means no more web.xml and no more WEB-INF folders. gently caress XML configuration forever. Also Gradle is a great replacement for Maven.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Zaphod42 posted:

I find doing that is a huge pain in the butt compared to just dropping libs in a "libs" dir though.

What I'd really prefer to Maven would be a system where you have a libs dir and then Maven just automatically downloads and places libs into the libs dir based on dependencies. Any files that were not part of the Maven POM file would be ignored in the libs dir, so you could have your own libraries that Maven doesn't know about, but Maven would also pull things for you automatically and replace the old versions, more like a package manager. Then you'd have a totally portable folder that can compile without Maven. Make it more of a setup tool. My problem is that Maven itself ends up becoming a dependency that anybody who wants to deal with your project has to deal with. I really love being able to just rip a lib from an FTP site and compile right away without having to edit POM files. That's great for the big heavyweight stuff with lots of dependencies and versions, but for some small lightweight libs its super overkill and takes too long to get going.

I don't know why they don't just build that as a feature into Maven, even. "Maven copy dependencies" would build a libs dir or something to that effect. But I guess its kinda anathema to Maven's mentality, so it'd have to be some other software to offer that kinda approach.

Sounds like you want Gradle. You keep your non standard libraries local as needed. If you work anywhere where you're maintaining multiple projects with different requirements, you're gonna want something like Maven or Gradle. You can't assume anyone coming in is going to have the same libraries in a folder as you. That runs dangerously close to the "works on my machine" issues.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Wheany posted:

Yeah, I checked out a Minecraft mod and it used Gradle. Fine, whatever, just enable Gradle support in Idea. Import gradle project and... it takes 2 hours to resolve the dependencies. :wtc:

This is not typical. I'm guessing that mod has repositories pointing all over the internet with slow connection speeds.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Wheany posted:

That's what the .m2 directory under your home directory is.

Or the .gradle directory under your home directory if you're using gradle. ;)

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Jo posted:

Would this be the place to talk about Kotlin? I recently stumbled upon the language and have taken a liking to it. Do we have a JVM languages thread?

I don't know poo poo about Kotlin or Scala besides the fact that they don't do anything that Groovy doesn't already do and the syntax looks like rear end.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Zaphod42 posted:

I don't want it in a compiled jar though; I want to just have a folder with the loose libraries for building with without Maven in the future.

But that's pretty close and worst case I could always rip the libs out lol. Cool read, thanks.

I'm aware of the local repo but you have to add things to the local repo first, and then it stores them in its own directory. That's efficient so you don't have tons of copies of the same library all needing to be copied around and updated, but I just would really like to be able to like detach from Maven at will and create a portable source zip. But like I said that's just kinda backwards to the whole mentality of how Maven is designed to be used.


But my point is even having to add things to an internal artifactory is overkill for some applications. If I'm just rolling up a quick dumb application for fun that I'm going to delete tomorrow, or if its some high school student project that's never going to be maintained or updated or something, situations like that it ends up being a hassle. Like you could write a bash script to accomplish some quick task, but what if you just wanna do java real quick?

My entire point is that you shouldn't have to jump through so many hoops to get stuff built! That's exactly what I'm trying to accomplish. For complex business software maven makes it easier to build and deploy, but for really simple one-off projects or student learning projects its a huge initial burden before you can even compile and run a single test.

If you're scared of your system being compromised you can use SSL, checksums, and virus scans.


That's for all libraries for the machine, right? I'm saying I want a directory with just a single project's needed dependencies.

Its not a big deal though just a gripe. There's probably tools I should use to make deploying your own libraries into Maven and configuring a POM to use them much more painless.

I'm really just salty because a project I use switched over to gradle after not requiring it for a long time and it was a real pain to reconfigure the project and get everything in the right form that it could build.

I'm not sure what libraries you need to download and put in a folder that aren't already on mavenCentral or jCenter. Imagine for a second that you have one additional file in your project that lists all the things you want. Now imagine there's a single command to download all the things you want and build your jar. Now imagine that someone can clone your git repo or unzip your source (lol) and run that same command and get the exact same outcome as you did on your own machine. That's gradle and/or maven.

If you're just doing Java to dick around and you don't think anyone will ever touch your source code and you don't think you'll write anything worth sharing, then go ahead and download jars manually and add them to your classpath. Even for one off projects and hackathons, I still find gradle is easier than going and downloading libraries and adding them to projects manually. There's a reason why other languages have package managers tied to them.

Seriously, check this: https://gist.github.com/poemdexter/6cb747368e34992ea6e0aeb386981259
code:
apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
  compile 'com.google.guava:guava:20.0'
  testCompile 'junit:junit:4.12'
}
Now if you have gradle installed, all you have to do is:
code:
gradle build
and now those libraries are linked to your project and a jar was built. Now I can do fancy guava stuffs and even test my code and I didn't have to go all over the internet hunting for jars!

poemdexter fucked around with this message at 10:16 on Dec 7, 2016

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

TheresaJayne posted:

build.xml is Gradle

ant is buildfile

build.gradle is Gradle.

Volguus posted:

If you have a Makefile you have an external dependency on make.
If you have a build.xml file you have an external dependency on ant.
If you have an IDE project file you have an external dependency on that IDE.

It just never ends and it's a nightmare.

Yes, the solution is never build a project ever.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
A lot of configs use the word "password" for fields. I think you might need to lower your security settings on that one because it's not like you can go and change the external libraries to start using a different word.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

AbrahamLincolnLog posted:

So, I'm going to preface this with the point that this is potentially a very dumb question, but I have to be honest and say that I'm just totally stumped.

Yesterday I logged into my COP 2805 online class to see my final assignment. The instructions are as follows:


The assignment comes with a ComplexClass.java which is all fine and dandy. But where the gently caress do I get GenericMatrix from? There's no GenericMatrix class in the given files; attempting to just extend it gives me a "class not found error" (obviously). With some extensive googling, all I've found is people who have had the exact same assignment, with one catch: they're all using a different textbook, which included code for a GenericMatrix class. My textbook is an e-book and I've searched it for "GenericMatrix" and there's no results. As far as I can tell, my professor has ripped this assignment out of another text book that we aren't using and only included part of the code.

Am I missing something? Is there a GenericMatrix in Java somewhere, and I'm just missing it (or are too dumb to know how to import it)? The rest I can kind of figure out, but I have no idea where I'm supposed to be getting this GenericMatrix stuff from, and I wanted to double check to see if I was just loving up, or if I'm right and I'm missing part of the assignment.

Big thanks in advance for any help. My grade is high enough that I should still get a B if I "fail" the final, but I'd rather keep the A.

http://www.cs.armstrong.edu/liang/intro9e/html/GenericMatrixWithLineNumber.html is this it? Still, I would hit up the professor.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Zorro KingOfEngland posted:

Apache POI is the library I've always used - https://poi.apache.org/

This is the only answer for Excel imho.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

smackfu posted:

Has anyone had any luck slowly updating a legacy code base to newer technologies? The old code has SQL mixed in with controllers all over the place. It's pretty easy to pull out repositories and modes and such but it would be nice to stick in Hibernate and some kind of dependency injection framework but without breaking all the other existing code that we aren't touching yet.

I took something from old Spring to new Spring so we could get off the xml config. I also swapped it to Groovy so we could use that. src/main/java turned into src/main/groovy and the file extensions went from .java to .groovy with a couple @StaticCompiles where needed. If you have all of your business logic contained in a decent way, it might be easy to hop on Spring but I dunno. Depends on the codebase size and how messy it is. Good luck!

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
You should have separate jobs per branch and you can set the branch in Jenkins job config. Use this for automatically doing builds. We only watch the development branch and the release branch for automatic builds and each has it's own job.



Here's the Continuous Integration/build engineering/devops thread: https://forums.somethingawful.com/showthread.php?threadid=3695559

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

venutolo posted:

Thanks. I was hoping not to have to do separate Jenkins jobs for different branches.

When you create a new job, there's an option to clone a previous job. Use that, change one string, poof you're done.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Wheany posted:

I can't find a library that does 3D delaunay triangulation in Java and I refuse to believe one doesn't exist.

Look man, I just want to input a List<3DPoint> or something to a method and get a List<Tetrahedron> back.

I also want the library to have a maven dependency I can just poop into my pom.xml.

Lastly, I want a pony.

I don't know much about 3d delaunay triangulation, but maybe this will help? http://download.java.net/media/java3d/javadoc/1.5.1/com/sun/j3d/utils/geometry/Triangulator.html

Maven dependency: https://mvnrepository.com/artifact/java3d/j3d-core-utils/1.5.1

pony:

poemdexter fucked around with this message at 21:25 on Jan 31, 2017

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

fletcher posted:

Why does the GC log have to be so annoying to parse. I'm trying to write a logstash pattern for it, what a fuckin' pain!

I found an existing one online but god drat it is complicated: https://github.com/Mortinke/logstash-pattern/blob/master/logstash/etc/logstash/patterns/gc

They don't make monitoring applications for this sort of thing so you don't have to manually parse it all an then do something with results from logstash later?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

HFX posted:

Emoji is neither a valid return type or a valid character for identifiers.

Well there goes my plan to have all my packages named poop emoji.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

PierreTheMime posted:

So I managed to wrestle Eclipse and Maven into working order and get a working SOAP test created which returns my expected result from my API. What is the best (or at least a semi-standard) way of using SOAP for websites? I have absolutely zero experience with HTML/Javascript (outside of HTML 1.0 from the late 90s), but I have a feeling I'll need to get a few things in place. I tried searching for good basic examples and didn't turn up much--does anyone have a good idea of where I should start?

SOAP is really for service to service communication. Why not use REST? Is your API only allowing SOAP requests?

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

smackfu posted:

Anyone use any neat Spring things with Spring Boot? They have what seems like dozens of packages, are there any that you found particularly useful?

Yes! Spring Security is awesome for setting up auth. Spring Actuator is great for all the nice endpoints it gives you for server status tracking as well as the ability to write custom endpoints easy.

Basically all our projects here start with these lines in gradle:

code:
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-security'
compile 'org.springframework.boot:spring-boot-actuator'

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

smackfu posted:

I will need to try that. I've been playing with the SpringFox Swagger package which auto documents your REST apis. It's useful for seeing which end points you were lazy with, like "why is DELETE enabled on this controller???" And useful if someone says that you need to document APIs of course.

Spring Actuator is also really cool although I'm not sure how to use it in our production environment since our individual web servers are not directly addressable. So you could get stats/health for the server you happen to be connected to but not sure how useful that is.

For production servers that are directly addressable, automated health checks by sysadmin tools is great. Plus you can write custom endpoints for things like integration health checks (can service A reach service B) for microservice environments.

Personally, I wrote a little webapp at work that pings all servers' /health endpoint in all environments to get the version deployed. I think display it in a simple table on a page. Now people can just hit that to see what version of what is deployed where instead of bugging the hell out of me.

P.S. Devops is a rabbit hole you do not want to go down if you're a developer trying to write code. There's always more things to monitor and automate and tweak and people will lean on you hard when things randomly stop working.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
Make drat sure you're not breaking any HIPAA poo poo throwing medical information onto the cloud. Amazon wrote up a white paper to cover AWS and HIPAA. https://d0.awsstatic.com/whitepapers/compliance/AWS_HIPAA_Compliance_Whitepaper.pdf

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Hughlander posted:

Stupid question that's been bugging me.

Has anyone seen a library/program to talk to a gradle daemon running and let you kick off tasks and see their status just by hitting a localhost port? I have a poo poo ton of utility tasks that I'd like to just have a browser window open in the corner and click rather than find the right terminal window and type a long rear end task name. Secondary is there a good IntelliJ plugin to run tasks? For whatever reason the built in Run Gradle Task doesn't show the tasks for my project.

When you import your project, don't navigate just to the directory. Instead navigate all the way to the build.gradle file. That will set up your project as a gradle project. From the gradle tab thing on the right, you'll be able to see all your tasks and you can double click them to run them. This is built into intellij and you don't really need a plugin.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

Volguus posted:

Well, that's one name that I haven't heard in a long time. With the release of Spring Boot, the advantages that Grails brings to the table diminish quite a bit. While I do not know how it performs nowadays, but back in 2010 when I wrote my first app in grails it was quite slow for the time (and upon release I had 10000 hits in the first 2 minutes and that didn't help the poor thing).
Just out of curiosity, if you're familiar with current day Grails and list its features and compare them with Spring Boot, what do you get? What would be the killer thing that Grails has that Spring Boot doesn't (other than Groovy)?

I've been writing Spring Boot apps in Groovy for the past 2+ years so it's definitely not a Grails only thing. I did get an email this morning about the Dallas Grails group disbanding due to lack of interest. I've never seen a Grails app in the wild either. It's all Spring or Spring Boot and sometimes Ratpack depending on the team.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

CPColin posted:

It did seem like Grails was on its way out, given the age of many of the Grails search results I've been seeing. Unfortunately, I don't know enough about Grails or Spring Boot to make any meaningful comparisons, but I'll be sure to keep this info in mind if and when it becomes time to start making some large-scale tech recommendations.

Spring Framework has been around forever it feels like and is incredibly stable and easy to use imho.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
Import project from existing sources. When you navigate to the project, click on the build.gradle file and import that. Your project will be setup as a Gradle project.

Right now IntelliJ is just building it however it thinks it can based on project type so who knows what it's doing.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

PierreTheMime posted:

Another dumb question--this project team wants all code put into one repository. I've got my different little applications separated into packages, but all the dependencies are managed in the same pom file, so performing an export of one of the applications as a runnable .jar pulls all the dependencies and bloats the executable (13MB instead of 1MB). It's not a huge deal, but in the interest of learning not to be terrible I'd like to know if there's a way to manage which run configuration export receives which dependency within the same project or if I should just ask them for a different repo and split it into two projects.

Are you not using some artifact repo like artifactory, dockyard, or nexus? How is your CI/CD handled?

This sounds like hell from a devops perspective.

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice
Back in college, we used Dietel Dietel Java books as textbooks. https://www.amazon.com/exec/obidos/ASIN/0134743350/deitelassociatin

It's basically everything you could possibly want to know about "how to do X in java" with explanations and full code examples. They even explain line by line what's going on. It was my bible starting computer science in college and I still have it on my shelf. It's basically the book version of stack overflow (which didn't really exist when I was in college).

Adbot
ADBOT LOVES YOU

poemdexter
Feb 18, 2005

Hooray Indie Games!

College Slice

CPColin posted:

Thanks for that playlist. I started messing around with Spring Boot a little bit ago using "see how easy?" type stuff, so it'll be nice to get a better handle on what's actually going on. Especially since my project was trying to figure out how Spring Boot + Thymeleaf + Ceylon could fit together and the Ceylon folks want me to write up an article on my findings. It'll be a better article if it looks like I actually know what I'm talking about!

I don't know anything about Ceylon, but I already dislike the package.ceylon and module.ceylon files sprinkled everywhere instead of contained in a single build.gradle or pom.xml. I understand Ceylon is trying to support java and javascript at the same time, but meh... (just opinion)

Here's a ping pong ELO app I wrote using thymeleaf and spring boot super quick for the last company i worked at if it helps a little. I kept the "business logic" in the controllers because I was lazy and doing this when I had spare time in afternoons before anyone gives me poo poo about MVC practices. We played way too much ping pong and I'd rather do that than write code to track rankings.

https://github.com/poemdexter/rn-pingpong

I wrote this with groovy so it already has a lot of features that Ceylon has. Look how clean my model is! ;)
https://github.com/poemdexter/rn-pingpong/blob/master/src/main/groovy/com.rnpingpong/models/Player.groovy

Looks like a lot of the features from ceylon are already in groovy with the big exception being support of javascript. But then again, javascript.. :gonk:

poemdexter fucked around with this message at 21:00 on Apr 12, 2018

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