Quick references to convert string to int values in java. Included code snippets have examples of converting string values to int or Integer in multiple base or radix. Code snippets to convert string to int Output: 1001 1001 1001 513 513 513 4097 4097 4097 Convert String to int with Integer.parseInt() parseInt() method is overloaded […]
Learn to use System.getProperty(“user.dir”) and Paths.get(“”).toAbsolutePath() to get current working directory or root folder of the application.
Learn to use java.util.Random, Math.random(), SecureRandom and ThreadLocalRandom to generate random numbers based on your application requirements.
Use given syntax examples for setting CLASSPATH for any java application runtime, in windows and linux environments.
While working with encryption algorithms, you may get encrypted text as byte, which later need to be converted to String for comparison purpose. Converting byte to String in java is pretty much straightforward and easy. You need to use String class constructor String(byte bytes) or String(byte bytes, String charsetName) and you will get String represenation […]
Let’s look at few java examples of conversions between decimal, binary, octal and hexadecimals. All examples are uses native java APIs without adding any more complexity. Convert from Binary, Octal or Hex to Decimal using Integer.parseInt(String input, int radix) Use Integer.parseInt(String input, int radix) to convert from any type of number to an Integer. Convert […]
Java maintains a set of system properties for its operations. Each java system property is a key-value (String-String) pair such as “java.version”=”1.7.0_09“. You can retrieve all the system properties via System.getProperties() or you can also retrieve individual property via System.getProperty(key). Please note that Access to system properties can be restricted by the Java security manager […]
The normal import declaration imports classes from packages, so that they can be used without package reference. Similarly the static import declaration imports static members from classes and allowing them to be used without class reference. A static import declaration also comes in two flavors: single-static import and static-import-on-demand. A single-static import declaration imports one […]
Java provides four access modifiers to set access levels for classes, variables, methods and constructors. Access level modifiers determine whether other classes can use a particular field or invoke a particular method.
Classes are the basic units of programming in the object-oriented paradigm. In this tutorial, we will look into some basic yet important stuffs, you need to know, while writing a class in java. In Java, classes are used as templates to create objects. Let’s discuss how to define a class. A class in Java may […]