|
Okay so very basic coding question here but even after googling and harassing quite a number of people i can't seem to find out how. How would i iterate through an ArrayList and count how many times each element occurs in the array and produce an answer which will display the element which occured the highest number of times?
|
# ? Mar 14, 2008 02:19 |
|
|
# ? May 13, 2024 07:09 |
|
itsasnake posted:Okay so very basic coding question here but even after googling and harassing quite a number of people i can't seem to find out how. Lazy way: code:
|
# ? Mar 14, 2008 03:00 |
|
Yeah, i sorted the list into an ArrayList of 1050 elements. Can you elaborate please?
|
# ? Mar 14, 2008 03:04 |
|
itsasnake posted:Yeah, i sorted the list into an ArrayList of 1050 elements. Can you elaborate please? Something like this: code:
|
# ? Mar 14, 2008 03:19 |
|
Thanks, appreciated, i'll go play with that for a bit.
|
# ? Mar 14, 2008 03:53 |
|
How does one go about implementing the externalizable interface so that a treelike object can't overflow the stack? I came across this issue and while realistically it shouldn't affect me I couldn't figure it out.
|
# ? Mar 15, 2008 20:44 |
|
OK, I know homework questions are frowned upon here, but I just want to make sure I'm on the right track. We are supposed to create a real-world entity, then make a subclass that is a specialized form of that entity. I've got both of those done. (CellPhone and SmartPhone, smart phone having data minutes in addition to regular minutes and all the other stuff cell phone has via super();). The final part is where I'm getting a little confused. it says 'Illustrate composition by developing a third class that is used by one or both of the first classes[in my case cell/smartphone]'. I'm planning on creating a customer class that 'has-a' cell phone or smart phone. Is this what y'all think he's trying to get us to do? If i create a constructor with a cellphone argument, can I put a smartphone in there? edit: Okay, I threw the customer class together and I could use either one. I'm pretty sure I'm on the right track, but I'd still greatly appreciate any advice. PuTTY riot fucked around with this message at 21:41 on Mar 15, 2008 |
# ? Mar 15, 2008 21:03 |
|
Sterra posted:How does one go about implementing the externalizable interface so that a treelike object can't overflow the stack?
|
# ? Mar 15, 2008 23:06 |
|
American Jello posted:OK, I know homework questions are frowned upon here, but I just want to make sure I'm on the right track. We are supposed to create a real-world entity, then make a subclass that is a specialized form of that entity. I've got both of those done. (CellPhone and SmartPhone, smart phone having data minutes in addition to regular minutes and all the other stuff cell phone has via super(). If the third class needs to 'be used' by one of the first two, a Customer would 'use' a phone, rather than than a phone 'using' a customer. So you might make a class for a phone number and say that they both 'use' a phone number, or a web browser, which only the smart phone uses. But I doubt that's the important part. I think what you're supposed to understand is the difference between having an instance of a class (customer has a phone), and being an instance of a class (smart phone is a cell phone). You also might be making this more complex than it really is, because it sounds like you have it down just fine.
|
# ? Mar 16, 2008 00:06 |
|
See, this is why I came in here for a second opinion. I had the right idea but I misread what he wanted us to do. Went ahead and used the phone number idea, it took some more work than the customer class, but I need an A in this class so I don't really care. Thanks for the help.
|
# ? Mar 16, 2008 02:40 |
|
Reflection! And Generics! I'd like to get the type parameter, as a Class, Type, or even just the canonical name String, used in a generic class. For example, I'd like to get the Class object for java.lang.String from a Vector<String> object, or a Class object for java.lang.Integer from a Vector<Integer> object. I found the Class.getTypeParameters() method, but the best I can get out of that is a java.lang.Object Type object. This isn't crucial to my project, so if it's impossible it's impossible. It would really simplify maintenance and documentation if there is a way to get it, though. Any ideas?
|
# ? Mar 18, 2008 01:42 |
|
ColdPie posted:Reflection! And Generics! Just to double check what you're meaning, given any Vector<?> you want to retrieve the class of ? at runtime? Sorry to say but you can't. Java uses type erasure for generics which means at runtime all the type information is gone.
|
# ? Mar 18, 2008 02:04 |
|
F'Nog posted:Just to double check what you're meaning, given any Vector<?> you want to retrieve the class of ? at runtime? Sorry to say but you can't. Java uses type erasure for generics which means at runtime all the type information is gone. Lame. Then what's the point of Class.getTypeParameters()?
|
# ? Mar 18, 2008 02:04 |
|
ColdPie posted:Lame. Then what's the point of Class.getTypeParameters()? It just gives you a nice representation of the classes generic declaration. i.e. code:
|
# ? Mar 18, 2008 03:53 |
|
Yeah, using generics at runtime is pretty much a dead end in the current implementation. It's just a compiler restraint (so you can, for example, get access to stuff like that by using an annotation processor, but that's unlikely to be what you want).
|
# ? Mar 18, 2008 08:41 |
|
I just started a co-op (my first job programming), and one thing I see in a lot of the code is the following: private final int ONE = 1; private final double FIVE = 5.0; I always thought that was bad coding; why not just use 5.0 in the code. The only thing I can think of is if you want to be able to modify all references of "FIVE" in one location. However, it probably shouldn't be named "FIVE" if you want to do that, because if you change it to FIVE = 6.0, then the name of the variable isn't really useful anymore. Is this bad coding practice, or am I just stupid? They also do multiple return statements in methods often, which I thought was another no-no.
|
# ? Mar 18, 2008 22:40 |
|
Ranma4703 posted:I just started a co-op (my first job programming), and one thing I see in a lot of the code is the following: It's strange, yes, and you're right to recognize it as odd. That said, they may very well have a good reason in whatever context it exists (though it had better be good for something like that). This happens a lot when you hit the Real World, it's not often black-and-white this-is-good-and-this-is-bad. Ask another developer why it is like it is, but don't sound like a stuck-up academic prick about it
|
# ? Mar 18, 2008 22:57 |
|
Ranma4703 posted:They also do multiple return statements in methods often, which I thought was another no-no.
|
# ? Mar 18, 2008 23:42 |
|
BELL END posted:I've never understood the big hullabaloo about this. Depending on the size of the method, having just one exit point can definitely be helpful. That said, you shouldn't have monolithic methods that can't fit on a screen if you can help it.
|
# ? Mar 18, 2008 23:50 |
|
BELL END posted:I've never understood the big hullabaloo about this. Me neither. It's one of those things that just comes down to readability. Multiple return statements are bad when they're bad - ie hard to read - and not when they're not. Just like everything else.
|
# ? Mar 18, 2008 23:53 |
|
Ranma4703 posted:I just started a co-op (my first job programming), and one thing I see in a lot of the code is the following: code:
The better answer is csammis's: ask them about it. If there's some good reason for it you might want to know what it is. quote:They also do multiple return statements in methods often, which I thought was another no-no.
|
# ? Mar 19, 2008 00:54 |
|
BELL END posted:I've never understood the big hullabaloo about this. Personally, I think a lot of "rules" like that are established in schools so that novice programmers learn to keep code easier to read and it's an unwritten rule that once you have a serious justification for it that all those old "rules" are irrelevant. That's kinda how I view rules in general, but unfortunately I keep getting flack for violating the "don't kill the mailman" rule because apparently I don't have enough experience killing people in general yet to justify killing the mailman.
|
# ? Mar 19, 2008 02:28 |
|
Ranma4703 posted:Is this bad coding practice, or am I just stupid? They also do multiple return statements in methods often, which I thought was another no-no. It seems to be bigger deal in C. I try to keep a single exit point in Java methods, but hardly anyone else does where I work, and it never gets brought up in code reviews.
|
# ? Mar 19, 2008 04:02 |
|
I've now gone through two courses of Java-programming in my university and while I feel I know the basics of the syntax and object orientated programming, I'm a little frustrated that I don't really know how to program anything usable or sensible. Knowing how to program Game of Life or how to implement interfaces isn't exactly an adrenaline rush. So do you have any advice where to go from here towards actual programming?
|
# ? Mar 19, 2008 14:57 |
|
Contract Otter posted:I've now gone through two courses of Java-programming in my university and while I feel I know the basics of the syntax and object orientated programming, I'm a little frustrated that I don't really know how to program anything usable or sensible. Knowing how to program Game of Life or how to implement interfaces isn't exactly an adrenaline rush. There's no "golden path" when it comes to programming. Just practice... alot, start small and work towards bigger projects, find out what works / is effective and read up on things you'd like to be able to do in your apps and apply them. Sort of generic advice, but programming is a pretty big subject that it's impossible to have "do this, then do that".
|
# ? Mar 19, 2008 17:51 |
|
Contract Otter posted:I've now gone through two courses of Java-programming in my university and while I feel I know the basics of the syntax and object orientated programming, Don't say orientated.
|
# ? Mar 20, 2008 01:42 |
|
such a nice boy posted:Don't say orientated. I find it really disorientating when people pronounce it that way.
|
# ? Mar 20, 2008 03:51 |
|
Twitchy posted:There's no "golden path" when it comes to programming. Just practice... alot, start small and work towards bigger projects, find out what works / is effective and read up on things you'd like to be able to do in your apps and apply them. Sort of generic advice, but programming is a pretty big subject that it's impossible to have "do this, then do that". Yeah, I guess I'll just think of something and start coding. such a nice boy posted:Don't say orientated. I'm actually pretty impressed how stupid I made myself seem but I guess I'm just not linguistics orientated enough.
|
# ? Mar 20, 2008 06:44 |
|
I feel like strangling Java right now, so to keep myself away from the police I will ask here. I'm no stranger to Java, on my 5th year of my 4 year comp-sci program I know it front and back. Somehow though, Sockets seem to be destroying me right now and I have no idea why. It seems that the order in which I create the input/output streams from a socket may or may not break the program. Here's what I mean,code:
code:
|
# ? Mar 21, 2008 06:59 |
|
ReaperUnreal posted:The java doc is of no help quote:Creates an ObjectInputStream that reads from the specified InputStream. A serialization stream header is read from the stream and verified. This constructor will block until the corresponding ObjectOutputStream has written and flushed the header. You're causing deadlock by waiting for input before it's been produced in the same thread. zootm fucked around with this message at 10:13 on Mar 21, 2008 |
# ? Mar 21, 2008 10:10 |
|
zootm posted:ObjectInputStream(java.io.InputStream) Huh, how did I not see that? Thanks for the help, looks like I'll be reorganizing things. This'll be fun, having to create input and output streams inside a loop. Honestly, some times, I wish I was using C instead of Java.
|
# ? Mar 21, 2008 16:03 |
|
Some general tips: Learn a functional programming language if you don't know one. You'll never make money from it, but you'll get a good perspective. Try Lisp or Haskelif. Never write code when there is a good tool out there that will do the job for you. Java is very thready so you need to learn how threading works. This is especially true if you plan on writing GUIs. JMX is a good thing. JConsole is your friend. You'll never find deadlocks faster. Logging is a good thing. You'll never find bugs faster. Learn the JVM parameters, especially those about memory. Know that 64bit JVMs need about twice the memory that 32bit JVMs need. Plan for failures, especially around integration with remote systems. Make sure to fail as gracefully as is appropriate. Deadlock is seldom the right answer. Crashing sometime is. Here are some tools I have found useful: Ant is nice build tool. Its like make for java but good. If you don't know it and you plan to make money with java then you need to learn it. You'll never type javac again. Once you learn Ant, learn Maven. Its better because its more than a build tool, its a project management tool. Guice is a simple framework for dependency injection. Its like Spring, but very simple. If you are writing a sizable application or a reusable library then I suggest this as glue. The google collections library has some neat tools. I just found it so I haven't used it yet, but I can see the potential. Logback is the best logging framework I've used. You need a logging framework so you may as well use the best. Logback is fast and conventient. Any slf4j log framework is good. I'd stay away from Apache commons logging because it can have funky class loader problems. JCS is a well thought through caching system. Its good if you really need to cache things from a database. Speaking of databases, I've had a great time using Postgresql. Its quick and second only to Oracle in terms of features. The only real problem is that you have to tune the hell out of it when you get large databases (bigger than your ram). Saxon is a great Swiss army knife for XML. It does Xquery and XSLT quite quickly and quite correlty. Use it if you absolutely have to do stuff with xml. Antlr is a fun tool for text/pattern recognision. If you can't do it with regular expressions, you can do it with Antlr. Its documentation is kind of weird, but the mailing list is good. Its also stupid fast. Not yacc fast, but still.
|
# ? Mar 21, 2008 16:06 |
|
ReaperUnreal posted:Huh, how did I not see that? Thanks for the help, looks like I'll be reorganizing things. This'll be fun, having to create input and output streams inside a loop. Honestly, some times, I wish I was using C instead of Java. nik9000 posted:Once you learn Ant, learn Maven. Its better because its more than a build tool, its a project management tool. zootm fucked around with this message at 18:57 on Mar 21, 2008 |
# ? Mar 21, 2008 18:55 |
|
zootm posted:Maven's always a point of contention; a lot of people don't like it. I'm not personally a fan myself, I find its behaviour a little too opaque and wide-ranging. It's respected by a lot of other people too, though, it's just a bit of a "love it or hate it" thing. I'm in the Ant + Ivy camp myself. Maven is really a bitch to get going.
|
# ? Mar 21, 2008 20:17 |
|
Okay, I have an Eclipse problem. I'm trying to do a school project with it, but I can't figure out how to get it to do what I need it to. I have a large set of precomplied class files which don't have any source files with them (well, only 2 have their source code, the rest are just .class files). I'm trying to do a project in which I have to extend the one class that I have the source for. However, when I try to use that directory with Eclipse, it deletes all of the .class files. Is there any way I can make a project with a preexisting library of .class files in eclipse?
|
# ? Mar 21, 2008 22:52 |
|
I'm looking for guidance on recommended online Java studying resources. I'm in-between a junior and senior-level type of corporate programming position, and having to switch focus from the .NET framework to Java due to being placed in a new development group that is completely Java oriented. I'm concerned about building up my Java knowledge so I can hold my own in the new position, as opposed to interviewing for a new job. I'm already using Eclipse at work and have access to a lot of Java source code to help me hit the ground running. I know some aspects of the Java language and have worked on modifying existing code in a few Java-based projects, but now I need to bulk up on the fundamentals, design patterns, various frameworks and APIs (JMS, Spring, threading, etc.). For plain Java, Eckel's Thinking in Java was recommended earlier in this thread, and I noticed his 3rd edition, published in 2002, is available for free but his 4th edition is not free. Here's a link to the third edition, which has link to 4th edition page: http://www.mindview.net/Books/TIJ/ Are there any significant differences between Eckel's 3rd and 4th editions that I should consider purchasing the 4th edition instead? I don't mind spending money if I will be able to obtain the latest-and-greatest information. How useful are Sun's Java Learning Center pages? http://java.sun.com/learning/index.html How effective is the Java Blackbelt site for testing your own knowledge for various Java-based frameworks and APIs? http://www.javablackbelt.com/ On first glance I'm not crazy about javablackbelt.com's contribution-point system, since I do not like have my learning held back by a system that requires me to spend time attempting to add value to website content based on a subjective criteria. I also don't like their mandatory waiting period to retake tests, unless I can skip the belt-obtainment altogether.
|
# ? Mar 22, 2008 04:23 |
|
Spartan22x posted:Okay, I have an Eclipse problem. I'm trying to do a school project with it, but I can't figure out how to get it to do what I need it to. I have a large set of precomplied class files which don't have any source files with them (well, only 2 have their source code, the rest are just .class files). I'm trying to do a project in which I have to extend the one class that I have the source for. However, when I try to use that directory with Eclipse, it deletes all of the .class files. Is there any way I can make a project with a preexisting library of .class files in eclipse? Hmm, perhaps you need to treat the existing class files with no source code as external libraries for the project, which is no different than referencing a separate jar file. Put your class files in a separate directory from the source folder, then open up your Java project's properties and add the classes as a library (under the libraries tab of the Java Build Path setting). Just leave out the classes from the class folder that you have the source-code for, since Eclipse will build new classes for those .java files.
|
# ? Mar 22, 2008 04:28 |
|
nnnotime posted:For plain Java, Eckel's Thinking in Java was recommended earlier in this thread, and I noticed his 3rd edition, published in 2002, is available for free but his 4th edition is not free. Here's a link to the third edition, which has link to 4th edition page: In 2002, it'd be talking about Java 1.3 or 1.4 (both are pretty drat old). I wouldn't look at anything which talks about Java before 1.5 except for purposes of maintaining legacy code. Even with legacy code 1.4.2 is as old as I'd venture and I'm hoping to avoid having much to do with my company's clients still stuck on 1.3.1. It's still important to know when certain things came into being or became usable (Ask me about JAXB 1.0), but new code should be predominantly written with the newer versions of the language. quote:How useful are Sun's Java Learning Center pages? The Sun documentation can be pretty good, although I'm not a fan of their XML/Web Services tutorials and security is just a nightmare regardless. Learning the (very) extensive APIs should probably be one of your first goals. Start out with something simple and sane like java.util.logging and slowly expand your horizons outwards.
|
# ? Mar 22, 2008 05:52 |
|
1337JiveTurkey posted:In 2002, it'd be talking about Java 1.3 or 1.4 (both are pretty drat old). I wouldn't look at anything which talks about Java before 1.5 except for purposes of maintaining legacy code. Even with legacy code 1.4.2 is as old as I'd venture and I'm hoping to avoid having much to do with my company's clients still stuck on 1.3.1. It's still important to know when certain things came into being or became usable (Ask me about JAXB 1.0), but new code should be predominantly written with the newer versions of the language. I'm curious what that client's excuse for sticking with Java 1.3 is. Did they use some Sun internal API that got removed?
|
# ? Mar 22, 2008 13:57 |
|
|
# ? May 13, 2024 07:09 |
|
TRex EaterofCars posted:I'm curious what that client's excuse for sticking with Java 1.3 is. Did they use some Sun internal API that got removed?
|
# ? Mar 22, 2008 16:46 |