Posts

Showing posts from September, 2014

Setting up EJB3 Development Environment with Eclipse and JBoss

Image
I gave up my 30 day Programming challenge   after a few days only, partly due to time-constraints and partly because the problems I had been working on didn't seem challenging enough.Learning EJB3 took a priority and I started on that path. Here on my blog I will share my journey as I progress on the path. The first step was picking up a good book. I had purchased EJB3 In Action long back, so planned to go with it.I had recently seen a review about the second edition of this book.I thought the second edition will be pretty much the same as the first one with a little bit of addition here and there about EJB 3.1.Don't know what motivated me to take a peek at the second edition, and that very moment I decided to start with the second edition only. Got a soft copy in mobi format, so that I can read it on Kindle app in my mobile and tab. I read through Chapter 1 which is kind of introduction or the 25000 feet view of EJB3. Once I started chapter 2, I felt the need to se...

Day# 5 of Java Programming Practice- Change the first letter of each word in a sentence to Uppercase.

Image
This problem also seemed simple and I didn't take much time to write this one. In fact I decided to move on to the next problem again today and post two of them together. But on reading the next problem I felt that I will be able to do it better once I am through with regular expressions. So, taking a break to read through the topic of regular expressions before diving into the next problem.   Here is the problem and my solution of the day. The problem is just to change the first letter of each word in a sentence to capital case.  

Day#4 of Java Programming Practice- Two Simple programs

Image
Today's program turned out to be quite simple , so I completed two of them. the first problem is to replace each letter of the string to its subsequent letter and change the case of all vowels in the resulting string to capital. All characters other than alphabets should be left as is. Here is my program and its output: The second program is to keep adding all numbers from 1 up to a given argument. Here is the program and its output: Closing this not so interesting day, will be back again tomorrow with something interesting hopefully.

Day#3 of Java Programming Practice- Longest word of a Sentence

Image
Today's problem is finding longest word of a sentence.The twist being, in case any of the words has punctuation marks, the punctuation should be ignored while calculating the length of that word. My first choice to separate each word in the sentence was by using a String Tokenizer, but when I looked in the documentation for the syntax, it told me that using split is a better idea. This twist of ignoring punctuation mark got me thinking , and this is the program I wrote along with the output. Though it gives correct output, I felt it to be an ugly version. I started looking on the net for a better solution, Though I didn't get an exact solution of this problem, I did get an interesting idea that helped in making the program look better. So here is the second version of my program.  This made me realize that I need to work on learning regular expressions properly. And the learning notes will certainly make it to a post on this blog.  Signing off for tod...

Day#2 of Java Programming Practice: Return Factorial of a number

Image
Taking a first look at this problem, I decided to skip it as it seemed very simple. Then I thought, may be instead of using the simple for-loop, I will try writing it using recursive function. This did turn out to be a challenge for me because I had always avoided learning and practicing recursions. This is the final version of the program I wrote and its output:  On successful completion of the above, I started searching the solutions on the net for a better approach. This led to posts where it was mentioned that my approach won't give correct results for large numbers as the factorial will be out of range of int and long. So, we need to use BigInteger to solve the problem. Taking the advice, I started working on updating my program to make use of BigInteger. This again was a challenge for me as I was not familiar with the availability and usage of BigInteger methods and fields. This is the final version of the program and its output.  As I was struggling with writ...

Java Programming Practice- A new 30 day challenge

Image
It has been a long while since I worked on improving my technical knowledge or tried polishing my existing skills. Its never too late, so starting now. Here comes my latest 30 Day challenge. For coming 30 days, I will write one practice program everyday , compare it with other examples floating on the net, and find out what would have been a better way to do that. The practice program of the day: Reverse the String passed to a method. Here is what I wrote:   The output of the program is something like this :  gnirtS esreveR fo tset si sihT   Now for the better way of doing it: Instead of converting to character Array and then looping through I could have used the charAt method of the String class directly inside the loop. Here is the updated version:     We can reverse an input String also using the inbuilt reverse() method of the Stringbuffer and StringBuilder. But here is one approach (using recursion) that caught my eye: ...