Converting between Date to LocalDate

Learn to convert from java.time.LocalDate to java.util.Date and vice-versa using the easy-to-understand Java examples. 1. Convert Date to LocalDate The Date.getTime() method returns the epoch milliseconds i.e. the number of milliseconds since January 1, 1970, 00:00:00 GMT. To get the LocalDate, we need to first set the zone offset information …

How to Format LocalDateTime in Java

Java example of formatting LocalDateTime instance to String using default formats in DateTimeFormatter class and format to custom patterns.

How To Measure Elapsed Time in Java

Learn to calculate execution time or elapsed time of program or some statements using System.nanoTime() or System.currentTimeMillis() methods.

Get Current Timestamp in Java

In Java, timestamps should be represented with java.time.Instant from Java 8, and java.sql.Timestamp till Java 7. Learn to get current timestamp in java.

Compare Two Dates in Java

Learn to compare two given dates in Java to find out which date is earlier and which is later in the universal timeline. We will see date comparison examples using the following classes: 1. Date Comparison since Java 8 1.1. Core Classes The most used date classes in Java 8 …

Converting Date to EST/EDT Timezone

Java supports three timezone constants for Eastern Standard Time i.e. “EST”, “America/New_York” and “EST5EDT”. Learn to convert date to EST in Java.

Spring Batch CSV to Database Example

Learn to use Spring Batch to read records from CSV files and insert them into the database using JdbcBatchItemWriter in a Spring Boot application.

Spring Batch ItemProcessor Example

Learn to use Spring batch ItemProcessor to add business logic after reading the input and before passing it to the writer for writing to the file/database.

Spring Batch Event Listeners

Learn to create and configure Spring batch’s listeners for capturing the important events using JobExecutionListener, StepExecutionListener, ItemReadListener, ItemProcessListener, ItemWriteListener and SkipListener.

Spring Batch Job Scheduling with @Scheduled

In enterprise applications, you will need to execute spring batch jobs periodically on fixed schedule using some cron expression passed to Spring TaskScheduler. In this example, we will execute our example spring batch job using spring’s inbuilt scheduling capability.

TypeScript Callback Function Example

TypeScript supports callback functions to make your program asynchronous. A callback function is a function which is scheduled to be called after some asynchronous processing is completed.

TypeScript Function Overloading

In TypeScript, function overloading, or method overloading, is the ability to create multiple methods with the same name and a different number of parameters or types.

TypeScript Function Types

Learn to create functions in typescript and function type declaration. We will also see how to declare and pass optional parameters, setting default value for any parameter; and rest parameters with easy-to-follow examples. Table of Contents 1. Creating a function 2. Function Types 3. Optional Parameters 4. Parameters with Default …

TypeScript Template Strings

A typescript template string (or template literal) is a regular JavaScript string which is enclosed within the back-tick characters (`) seeded with multiple placeholders denoted with ${ }. At runtime, the code replaces the placeholders with their real values. The process of evaluating a template literal containing one or more …

TypeScript Set

Set is a new data structure introduced in ES6. It allows to store distinct values into a List. Learn to create set, add and iterate set values.

TypeScript Map

Map is a new data structure introduced in ES6, to store key-value pairs. Learn to create map, add, delete, retrieve and iterate over Map entries.

TypeScript For-loop, For..of and For..in

In TypeScript, You can iterate over iterable objects (including array, map, set, string, arguments object and so on) using for…of loop. To be an iterable, an object must implement the @@iterator method.

TypeScript Compiler Configuration

TypeScript compiler uses tsconfig.json to get configuration options for generating JavaScript code from TypeScript sourcecode. When you uses $ tsc command to compile TypeScript code, compiler searches for configurations loaded in tsconfig.json.

TypeScript Literal Types

In TypeScript, string literals allow you to specify the exact value a string must have in it’s lifespan. You can assume it a form as ‘string based enum’ which also is named group of string constants.

TypeScript Enum

In TypeScript, enums are set of named constants. Though it is optional, but enums should be a named group of related constants. TypeScript supports both traditional enums and string-based enums.

TypeScript Array

Learn to create an array, add/remove items, and iterate over array items along with cloning and merging the arrays in TypeScript.

Difference between undefined and null

In JavaScript, a variable is said to be “undefined” if it has been declared but not initialized. Whereas “null” is assigned to a variable whose value is absent at the time of initialization. In simple words, when we do not assign any value to a variable, the JavaScript engine treats …

TypeScript Union Types

In TypeScript, a union type variable is a variable which can store multiple type of values (i.e. number, string etc). A union type allows us to define a variable with multiple types. The union type variables are defined using the pipe (‘|’) symbol between the types. The union types help …

Equals Operator ( == ) vs Strict Equals Operator ( === )

In TypeScript (or JavaScript), we can compare the two variables with either equality operator (‘==’) or strict equality operator (‘===’). Both comparison operators seems almost similar; but the way, they compare two given variables, is very different. The equality operator compares only the value after applying the type coercion, if …

TypeScript / JavaScript Spread Operator

The spread operator is a new addition to the features available in the JavaScript ES6 version. The spread operator is used to expand or spread an iterable or an array in Typescript or Javascript. 1. When to use the Spread Operator? The spread operator (in the form of ellipsis) can …

TypeScript Logical Operators

TypeScript logical operators are similar to what we have learned in JavaScript logical operators. These operators help in comparing boolean expressions and producing a single boolean value as result. 1. Logical Operators Operator Description Logical AND operator – && If both operands (or expressions) are true, then result will be …

TypeScript Comparison Operators

TypeScript comparison operators are the same as JavaScript. Comparison operators help in comparing two variables by their values. Please note that some operators use type coercion while comparing the values, while some do not. Please use them carefully. Type coercion means that when the operands of an operator are different …

TypeScript Type System

TypeScript supports type checking for all primitive types and object types. TypeScript also supports generics, decorators, and ES6 module types as well. It is important to learn that the type system in typescript is designed to be optional. So all programs written in JavaScript are TypeScript programs as well. Table …

Getting Started with TypeScript

In this TypeScript tutorial, learn to basics, compiler, installation and how to start development in TypeScript language with examples.

TypeScript Arithmetic Operators

An operator is a symbol that represents a specific action. An arithmetic operator can be used with one or more than values to produce a single value. In typescript, we can perform arithmetic operations using below given 10 operators. Arithmetic operators Operator Name Description and Example x + y Addition …

Difference between let, var and const

In vanilla JavaScript, variables are declared using ‘var‘ keyword. In version ES6, we can define the variables using let and const keywords too. All three keywords have similar syntax for variable declaration and initialization, but they differ in their scope and usage. 1. Differences between var, let and const We …

JavaScript Variable Hoisting

Variable hoisting in JavaScript means to move all variable declarations to top of function. This means that if we declare a variable at the end of a function, the runtime will hoist it to the top and we will not have any error if we would have used that variable …

Truthy and Falsy Expressions

In JavaScript, Truthy expressions evaluate to boolean true value and Falsy expressions evaluate to boolean false value. Unlike other programming languages, truthy and falsy values are not limited to boolean data types and comparisons. They can have many other forms. Let us learn what makes an expression truthy or falsy …

Transpiler vs Compiler

Transpilers, or source-to-source compilers, are tools that read the sourcecode written in one programming language and produce the equivalent code in another programming language with a similar level of abstraction. A good example of transpiler is the Typescript transpiler which converts Typescript code to JavaScript. Similarily, Babel transpiler can also …

[Solved] Npm install hung or takes too long time

While working on Node you may be downloading various npm packages. Sometimes the download process just hung and does not move forward. You may also see errors related to non-reachable registry.npmjs.org URL. 1. Error Log Typically error logs look like this: 2. Solution Mostly (and for me as well) this …

Spring RestTemplateBuilder Example

Learn to use Spring RestTemplateBuilder to create or build RestTemplate bean which can be used to send HTTP requests. 1. Default RestTemplateBuilder To inject RestTemplateBuilder, pass it as a constructor argument in the service class. 2. Custom RestTemplateBuilder To create custom RestTemplateBuilder, create @Bean of type RestTemplateBuilder in Spring context. …

Log Request and Response with Spring RestTemplate

In this Spring boot rest interceptor example, learn to use ClientHttpRequestInterceptor with Spring RestTemplate to log request and response headers and body in Spring AOP style. 1. Spring REST Interceptor Usages We can use this interceptor for many useful tasks. 2. REST Interceptor to Log Requests and Responses Below given …

About Us

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.