If you are a Java developer who has been using Eclipse for Java development, but you need to use Netbeans for your current project for various reasons, this article is for you. Whenever we transition between tools, we need the equivalent of one into other. For example, if you are an Eclipse power user who is used to Ctrl + Shift + R and Ctrl + Shift + T, you miss those as soon as you start using Netbeans shortcuts. One thing to keep your productivity up is to quickly find the equivalent shortcut in a new tool, like, Netbeans if you are switching from Eclipse or vice-versa.
Learn Java and Programming through articles, code examples, and tutorials for developers of all levels.
How to convert int value to a Long object in Java? Examples
Suppose you have an int variable but the part of the application is expecting a Long object, how do you convert a primitive int to a Long object in Java? It shouldn't be a problem, right? after all long is a bigger data type than int, so all int values are acceptable as long, but we also need a Long object, not just the long primitive value. Now, the problem is reduced to converting a long primitive to a Long object, which is not really a problem if you are running on a JRE version higher than Java 5. But, sometimes autoboxing is not efficient like when you have to convert multiple long values into the Long object in a loop.
How to Create Random Alphabetic or AlphaNumeric String of given length in Java? SecureRandom Example
Hello Java programmers, if you want to create a random alphanumeric string and looking for examples then you have come to the right place. Earlier, I have shown you how to generate random numbers in a range, and in this article, you'll learn how to generate random alphanumeric String in Java. Suppose, you want to generate an alphabetic or alphanumeric string of a given length in Java? How do you do it? Well, if you are like me, you probably search a library like Apache commons-lang or Google Guava for something which can do this task. It's a good thing. There is no point in re-inventing a wheel if a tried and tested solution already exists. In fact, Effective Java, the most respected book in the Java world also suggests knowing and use your library.
How to Order and Sort Objects in Java? Comparator and Comparable Example
Java Object Sorting Example
How do you sort a list of Objects in Java is one of the frequently asked coding questions in Java interviews and surprisingly not every Java programmers know How sorting of object happens in Java. Comparator and Comparable interface along with Collections.sort() method are used to sort the list of objects in Java. compare() and compareTo() method of Comparator and Comparable interface provides comparison logic needed for sorting objects. compareTo() method is used to provide Object's natural order sorting and compare() method is used to sort Object with any arbitrary field.
Difference between int and Integer data type in Java? Example
The first and foremost difference between an int and Integer or a char and Character is that the former is a primitive data type while the latter is a class, also known as wrapper class because they wrap the primitive data type inside it. When you first start learning Java, you start with primitive data types like int, long, char, byte, boolean, float, and double but slowly you learn about Object, and sometime later you know about Integer, Long, Character, Byte, Boolean, Float, and Double. At this point in time, you may wonder, what is the real difference between an int and Integer? isn't both the same? We can pass Integer where int is expected and vice-versa then why on the earth we have both int and Integer?
Subscribe to:
Posts (Atom)