Get Current Working Directory in Java
To find the current working directory for any Java application, we can use System.getProperty(“user.dir”) or Paths.get().toAbsolutePath().
“Core Java” is Sun’s term, used to refer to Java SE, the standard edition and a set of related technologies, like the Java VM, CORBA, etc. This is mostly to differentiate from others like Java ME or Java EE. “Core Java” is Oracle’s definition and refers to subset of Java SE technologies.
The Core Java technologies and application programming interfaces (APIs) are the foundation of the Java Platform, Standard Edition (Java SE). They are used in all classes of Java programming, from desktop applications to Java EE applications.
To find the current working directory for any Java application, we can use System.getProperty(“user.dir”) or Paths.get().toAbsolutePath().
In this example, we will learn to serialize the java objects into XML files and then de-serialize them back to the original java objects.
Knowing the difference between Externalizable vs Serializable is important in two aspects, one – if could be asked as an interview question, two – you can use the knowledge to make better informed decision for performance improvement for applying serialization into your application.
You can achieve more efficient serialization by implementing Externalizable interface and overriding it’s methods writeExternal() and readExternal().
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.
Java examples of reading a file from the resources folder from a jar file, war file, spring application or the development environment.
I encountered this exception while building spring MVC file upload example. The error stacktrace looks like this: Solution You have incorrect version of apache commons-fileupload. To solve this error, you correct version 1.2.1. This will solve your error. Happy Learning !!
In this Java OOPs concepts tutorial, we will learn four major object oriented principles– abstraction, encapsulation, inheritance, and polymorphism. They are also known as four pillars of the object oriented programming paradigm.
We may be asked to write a program to calculate factorial during coding exercises in Java interviews. This always better to have an idea of how to build such a factorial program. 1. What is Factorial? The factorial of a number is the product of all positive descending integers up to …
BlockingQueue is excellent when you want to skip the complexity involved in wait–notify statements. This BlockingQueue can be used to solve the producer-consumer problem as well as given blow example. As this problem is well known to every programmer, I am not going in detail of problem description. How BlockingQueue …
Learn different techniques to iterate over a Java Collection (List, Set and Map) using for-loop, enhanced for-loop, Iterator and Java Stream.
Let’s look at a few Java examples of conversions between decimal, binary, octal, and hexadecimal. All examples use native Java APIs without adding any more complexity.
Learn to write Java programs to reverse a String. Learn how to reverse the characters of a string and then how to reverse the words.
Learn about the lifecycle of a Thread in Java, and how the state transitions happen between different states of the Thread by JVM and OS.
Learn to join string array with delimiter to produce single string. Use listed java example to convert list of strings or array of strings to single string.
Knowledge of how to secure REST APIs is as much necessary as writing the APIs themselves. Mostly REST APIs are HTTP protocol-based, and any user having an internet connection can access them, and so can bad users as well. It is crucial to write secure APIs to protect the business. …
Concurrency means multiple tasks running in overlapping time periods. Parallelism is when several parts of a unique task run at the same time
Java maintains a Set of system properties that can be accessed in the runtime by executing programs. Each system property is a key-value pair. For example, one such system property is “java.version”=”1.7.0_09“. We can retrieve all the system properties via System.getProperties() or we can also retrieve individual property via System.getProperty(key) …
Learn to create new date, get current date, parse date to string or format Date object using java.util.Date class. These use-cases are frequently required, and having them in one place will help in saving time for many of us.
Java offers many useful ways to get current date or current time using Date, Calendar and newly introduced LocalDate, LocalDateTime and ZonedDateTime classes in Java 8 Date/Time API classes.
One of our reader, Anant, asked this extremely good question to elaborate / list down all related topics that we should know about multi-threading including changes made in java 8.( Beginner level to Advance level). All he wanted to know was evolution of Multi-threading Framework in Java from Simple Runnable …
You may have faced this question in your interview that what is the difference between lock and a monitor? Well, to answer this question you must have good amount of understanding of how java multi-threading works under the hood. Short answer, locks provide necessary support for implementing monitors. Long answer …
Learn to find difference between two dates in days, months or any other time units – using Java 8 classes such as Duration, ChronoUnit and finally JodaTime.
We must have heard multiple times that enums are always the best choice for implementing singleton design pattern in java. Are they really the best? If it is then how is it better than other available techniques? Let’s find out. Writing a singleton implementation is always tricky. I already discussed …
Java enumerations are only applicable for legacy classes e.g HashTable, and Vector. Iterator is the recommended way to iterate over collections since Java 1.2 and takes place of Enumeration.
The given Java program uses a TreeMap to store the length of words as Map key, and all similar length strings in a List as Map value.
1. What is a Complete String? A string is said to be complete if it contains all the characters from a to z. If it misses even a single character, it is considered an incomplete string. For example, the following string is a complete string. It contains all the characters …
Good strings do not have the same consecutive letters. We simply need to perform one operation – if there are two same consecutive letters, delete one.
When Java Iterator detects the modifications, it cannot guarantee iteration consistency and throws the ConcurrentModificationException.
Multiple inheritance is a feature of some object-oriented computer programming languages in which an object or class can inherit characteristics and behavior from more than one parent object or parent class.
Java Jsoup parses HTML. It provides a very convenient API for fetching URLs and extracting and manipulating data with examples.
Learn to create password-protected zip files using a very useful library Zip4j that uses completely Java code without any native code.
Learn to set environment variables e.g. JAVA_HOME when you don’t have admin access to your development windows machine.
Learn to align a string to left, right or center in Java using the utility StringAlignUtils, which wraps all the alignment logic inside it.
The static import statements import the static fields and methods from a class and allow them to be used without the class reference.
Java provides four access modifiers to set access levels for fields, methods and constructors i.e. public, private, protected, and default.
Classes are the basic units of programming in the object-oriented paradigm. In this tutorial, learn to write Java class and how to create object in Java.
The Java continue statement skips the current iteration of a for loop, while loop, or do-while loop and moves to the next iteration.
The break keyword in Java is used to terminate for, while, or do-while loops. It may also be used to terminate a switch statement as well.
Java do-while loop executes the statements in do block, and then evaluates a condition in the while block to check whether to repeat the execution.
The while loop in Java continually executes a block of statements until a particular condition evaluates to true, else the loop terminates.
Since Java 1.5, the for-each loop or enhanced for loop is a concise way to iterate over the elements of an array and a Collection.
Java for-loop statement is used to iterate over the arrays or collections using a counter variable that is incremented after each iteration.
Java switch statements help in providing multiple possible execution paths for a program. Java switch statements can be used in place of if-else statements to write more cleaner and concise code. Java switch statements have evolved over time. In this tutorial, we will learn about basic switch statement features and …
Java if-else statements help the program execute the blocks of code only if the specified test condition evaluates to either true or false.
A block statement is a sequence of zero or more statements enclosed in braces. A block statement is generally used to group together several statements, so they can be used in a situation that requires you to use a single statement. 1. What is a Block Statement? Generally, a java …
A statement specifies an action in a Java program. For example, a statement may tell the add of values of x and y and assign their sum to the variable z. It then prints a message to the standard output or writes data to a file, etc. Java statements can …
Learn about available Java operators, and precedence order and understand their usages with examples. We will also try to understand when to use which operator and what to expect in the result. 1. Java Operators An operator is a symbol that performs a specific operation on one, two, or three …
We must have heard the terms Little-Endian and Big-Endian many times in your engineering course. Let’s quickly recap the concept behind these words. 1. Little-Endian vs Big-Endian These two terms are related to the direction of bytes in a word within CPU architecture. Computer memory is referenced by addresses that …
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.