Scanner Class in Java

Java Scanner is a simple text parser, it can parse a file, input stream or string into primitive and string tokens using regexp. It breaks an input into the tokens using delimiter regular expression (whitespace by default Character#isWhitespace(char)). Tokens can be converted into primitives (double, float, long, int, byte, short, boolean), number objects (BigDecimal, BigInteger) … Read more

Top-325 Core Java Interview Questions: Ultimate Collection

I had more than 50 interviews since 2010th. I collected all the most interesting and useful Java interview questions. This is not only basic coding interview questions or questions for experienced developers. I think this collection would be good for everyone even if you’re basic (entry level) or advanced engineer (advanced level) or even architect. … Read more

How To Write Simple In-Memory Cache in Java Tutorial

I want to show you my implementation of lightweight and simple in-memory key-value cache mechanism in Java. Database queries could take a time and it’s a good idea to store frequently used data in the cache to retrieve it faster. Java caching frameworks like Spring Cache allows to define your own in-memory cache implementation, so … Read more

How to Split String in Java

I think you will agree that split a string in Java is a very popular task. Usually, you need to cut a string delimiter and parse other string parts into an array or list. I’ll explain to you 5 the most popular methods how to split a string in Java.How to Split String in Java: … Read more

Random Number Generator in Java

Generating random numbers in Java is a common task. It’s frequently used in gambling, cryptography, statistical sampling and other areas where you need to simulate unpredictable behavior. I’ll explain to you how to create random number generator and show few a little bit different ways how to do that. How To Generate Random Range in … Read more

Declaring Constants in Java

Constant in programming is a variable that never changes. Today I’ll tell you about declaring constants in Java. Java doesn’t have a special keyword to define a constant. const is reserved keyword (you can’t use it as a name of a variable for example), but it’s unused. So to declare a constant in Java you … Read more

How to Reverse a String in Java

Reverse a string in Java is a quite easy task. I’ll provide you 6 pieces of Java code to reverse a string. I think StringBuilder.reverse() and StringBuffer.reverse() are the best string reverse functions in Java. It’s already optimized, looks simple and easy. But sometimes you have a task to implement string reversal using for loop, … Read more