Reading Substring in Java

A substring is a String object created from another String object. In Java, you can get substring in multiple ways based on which String class you are using. Classes like String, StringBuffer, StringBuilder have substring and subSequence methods which can return substring. One thing we have to remember is that the index of string start … Read more

Comparing Two String Objects in Java

String class provides equals method for comparing two String objects. Comparing two String variables: Output: However, this may result in NullPointerException if str1 is null. So, it is always better to check if the reference variable is not null, which is calling the equals method. Output: You don’t have to null check for the variable … Read more

Callback Function in Node.js

A callback function is a function which can be passed as an argument into another function. This callback function can then be invoked inside the outer function. Callback functions were introduced in JavaScript. Since Node.js built on V8 engine, it also support callback functions. In the above example, doComplete is a callback function. This program … Read more

Basic web application in Node.js to return text

Here we write a basic web application in Node.js that serves static text to the client’s HTTP requests. Added an event listener on the server variable that listens to the request events. The event listener takes a callback function with two arguments, request and response. If there is a request, node.js will raise a request … Read more

Why does a while loop blocks the event loop?

How Node.js process this program? flag variable declaration will be placed in call stack and it will be initialized to true. setTimeout() function call will be placed in call stack. Node.js start the timer and schedules a timer event for 1 second. The callback function will be placed in MessageQueue after 1 second. Node.js continues … Read more