This discussion is archived
3 Replies Latest reply: Oct 26, 2012 12:56 PM by 939520 RSS

Any source for java exercises with solution

S M Newbie
Currently Being Moderated
Experts,
Need some information.

I am new to JAVA. I have programming background of C and PL/SQL
I know the basics of JAVA and now want to learn JAV through exercises.

I am able to find many exercises but without any solution.
Anybody has idea regarding any form/blogs/websites where I can find java problems with solution. By this I will be able to practice and verify my code with the solution?

Kindly suggest.
Thanks,
M S
  • 1. Re: Any source for java exercises with solution
    gimbal2 Guru
    Currently Being Moderated
    Not really, its more the territory of books. There is Head First Java which is written to teach through puzzles, games and exercises. Then there is also the official SCJP/OCJP study guide which has a great deal of exercises at the end of each chapter (with the answers in the back of the book). The latter is nice to have if you think about going down the certification route of course, but its quite dry material.

    Here is a nice exercise for you I pitch to juniors: create a command line hangman with the following rules and restrictions:

    - the game asks for your name and addresses you with it
    - possible words you can guess need to be loaded from a text file. You could use this one for example: https://github.com/andypike/hangman/blob/master/dictionary.txt
    - a word is randomly chosen, the game does NOT allow the same word to be chosen twice in a row
    - you need to be able to play multiple rounds, the game automatically starts a new round each time you win or lose
    - the game keeps track of how many times you won and how many times you lost
    - you can guess wrong at most 10 times
    - the game does not penalize you when you guess a character already guessed before
    - the game displays the word to guess , but only all letters you guessed correctly. Letters not guessed yet are displayed as underscores (_).
    - if the player inputs more than one character and anything other than a to z, the game simply ignores it and asks for a guess again.

    An example: say the word is 'tree'. When the game starts and the user input his/her name it displays this:
    You have 10 guesses left.
    Word to guess: _ _ _ _
    Guess? : <character will be input here>
    Player chooses 'e'.
    Correct! You have 10 guesses left.
    Word to guess: _ _ e e
    Guess? : <character will be input here>
    Player chooses 'd'.
    Wrong! You have 9 guesses left.
    Word to guess: _ _ e e
    Guess? : <character will be input here>
    Player chooses 'e' again.
    Already guessed! You have 9 guesses left.
    Word to guess: _ _ e e
    Guess? : <character will be input here>
    etc. etc. If you think this is an easy exercise: you are quite wrong. You have to do File I/O, you'll probably want to use one or more collection classes, you have to figure out randomization, you do several String operations, you do some work with I/O streams and it is a nice introduction into application flow and state management.
  • 2. Re: Any source for java exercises with solution
    S M Newbie
    Currently Being Moderated
    Thanks gimbal2 !
  • 3. Re: Any source for java exercises with solution
    939520 Explorer
    Currently Being Moderated
    As previously stated, books are a good way to go. Look for good reviews at amazon.com for any book you are considering. After you read a book on Java and try compiling/running several of its examples on the command line, you can consider downloading Eclipse IDE which is very popular with Java developers. Then I suggest installing a free database such as Oracle Express. Then read up on JDBC and see if you can get your Java program to perform CRUD operations against a database table. Next get a book on JSP/Servlets (assuming you're interested in web application development). I know JSP is getting pretty old and many recommend other things like JSF, but JSP is installed on countless existing applications that you will almost certainly work in future jobs.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points