|
The problem I have with BlueJ is that, unless you really have problems grasping object oriented fundamentals, it doesn't offer much that other IDEs don't while teaching you some processes that don't really exist outside of BlueJ. That's not to say it's a bad program (I learned on it back in my first CS course) but I would just be aware that there really isn't anything like it in wide use.
|
# ? Jul 21, 2013 00:04 |
|
|
# ? Jun 3, 2024 00:21 |
|
carry on then posted:Are you creating a new project for each problem? If not, it thinks the new file you've started is going to be called from some other file. In Netbeans you can right-click on the file and choose Run, as long as it has a public static void main method. Oh, no I was creating new files within the same project. And yeah that works. Thanks! I think compiling isn't too hard, but an IDE looks so much nicer! But fine, you're right, I should just practice doing everything. I'm poo poo with computers, unfortunately.
|
# ? Jul 21, 2013 00:07 |
|
Hand Model posted:Oh, no I was creating new files within the same project. And yeah that works. Thanks! I'm not saying you should drop Netbeans right now if it works for you, more that it sounds like you're working with smaller problems, and something as monolithic as Netbeans can seem to be in your way at times.
|
# ? Jul 21, 2013 00:08 |
|
carry on then posted:I'm not saying you should drop Netbeans right now if it works for you, more that it sounds like you're working with smaller problems, and something as monolithic as Netbeans can seem to be in your way at times. I agree that I am having some dumb and frustrating problems in it. And that's a waste of time. But then I went to the command line and it's not much better haha
|
# ? Jul 21, 2013 00:16 |
|
I use an IDE for its auto complete features and code highlighting and set up javac.exe as a default program option (right click > open with > javac) for easy compiling. If it doesn't compile, I bring up the command prompt to see the error, but the IDE is usually good about highlighting my errors before I get to that point.
|
# ? Jul 23, 2013 11:47 |
|
What does this mean?code:
If isBar is true, it...adds a space and a literal asterisk? Otherwise it adds nothing? In other words: (boolean test) ? (if true do this) : (otherwise do this) The syntax just seems confusing and I'm not quite sure how to google it.
|
# ? Jul 24, 2013 14:53 |
|
mister_gosh posted:What does this mean? It's known as the ternary operator: http://java.about.com/b/2009/06/06/java-term-of-the-week-ternary-operator.htm
|
# ? Jul 24, 2013 14:58 |
|
The ending parenthesis should be after the boolean test, but yes, that's the jist of it. code:
http://www.ibiblio.org/java/course/week2/43.html
|
# ? Jul 24, 2013 15:00 |
|
Been creating a screen scraper for a few web pages in java. I am using jsoup to parse some html after I get back the pages. In general I can iterate through multiple pages on the site using some URL parameter which the page is using. However I have hit a speed bump with a specific website I am attempting to scrape, they seem to be using ajax to update the page. I am unsure how I will invoke the 'button' which is going to the next page. I assume it is ajax because the url does not change. Does anyone have any insight on this?
|
# ? Jul 24, 2013 15:07 |
|
Well you could look at the page and figure out how the onclick method fetches the next page, or you can ask Stack Overflow and get suggested to use this library to provide what you need. You still need to inspect the page you're scraping to know what its 'next page' button is, though.
|
# ? Jul 24, 2013 17:59 |
|
DholmbladRU posted:Been creating a screen scraper for a few web pages in java. I am using jsoup to parse some html after I get back the pages. In general I can iterate through multiple pages on the site using some URL parameter which the page is using. However I have hit a speed bump with a specific website I am attempting to scrape, they seem to be using ajax to update the page. I am unsure how I will invoke the 'button' which is going to the next page. I assume it is ajax because the url does not change. Does anyone have any insight on this? JSoup doesn't really support AJAX pages IIRC. When I ran into this problem a while ago I ended up looking into the Javascript. Once I pieced together the call to the external service that was being made I manually called the exposed service. From there you will need to figure out how to process the data as it could return HTML, JSON, XML or whatever. If it returns HTML just parse it with JSoup, if it returns JSON I would plug into GSON or your favorite Java JSON library, and XML I usually work with the built in DOM parser because I'm to lazy to learn a better XML library.
|
# ? Jul 24, 2013 18:06 |
|
lamentable dustman posted:JSoup doesn't really support AJAX pages IIRC. When I ran into this problem a while ago I ended up looking into the Javascript. Once I pieced together the call to the external service that was being made I manually called the exposed service. From there you will need to figure out how to process the data as it could return HTML, JSON, XML or whatever. Thanks for the information. I think that HtmlUnit will support the javascript calls to iterate through the ajax pages. Once I perform that maybe I could use jsoup to parse through the html. Any suggestions on how to find the javascript call attached to this button?
|
# ? Jul 24, 2013 19:48 |
|
Use firebug plugin for firefox. Inspect the button and hopefully you can trace the function that gets called.
|
# ? Jul 24, 2013 20:29 |
|
If you're working entirely 'headless' (not strictly the definition, but if you're working straight from a terminal interface then y'know), you might have to use heuristic guesses of searching through (X)HTML tags for something suggesting the word 'next (page)' and then looking around that for an onclick method.
|
# ? Jul 24, 2013 23:04 |
|
Can anyone recommend some good books or other resources for a long time C# developer looking to gain a deeper understanding of Java? I've been a .NET programmer for >5 years and am pretty comfortable with Java at a high level. I've recently started a new job where I'll need to get up to speed with Java and am looking to expand my knowledge. I don't need anything that starts off with "Hello world!" or "What is a class?" but I've never really done anything with Java outside of a classroom either. I'm looking for stuff similar to CLR via C# but for Java and the JVM - something that explores some more advanced topics like threading, concurrency, performance, what's going on under the hood, etc. Everything I find on Amazon is either a basic intro to Java or seems pretty outdated. For example: Java Concurrency in Practice - this sounds like it would be useful but it's 7 years old. Is it still relevant?
|
# ? Jul 29, 2013 21:25 |
|
Horse Cock Johnson posted:Can anyone recommend some good books or other resources for a long time C# developer looking to gain a deeper understanding of Java? Concurrency in Practice is a very good java book. I'm also a fan of Effective Java. Despite being 7 and 5 years old, they're still pretty relevant. The latest Java Version is Java SE 7, out in 2011, which... doesn't really contain a lot that's super interesting. Just some convenience stuff - Strings in switch statements, ways to represent binary literal integers, etc. Java 6, out in 2006, was the last big change, and Java 8 (2014?) is going to have a lot of convenience stuff for lamdas and functional-ish programming, which will be great to work with. It has been my experience, starting out with Java about a year ago, that familiarizing myself with the Apache Commons and Google Guava libraries has been incredibly useful. They contain the things that should be in core Java but aren't. Gravity Pike fucked around with this message at 21:44 on Jul 29, 2013 |
# ? Jul 29, 2013 21:40 |
|
This is probably a dumb question, but doing a google search hasn't helped me understand. I'm making a new servlet project in Eclipse (well, okay a "Hello World" thing). I'm using the New Dynamic Web Project wizard, and the third page of the wizard is Web Module, where there are two options: Context Root and Content Directory. I've learned that context root is the root directory, so if should leave it as "\" if I want it to look in the "E:\Tomcat7\webapps\ROOT\...". I'm not quite sure what the Content Directory is, what it is looking for there. Google says that it "serves files from there". I don't know what it wants. Thanks for helping.
|
# ? Jul 30, 2013 13:50 |
|
Question about ConcurrentModificationException, but may be unexpected: Say, I have a list, and go over it with one iterator that duplicates entries, and with another iterator that selectively deletes entries. I imagine that 'undetermined behavior' here would be not knowing whether there has been duplication or deletion. If so, I think that could be desired behavior for some hypothetical case. If I'm correct, I could just catch the exception and continue. Or am I incorrect and there could be some other consequences?
|
# ? Jul 30, 2013 17:02 |
|
supermikhail posted:Question about ConcurrentModificationException, but may be unexpected: The Iterator class does not specify the precise mechanism of iteration. The iterator might retrieve one element from the collection at a time. It might retrieve elements from the collection in size 5 blocks. It might make its own internal copy of the collection and do something fiddly to keep it synchronized. So if you try to modify the list with two iterators at the same time, you have absolutely no guarantee as to what will happen; it's not as simple as "oh well they might both hit the same element at the same time". In any case, there is also no guarantee that a ConcurrentModificationException will be thrown, so you cannot rely on catching it for your program to function correctly. Amarkov fucked around with this message at 18:37 on Jul 30, 2013 |
# ? Jul 30, 2013 18:32 |
|
I would consider my program to function correctly if it continued working despite all (whether by catching runtime exceptions or missing some glitches), and didn't break my computer. Or run out of memory by accident... Oh, I just will have to test it out. Have to.
|
# ? Jul 30, 2013 21:05 |
|
I mean, you can always make the program keep running by doingcode:
|
# ? Jul 30, 2013 21:12 |
|
If you can keep a secret, I had this as part of an idea of artificial evolution while commuting. /secret.
|
# ? Jul 30, 2013 21:31 |
|
supermikhail posted:If you can keep a secret, I had this as part of an idea of artificial evolution while commuting. /secret. I think it's deterministic, just not guaranteed in any given circumstance.
|
# ? Jul 30, 2013 22:03 |
|
Amarkov posted:
Generally, you're going to want to catch Exception instead of Throwable, unless you're able to handle things like OutOfMemoryError or StackOverflowError. Errors are generally unrecoverable, and your best bet is to let your program bail.
|
# ? Jul 30, 2013 22:14 |
|
Gravity Pike posted:Generally, you're going to want to catch Exception instead of Throwable, unless you're able to handle things like OutOfMemoryError or StackOverflowError. Errors are generally unrecoverable, and your best bet is to let your program bail. I recover from them by running the program on a remote supercomputer e: trex eaterofcadrs posted:I think it's deterministic, just not guaranteed in any given circumstance. Yes, this is correct. I don't know how it's actually done, but the obvious fail-fast implementation has completely uninteresting behavior; the first iterator will simply stop working whenever a modification is made using the second iterator. Amarkov fucked around with this message at 02:09 on Jul 31, 2013 |
# ? Jul 30, 2013 23:08 |
|
Gravity Pike posted:Generally, you're going to want to catch Exception instead of Throwable, unless you're able to handle things like OutOfMemoryError or StackOverflowError. Errors are generally unrecoverable, and your best bet is to let your program bail. Also VirtualMachineError and ThreadDeath, which is silently thrown and handled when Thread.stop() is called.
|
# ? Jul 31, 2013 04:18 |
|
Max Facetime posted:Also VirtualMachineError and ThreadDeath, which is silently thrown and handled when Thread.stop() is called. Using Thread.stop() is just about as much of a horror as catching Throwable.
|
# ? Jul 31, 2013 16:46 |
|
It's not nearly as bad as Thread.suspend() and Thread.resume() at least. Really it's the same thing as doing throw new ThreadDeath(); in your code. Except you can also cause that to happen while someone else's code is executing. Sun's/Oracle's documentation makes a big deal about Objects being left in unknown states making their further use risky, but to my mind the important use is in a fast and reliable cleanup of resources that a plugin manager might perform. If the unknown code that's executing doesn't corrupt all the state when faced with a thrown OutOfMemoryError then it should survive a ThreadDeath too. E: well not survive per se, but you know what I mean. For something like a plugin system it's not perfect but it's as good or better than the alternatives: making threads interruptible and/or relying on some custom shutdown procedure existing and working in a timely manner. I know I've written something like this a few times: Java code:
Max Facetime fucked around with this message at 23:34 on Jul 31, 2013 |
# ? Jul 31, 2013 23:31 |
|
Interrupts are everywhere 'cause spurious wakes are a real thing. The key trick is every interruptible call really needs to matched with a loop+condition. If you really want to guarantee a 'sleep' for at least some time : Java code:
|
# ? Aug 1, 2013 03:40 |
|
Brain Candy posted:
... and at this point, I'm just going to use Uninterruptibles.sleepUninterruptibly(), because Guava includes
|
# ? Aug 1, 2013 09:52 |
|
Looking at it, Guava still has the same problem because it's basically the loop I posted plus actually forwarding the interrupt. The heart of the issue is Thread.sleep(long,long). There are no guarantees about the minimum argument it consistently works for. For years, on windows (maybe still?), Thread.sleep(1) actually slept 10ms because that was the period of the available system timer. This isn't a big deal if you pass 1000ms into it, you've just got to be aware that the accuracy is going to be significantly less than the precision and that it's machine/jvm/os dependent.
|
# ? Aug 1, 2013 13:30 |
|
Tomcat 7 says that it is started and running, but http://localhost:8080/ is giving me a (Tomcat-generated) 404. I swear this poo poo was working the other day. I have no idea why it isn't working now. Tomcat is clearly running, it's generating the 404 message, so why can I not see it (or any other html or jsp page) that are in the webapps\ROOT directory?
|
# ? Aug 1, 2013 15:50 |
|
Stabbey_the_Clown posted:Tomcat 7 says that it is started and running, but http://localhost:8080/ is giving me a (Tomcat-generated) 404. I swear this poo poo was working the other day. I have no idea why it isn't working now. Tomcat is clearly running, it's generating the 404 message, so why can I not see it (or any other html or jsp page) that are in the webapps\ROOT directory? For starters, try clearing the work folder in tomcat and make sure that webapps folder has permissions set correctly, toss a chmod -R 777 in there. After that, any errors in the tomcat logs? Also double check what the expected URL should be. Probably http://localhost:8080/<webapp foldername>/ The trailing slash can be important, if /<foldername> doesn't work makes sure you try /<foldername>/ Zaphod42 fucked around with this message at 15:58 on Aug 1, 2013 |
# ? Aug 1, 2013 15:56 |
|
EDIT: Deleting the bad project thing seems to have fixed it I think. I think chmod is Linux only. This is Windows, but the properties shows that I have full control over that directory. It appears I screwed something up when making a stupid test project in Eclipse, because the only page that actually works is "http://localhost:8080/HelloWWW2". Wonderful. How do I un-screw it? In the Eclipse project, I set the URL mappings to /HelloWWW2, and changed the content directory from \WebContent to \ROOT. Apparently something like that was the wrong thing to do. I saw this in the catalina log: "Aug 01, 2013 10:25:39 AM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:HelloWWW2' did not find a matching property." The localhost access log shows everything coming up 404's except for HelloWWW2. Stabbey_the_Clown fucked around with this message at 17:26 on Aug 1, 2013 |
# ? Aug 1, 2013 16:20 |
|
Stabbey_the_Clown posted:EDIT: Deleting the bad project thing seems to have fixed it I think. Oh, that's probably a snafu from the Eclipse Tomcat plugin (or is it called the web plugin?). What I usually did when I had to run tomcat from Eclipse was to tell the tomcat server (In the servers view) that it should use the existing tomcat configuration and not make a copy for itself (which is what it does by default). You can change that in the properties page of the server. If you cannot (the radio buttons are disabled) just delete the server and re-add it. Whenever it messes up I usually just remove/re-add the server information. Dunno if it's the best way, it usually worked for me. Since you're working on a test project ... you're probably ok to remove the project as well and just make a new one.
|
# ? Aug 1, 2013 19:06 |
|
I am attempting to create a jsp website. I have some functionality working, however I am attempting to port over some stand alone code into my application. This code references external jar files which have been imported into the web project in eclipse. However I keep getting a class not found error when I execute my method. Do I need to perform <%@page import="com.class"%> on external jar files which are found under 'Referenced Libraries' ? Let me know if this is unclear edit:nevermind. they need to be in the lib directory... DholmbladRU fucked around with this message at 20:58 on Aug 1, 2013 |
# ? Aug 1, 2013 20:45 |
|
I need to collect metrics in memory and occasionally flush the list contents to the database. What's the best data structure to use that will be threadsafe while metrics are being collected, but that I can also switch out to dump the ones in memory to the database in a timer thread? Should I just use Collections.synchronizedList, and then every now and then swap references from a live list to a secondary list so metrics can be collected while the dumping is going on? Is there any simple pattern for doing this?
|
# ? Aug 6, 2013 22:38 |
|
I think that a ConcurrentLinkedQueue will do just what you want without having to use a Collections.synchronizedList. However I don't think your approach to switching out the references is the correct way to do it. I suggest that the dumping job immediately creates a copy of the queue, then does the inserts and finally tells the queue to removeAll elements in your copy. If no one else but this dump job is reading the queue then this should be safe. Another possible more light-weight approach is for the dump job to create an iterator and then for each element, removes and insert it / batch it into your bulk insert. This however might not terminate if the iterator reflects new items that were added to the queue after its creation, which the javadoc doesn't spell out. quote:The returned iterator is a "weakly consistent" iterator that will never throw ConcurrentModificationException, and guarantees to traverse elements as they existed upon construction of the iterator, and may (but is not guaranteed to) reflect any modifications subsequent to construction.
|
# ? Aug 6, 2013 23:16 |
|
Hard NOP Life posted:I think that a ConcurrentLinkedQueue will do just what you want without having to use a Collections.synchronizedList. However I don't think your approach to switching out the references is the correct way to do it. Hmm thanks lets see... the javadoc makes it sound like it may get new elements in which case I'd have the same concern about the job never ending. However in your first suggestion I like the fact that removeAll isn't called until the end of the dump job - if I do the dump in one transaction and it fails, its nice that those elements won't be lost and the next job can get them all. To do the copy should I just pass the original list into a ConcurrentLinkedQueue(collection) constructor? If so this should work out pretty well, I appreciate it. edit - well this turned out pretty easy: code:
FateFree fucked around with this message at 00:46 on Aug 7, 2013 |
# ? Aug 6, 2013 23:45 |
|
|
# ? Jun 3, 2024 00:21 |
|
Can't you just use .drainTo() on the queue? Just drain the queue to a new list, and it's atomic.
|
# ? Aug 7, 2013 02:06 |