I want to learn java for competitive programming . I'm actually aware of all the great books on java like thinking in java , effective java etc. But those books are very detailed . i want to learn enough for competitive programming without going into too much of unnecessary details . I'd be glad if somebody can tell me the resources to learn from so that i can move on to the next , more important aspect of competitive programming i.e learning data structures and algorithms .

Competitive programming, as in you are given several problem statements, an input file, and you have X time (i.e. two hours) to do as many problems as you can? You are judged solely on getting the right answer?

If that is the scenario, understand up front that your goal is to whip out code that works, one time, for that problem and whatever input you have. It does not have to maintained, it does not have to make sense to anyone but you, it does not have to be safe, it does not have to be efficient, and it will violate just about every principle of good, well designed Java programming. Understand this and understand that just about every book written is written with the goal of getting you to use good, safe Object Oriented practices, i.e. not what you're doing here. Any code that you turn in in this competition would rightfully get an F if you turned it into a professor in a programming class.

Find out ahead of time what you will have as far as resources. Are you stuck using a text editor like Notepad++ or Programmer's Notepad or can you use something like NetBeans? it's important because NetBeans has those nice auto-complete features. You'll have that nice yellow-red balloon that you can click on where with a click of a button you can surround code with try-catch or import the right package. If you're coding with a text editor, you don't have that, so you'll need to research the common imports so you can regurgitate them quickly.

  1. Make everything public. Don't waste time writing getters/setters.
  2. Don't worry about object-oriented programming. Put yourself in a C++ functional programming mindset. There's no time to design things in an object oriented fashion, and chances are they won't throw problems at you that require good object-oriented design. Use it if you need to, but again, remember your goal is to get the right output fast. Whatever works.
  3. Do exactly what is required and no more. A lot of programming is handling the "Well, what if the user does something stupid like... How do I recover from that?" scenarios. You don't care here. they'll normally tell you exactly what the input is and even give you a file. That's all you care about, and who cares if your program crashes with no hint of why instead of exiting gracefully with a usefull error message that you can stick in a bug report?
  4. Get some sample problems and practice, practice, practice. Again, it's a completely different approach than normal Java programming where before you code anything, you think, think, think about the design, how everything relates, etc., and draw it on a whiteboard. None of that here. Think about that cool scene in Appollo 13 where a bunch of engineers had to put together some weird contraption in an hour and they could only use the junk that was lying around within reach of the astronauts. They threw away every single principle of good design they would normally apply to an engineering task. That's you here.
  5. Don't worry about comments, pretty indentation, good variable names, etc. You may have a 75 line main function and no other functions. If it works, that's fine. Again, if you were to hand the code on to your professor for grading and get anything but an F, you're doing it wrong. :)

more important aspect of competitive programming i.e learning data structures and algorithms .

See above. Data structure? What's that?

It's all in the mindset. Ever see a Java programmer get exasperated trying to read a Perl programmer/shell script programmer's code? They get more exasperated when they ask the Perl programmer to explain the code and the Perl programmer shrugs and says "It works". You want to be a Perl programmer who just happens to be writing code in Java, but still thinking like a Perl programmer.

That's my philosophy on programming contests.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.