Dependency Injection using factory-method in Spring
As you all know Spring uses dependency injection to create beans and the beans are by default singleton in scope with in the Spring container. Now if you have a Singleton Java class, or a factory class...
View ArticleBusy spinning in multi-threading
Busy spinning or busy wait in a multi-threaded environment is a technique where other threads loop continuously waiting for a thread to complete its task and signal them to start.while(spinningFlag){...
View ArticleReading file in Java using Scanner
Though reading file using BufferedReader remains one of the most used way to read a file but there are other ways to read a file too. Like Scanner class, which was added in Java 5, can be used to read...
View ArticleBlocking methods in Java Concurrency
There are methods in Java which want to execute the task assigned without relinquishing control to other thread. In that case they have to block the current thread in case the condition that fulfil...
View ArticleWiring Collections in Spring
In the post dependency injection in spring you would have seen examples of configuring both property values and reference to other beans. But these attributes property and ref can only be used with...
View ArticleReading delimited file in Java using Scanner
A Scanner, when reading input, breaks its input into tokens using a delimiter pattern, which by default matches whitespace.The scanner can also use delimiters other than whitespace. Scanner class has...
View ArticleReading file in Java 8
If anybody asks to point out two most prominent new features of Java 8, I guess most of the people will say Lambda expressions (along with Stream API) and interface default methods. These are...
View ArticleZipping files in Java
In Java java.util.zip package provides classes for data compression and decompression. For compressing data to a ZIP file ZipOutputStream can be used.The ZipOutputStream writes data to an output stream...
View ArticleUnzipping files in Java
The java.util.zip package provides classes for data compression and decompression. For decompressing a ZIP file you need to read data from an input stream. In the java.util.zip package ZipInputStream...
View ArticleAccess modifiers in Java
Access level modifiers are used to control the visibility of the class or the members of the class i.e. fields and methods. These modifiers will determine whether other classes can use a particular...
View ArticlePackage in Java
A package is a namespace that organizes a set of related classes and interfaces. Packages also help in preventing naming conflicts. Conceptually you can think of packages as being similar to different...
View ArticleFactorial program in Java
If we go by the definition factorial of a non-negative integer n is product of all positive integers less than or equal to n.As example4! = 4 X 3 X 2 X 1 = 24If you see here you need to multiply every...
View ArticleFibonacci series program in Java
Fibonacci series is series of natural number where next number is equivalent to the sum of previous two numbers i.e. fn = fn-1 + fn-2. The first two numbers of Fibonacci series are always 1 and...
View ArticleWriting file in Java
Though Java provides classes like FileOutPutStream and FileWriter to write files using byte stream and character stream respectively but using them directly will slow down the I/O operation...
View ArticleHow to append to a file in Java
In the post writing file in Java we have already seen how to write to a file in Java but the code given there creates a new file every time and writes the lines in the file. But there are many cases...
View ArticleString in Java
In Java String class represents character strings which means; Strings in Java are objects and all strings are instances of the String class. Internally in String class Strings are stored as character...
View ArticleString comparison in Java
In String class there are number of methods provided to compare the Strings or the portion of the strings.Some of the most used are mentioned here -startsWith() and endsWith() methodsboolean...
View ArticleString charAt() and subString() methods in Java
If you are trying to get characters and substrings by index with in a String then charAt() and subString() methods respectively can be used.If you are looking for methods to compare string in java...
View ArticleSearching within a String using indexOf(), lastIndexOf() and contains() methods
There are scenarios when you want to find characters or substrings within a string. For that purpose String class provides accessor methods that return the position within the string of a specific...
View ArticleSplitting a String using split() method in Java
String provides a split method in order to split the string into one or more substring based on the given regular expression.split() method has 2 variants -split(String regex) - Splits this string...
View Article