|
something I didn't consider. Also probably correct. I'll throw in some checks and see if it starts to work.
|
# ? Jan 10, 2014 03:35 |
|
|
# ? May 9, 2024 03:21 |
So Ive made a program in eclipse that I kind of like, and I'd like to be able to run it without opening the project in eclipse and then compiling and running it from there. How do I make it into an actual program that I just double click on and then it opens and runs?
|
|
# ? Jan 12, 2014 02:28 |
|
greenchair posted:So Ive made a program in eclipse that I kind of like, and I'd like to be able to run it without opening the project in eclipse and then compiling and running it from there. How do I make it into an actual program that I just double click on and then it opens and runs? I believe you can export it as a jar, which should be runnable on its own. However, the only Java stuff I've done is the tutorial videos hosted on Sourceforge that are in the OP, so take that as you will.
|
# ? Jan 12, 2014 03:28 |
|
greenchair posted:So Ive made a program in eclipse that I kind of like, and I'd like to be able to run it without opening the project in eclipse and then compiling and running it from there. How do I make it into an actual program that I just double click on and then it opens and runs? There are a number of ways to do this: 1) Make a runnable jar : http://www.mkyong.com/java/how-to-make-an-executable-jar-file/ 2) Let Ant make a runnable jar for you: http://stackoverflow.com/questions/9874550/how-to-create-a-bundled-runnable-jar-using-ant 3) Let maven make a runnable jar: http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven It doesn't matter which one you choose for an one-off project. For a maintainable and an easy to share (between developers) maven is probably your best bet. Or Ant with ivy. Any of the 3 methods will provide you with the desired end result. The difference is with maintenance.
|
# ? Jan 12, 2014 05:08 |
|
Pretty sure Eclipse can also export .jar files if you specify a main class to execute?
|
# ? Jan 12, 2014 06:18 |
|
So what is "modern" Java web development like? It's all enterprise stuff, right? And JSP is considered ancient, as is the slightly more recent JSF? I guess Spring is where modern, enterprise Java development is at, but isn't that just a dependency injection framework with a lovely MVC module available if you hate yourself? Never used Spring, that's just the impression I got from when I was looking for a Java web framework a while ago before I said "gently caress it" and decided I'd rather have some fun with Scala.
|
# ? Jan 12, 2014 17:01 |
|
Safe and Secure! posted:So what is "modern" Java web development like? It's all enterprise stuff, right? And JSP is considered ancient, as is the slightly more recent JSF? I guess Spring is where modern, enterprise Java development is at, but isn't that just a dependency injection framework with a lovely MVC module available if you hate yourself? Never used Spring, that's just the impression I got from when I was looking for a Java web framework a while ago before I said "gently caress it" and decided I'd rather have some fun with Scala. The spring MVC module is anything but lovely, but to each his own. JEE has come a long way since 2004. Now you have specifications like JSR 311 & JSR 339 with libraries like Jersey (the reference implementation) or RESTEasy. If you like Scala though, there's nothing wrong with that either, though im my personal opinion, the Scala web frameworks are either: - less feature-full than spring (for example). seem quite a bit immature (scalatra) - different for the sake of being different (Play2). Hipsters though, use things like nodejs for web development, with stuff like mongodb on the backend. Nothing wrong with that either if that's what you like.
|
# ? Jan 12, 2014 17:36 |
hooah posted:I believe you can export it as a jar, which should be runnable on its own. Thanks! For something that I think would be pretty common it was surprisingly unintuitive (to me at least). For any others out there wondering exactly how to do it: 1. Make sure you have the correct workspace open in eclipse 2. File -> Export. This brings up a menu that says "Select Export Destination" 3. Click on the Java Folder icon so that it is showing its contents 4. Click on "Runnable Jar file" 5. Click next, this brings up a screen "Runnable Jar File Specification" 6. In the first drop down menu find the name of the file that contains the "main" method. The project name is on the right 7. For "Export Destination" click on browse and find the folder you want it in, name it 8. Don't really know what the library handling stuff is I just picked the first option. 9. Don't know what ant is. I left it unchecked. 10. Click on Finish. It's done! This is probably super obvious to most out there, but it took me a while to figure out, so maybe someone else will find it useful.
|
|
# ? Jan 12, 2014 19:33 |
|
Safe and Secure! posted:So what is "modern" Java web development like? It's all enterprise stuff, right? And JSP is considered ancient, as is the slightly more recent JSF? I guess Spring is where modern, enterprise Java development is at, but isn't that just a dependency injection framework with a lovely MVC module available if you hate yourself? Never used Spring, that's just the impression I got from when I was looking for a Java web framework a while ago before I said "gently caress it" and decided I'd rather have some fun with Scala. I've actually been doing Java web development recently, and it's been pretty nice. For REST you have JAX-RS, which is surprisingly sane, and forms the core of Dropwizard, which is a library for easily building web services. I haven't used Spring MVC, but Spring provides other things like data access and AOP. As far as HTML templating goes, I've been using jade4j, which is just a port of jade to Java. All of this either runs in web container like Tomcat, or as a standalone JAR, so you don't have to muck around with app servers. Overall it's been good, and I haven't seen a lot of the cruft or FactoryFactoryImpls that people associate Java with.
|
# ? Jan 12, 2014 23:00 |
|
Safe and Secure! posted:So what is "modern" Java web development like? It's all enterprise stuff, right? And JSP is considered ancient, as is the slightly more recent JSF? I guess Spring is where modern, enterprise Java development is at, but isn't that just a dependency injection framework with a lovely MVC module available if you hate yourself? Never used Spring, that's just the impression I got from when I was looking for a Java web framework a while ago before I said "gently caress it" and decided I'd rather have some fun with Scala. Use Guice for DI instead. Guava for some neat data structures, and Dropwisard for running web APIs (or Jersey, which Dropwizard wraps, if you would prefer to deploy to Tomcat/Jetty/etc). IMO steer clear of Spring.
|
# ? Jan 12, 2014 23:36 |
|
Any recommendations on some absolute bare-bones First Programming Language books for Java? My roommate is going into his second semester of Comp Sci and he's really struggling. Decided to wait until the last week of vacation to buy a book and try to get back into it before the next semester starts Java, A Beginner's Guide seems to have good reviews.
|
# ? Jan 13, 2014 00:03 |
|
Doctor w-rw-rw- posted:IMO steer clear of Spring. This is a bad advice. Spring is extremely useful in a large number of applications. Is a huge framework, yes, but it can help more than it can hurt if you use it wisely. Check out the number of projects available: http://spring.io/projects
|
# ? Jan 13, 2014 02:42 |
|
rhag posted:This is a bad advice. Spring is extremely useful in a large number of applications. Is a huge framework, yes, but it can help more than it can hurt if you use it wisely. Check out the number of projects available: http://spring.io/projects Just because it has a large number of projects available doesn't necessarily mean they're any good. Can you explain some of its advantages?
|
# ? Jan 13, 2014 03:32 |
|
Doctor w-rw-rw- posted:Well, it *is* just my opinion. I just never reached the point where adding in a particular component ended up being a net value-add. I would recommend then to check some of them out. The introductory page should tell you about what they do. But, in one sentence, let me go through some of them that i have used: - Spring Data JPA - You get full CRUD operations on an entity writing one single line of code: public interface MyRepository extends JpaRepository<MyEntity,Integer>{} . Need more? You can write special queries, or do special poo poo - Spring web flow - a fantastically easy to write web flow api. really. it rocks (web flow, such as wizards). - Spring AOP - great support for aspects. cannot be easier (Few annotations, and you're golden). - Spring MVC - you can write REST applications, or use JSPs or any other view easily (xslt,freemaker,velocity). Writing controllers is trivial as well, just annotate your class correctly and you have any path you want. - Spring Integration - Written to support the Enterprise Integration Patterns. I used it to very easily get data from RSS feeds, ftp's or http sources. it made things a lot easier. - Edit: Spring Security (how could i forget that): - please find me an easier way to secure an application, while getting everything right and having easy way to write your own stuff should you need to. It comes with OAuth, kerberos, LDAP and AD integration, where you need to write very little if any code. Plus of course, the old username/password auth. Supports ACLs and path security. Now, where is spring not suited? Spring is big and can be heavy. I havent used yet the 4.x release, but with 3.x ... i wouldnt use spring in a desktop application. For light CDI, google-guice is great. But you cannot deny what spring brings to the table. Shitload of things that you don't have to write, that others have written for you probably better than you would be able to. Another project they have in there is called Grails. It's a huge and very heavy framework, using the Groovy language, but which can help you write a complex and full featured web app in days. Its perfect for when the boss wants you to be done yesterday, and still have an easy to maintain web app. However, grails is heavy, i wouldn't put it on an internet-facing server. But for internal web apps, i don't think you can find a faster to develop in framework. Volguus fucked around with this message at 05:40 on Jan 13, 2014 |
# ? Jan 13, 2014 04:49 |
|
Sab669 posted:Any recommendations on some absolute bare-bones First Programming Language books for Java? My roommate is going into his second semester of Comp Sci and he's really struggling. Decided to wait until the last week of vacation to buy a book and try to get back into it before the next semester starts I like the Head First java series for complete beginners. It has pictures.
|
# ? Jan 13, 2014 15:44 |
|
Sab669 posted:Any recommendations on some absolute bare-bones First Programming Language books for Java? My roommate is going into his second semester of Comp Sci and he's really struggling. Decided to wait until the last week of vacation to buy a book and try to get back into it before the next semester starts Honestly, I think the Oracle turorials are pretty decent. (Scroll down to "Trails Covering the Basics".) Comp Sci II doesn't cover anything more complicated than, like, Generic Collections, right? It's been forever.
|
# ? Jan 13, 2014 21:02 |
|
Gravity Pike posted:Comp Sci II doesn't cover anything more complicated than, like, Generic Collections, right? It's been forever. His first semester class was actually pretty weird. They covered basic data types, then jumped into objects and interfaces then flow control and loops. They did a bit with ArrayLists as well, never having even talked about just basic arrays. By the end of the semester he barely comprehended the concept of 'returning' a value from a method, constructors, or creation of variables for things other than basic data types. I don't know if his professor sucked, or it was a lack of sufficient labs to give him practice or what.
|
# ? Jan 13, 2014 21:07 |
|
Safe and Secure! posted:So what is "modern" Java web development like? I'm here to ask the same question, but mostly about the different libraries to use for views. Coming from .NET, which has had a pretty good template engine for some while with strong typed models and simple, clear syntax, I'm hoping there is something similar for Java. I don't mean exact same syntax, but something that is proven to work well for projects with big teams, and is not an HTML-only library with hipster endorsed inflexible syntax. Maybe plain JSP is good?
|
# ? Jan 13, 2014 22:25 |
|
Have you tried Thymeleaf?
|
# ? Jan 13, 2014 22:29 |
|
tohveli posted:I'm here to ask the same question, but mostly about the different libraries to use for views. Looking for 10 seconds at Razor ... it's very much like JSP. Few things here and there that are different, but ... it's JSP. What JSP has and that apparently does not is the concept of tags (that is, you can do <c:foreach...> instead of @foreach, but you can also make your own tags that do whatever you want them to). Unless i completely misunderstood what @foreach is and does. For templating (have master page with bodies,etc.) you can use sitemesh3 in java. JSF is fine as well, though the existing jsf engines/libraries do tend to be a bit on the heavy side with all that HTML that's generated. But that's just a personal opinion. If you wanna give jsf a try (for the heck of it) checkout http://www.icesoft.org/java/projects/ICEfaces/overview.jsf .
|
# ? Jan 13, 2014 23:09 |
|
This seems pretty trivial but I cant figure it out. How do you keep carriage returns from being removed from bufferedreader?code:
code:
DholmbladRU fucked around with this message at 22:09 on Jan 14, 2014 |
# ? Jan 14, 2014 22:06 |
|
DholmbladRU posted:This seems pretty trivial but I cant figure it out. How do you keep carriage returns from being removed from bufferedreader?
|
# ? Jan 14, 2014 22:14 |
|
DholmbladRU posted:This seems pretty trivial but I cant figure it out. How do you keep carriage returns from being removed from bufferedreader? http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html I would say look into the read() method instead, why use readLine if you don't want it stripped by lines? Don't force a square peg into a round hole. Always go to the java docs first! Java code:
|
# ? Jan 14, 2014 22:17 |
|
DholmbladRU posted:This seems pretty trivial but I cant figure it out. How do you keep carriage returns from being removed from bufferedreader? This is a perfect oppurtunity to use the Apache Commons IOUtils class: Java code:
Fake Edit: Also, if you're going to be looping through the file like that, you really ought use a StringBuilder instead of concatenating strings. Since a String is immutable, what that does is allocate memory for the first line, and write the first line's worth of characters to that memory. Then it allocates enough memory for the first two lines, and copies the first two lines worth of characters to that memory block. Then it allocates enough memory for the first three lines, and copies those three lines to memory... You end up writing something like (lines^2 * average-line-length) characters. If you use a StringBuilder, it saves a reference to each String, and only when you call toString does it allocate enough memory to hold everything put together. Java code:
|
# ? Jan 14, 2014 23:18 |
|
Gravity Pike posted:
The java compiler (at least from Sun/Oracle) has been able to see these kind of patterns since jdk 1.4 or so. It generates code that is using the stringbuilder, no need to worry. Still, it is a good habit to have, to not concatenate strings just for the sake of it.
|
# ? Jan 15, 2014 02:05 |
|
rhag posted:The java compiler (at least from Sun/Oracle) has been able to see these kind of patterns since jdk 1.4 or so. It generates code that is using the stringbuilder, no need to worry. Still, it is a good habit to have, to not concatenate strings just for the sake of it. Huh, that's neat. I knew the compiler could do that for things like Java code:
|
# ? Jan 15, 2014 07:20 |
|
I'm currently learning Java as part of a degree on the Open University in the UK. It's my first programming language (Sense, an OU variant of Scratch, doesn't count) and I'm coming late to it. While I'm enjoying the course, there's a load of course-specific terminology (messages instead of methods etc) and I'm concerned that I'm learning Java in a weird way. Can anyone recommend a definitive beginners guide to Java and OOP programming that reflects how the language is used in real applications?
|
# ? Jan 15, 2014 15:58 |
|
Gravity Pike posted:Huh, that's neat. I knew the compiler could do that for things like In lots of cases its an optimization to simply unroll the loop, or at least unroll it a couple times, and the compiler does that constantly without you knowing. Some of your 'loops' don't even exist!
|
# ? Jan 15, 2014 16:57 |
|
Zaphod42 posted:In lots of cases its an optimization to simply unroll the loop, or at least unroll it a couple times, and the compiler does that constantly without you knowing. Some of your 'loops' don't even exist! The best part is trying to convince people who setup the almighty automated rule scanners, that your code is more readable using concatenations and doesn't result in a performance hit. Then again its hard getting people to update any ideas.
|
# ? Jan 15, 2014 17:17 |
|
String.format is more readable IMO and is yet another way to do that
|
# ? Jan 15, 2014 18:14 |
|
Chas McGill posted:I'm currently learning Java as part of a degree on the Open University in the UK. It's my first programming language (Sense, an OU variant of Scratch, doesn't count) and I'm coming late to it. Have you seen the Oracle Java tutorials yet?
|
# ? Jan 16, 2014 01:56 |
|
Volmarias posted:Have you seen the Oracle Java tutorials yet? There's probably a way of turning them into PDFs or something, though.
|
# ? Jan 20, 2014 10:50 |
|
Is it possible to declare an abstract method that takes a particular type of object as a parameter, and then in the subclass that implements that method, require another type of object that extends the original one? Something like this:code:
code:
Is there a way to do what I'm trying to do, or should I just settle for using the same signature and type checking the options object when it's passed in? Sorry if this is full of stupid things, I'm kinda winging it here (especially with generics). Also this is on Android, in case there's any late-game Java magic that would otherwise help
|
# ? Jan 20, 2014 23:39 |
|
derp... wrong thread...
|
# ? Jan 21, 2014 00:34 |
|
baka kaba posted:Is it possible to declare an abstract method that takes a particular type of object as a parameter, and then in the subclass that implements that method, require another type of object that extends the original one? Something like this: What you can do is parameterize the type instead: code:
code:
|
# ? Jan 21, 2014 00:49 |
|
Ahhh that's it, you're a star! Looks like I need to do a bit more reading to understand what's going on, but it's accepting it at least
|
# ? Jan 21, 2014 01:08 |
|
baka kaba posted:Ahhh that's it, you're a star! Looks like I need to do a bit more reading to understand what's going on, but it's accepting it at least Read on this track: http://docs.oracle.com/javase/tutorial/java/generics/inheritance.html
|
# ? Jan 21, 2014 17:35 |
|
Hey Guys, I am just starting out with Java and am writing a simple program that takes user input and calculates the exponent of a number. I am not allowed to use the math library. My program works but for some reason the calculation of the exponents is way off, the numbers are all multiples of the base, but the exponents seem to shoot off. I am not sure if this is a syntax error or whats going on! code:
|
# ? Jan 22, 2014 01:16 |
|
There is a logical error, not a syntax error. (Syntax errors won't even compile in Java!) I have a feeling that you could catch your own error with a bit of testing. Tests should be simple. They should generally test one thing. Two is an easy number to work with in this case. Ask your program what 2^0, 2^1, 2^2, and 2^3 are. You're going to get wrong answers for some of them, but the pattern should make it pretty easy to work out what's happening.
|
# ? Jan 22, 2014 01:24 |
|
|
# ? May 9, 2024 03:21 |
|
^^^ Try running through your program yourself - pick a base and loop through the code, following your instructions. Try a few exponents starting at 0 and working up, and work out what they should be in advance. When you have an exponent of 1, total should equal base. You set that, but then you hit your loop. Because you're checking if count is less than or equal to exp, and count starts at 0, you always enter the loop and multiply your total by the base at least twice. You execute the code in the loop exp + 1 times, but you already set total to base1 before you got there. So you're actually calculating base1 * baseexp+1, or baseexp+2. You have to be careful with loops, and the code you always execute before or after them e: edits for not even noticing what I was pointing out baka kaba fucked around with this message at 01:38 on Jan 22, 2014 |
# ? Jan 22, 2014 01:32 |