Where Beginner Learn Java, J2EE and Java related technologies. Java Learning made simple with Java related Code Snippets, Tutorials, FAQ, FlashCard, Interviews, Howto's and more...
FrontPage Posts
How to Read a File as Byte Array?
In order to get the contents of the file as array of bytes we use BufferedInputStream on top of FileInputStream. Once the file handle is open, we read the bytes from the file in chunks and copy the byte chunks in the buffer using the System.arraycopy.
Find Files in Directory based on Extension
How about finding files of a given type (extension) in a given folder? The following snippets shows how to do so, it list all the files in the directory, then using Regex pattern it tries to match the extension within the file name. If a match is found, it adds to the list.
Write a program to generate Fibonacci Numbers
In mathematics, the Fibonacci numbers are the numbers in the following sequence:
0,1,12,3,5,8,13,21,34,55,89,144
By definition, the first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two. Some sources omit the initial 0, instead beginning the sequence with two 1s.
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
F_n = F_{n-1} + F_{n-2} with seed values
F_0 = 0 and F_1 = 1.
Write a program to generate Prime Numbers
In mathematics, a prime number (or a prime) is a natural number that has exactly two distinct natural number divisors: 1 and itself. The first twenty-five prime numbers are:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97
An infinitude of prime numbers exists, as demonstrated by Euclid around 300 BC, though the density of prime numbers within natural numbers is 0. The number 1 is by definition not a prime number. The fundamental theorem of arithmetic establishes the central role of primes in number theory: any nonzero natural number n can be factored into primes, written as a product of primes or powers of different primes (including the empty product of factors for 1). Moreover, this factorization is unique except for a possible reordering of the factors.
Write a program to compute factorial of a number in Java
In mathematics, the factorial of a positive integer n denoted by n!, is the product of all positive integers less than or equal to n. For example,
5 ! = 1 x 2 x 3 x times 4 x 5 = 120
0! is a special case that is explicitly defined to be 1.
The factorial operation is encountered in many different areas of mathematics, notably in combinatorics, algebra and mathematical analysis. Its most basic occurrence is the fact that there are n! ways to arrange n distinct objects into a sequence (i.e., permutations of a the set of objects).
No Managed Connections Available
No Managed Connection Available, this exception is thrown when the client (some DAO) tries to get a database connection out of a pool (managed by connection manager) and there is no more connection available in the pool to return back. This can happen in any connection pool e.g. a pool created using the Apache DBCP or a Pool created using JBOSS datasource setup. Normally there is wait timeout that can be defined for the pool in ms, that is the amount of time the Pool Manager will wait for a connection to be available before it throws the exception. In the example stack trace the value was configured as 5000ms i.e. 5sec.
What are the advantages of Spring MVC over Struts(Original)?

When we talk about MVC frameworks Struts(original and not Struts2) is the first framework that comes to mind, not only its because has been the pioneers in this space, but its one of best frameworks till today. With the advent of Spring MVC, the possible short coming of Struts framework very take care by Spring MVC . The following are Spring MVC advantages over Struts:
