Tag: java
-
Record Patterns in Java
Pattern Matching is a new area where Java has been introducing quite a few changes recently. It started with instanceof operator. Previously in Java , if you had to access an object whose instance type you didnt know prior, you had to use instanceof operator this way: You had to do a cast operation as…
-
How to share data across multiple components for a single request in a Spring Boot application?
Let’s say that you make a REST API request to a spring boot web application. There is a security requirement that you need to log the user id across all the method calls in the application for this particular request. Something like this: So , if your application flow starts from a controller class and…
-
The Real Benefits of Java Lambdas
Java 8 introduced the concept of Lambda expressions. They provide a concise way to represent functions as objects. A lambda expression is essentially an anonymous function that can be treated as an object and passed around as an argument to methods or stored in variables. Here is an example: In this example, the MathOperation interface…
-
Classes in Javascript vs Java
Nothing happens outside a class in Java. To create an object you need a class. Even to print a simple “Hello World” you need a class. That is not always the case with Javascript. You can create objects without using a class. Everything need not be encapsulated within a class! There are similarities between the…
-
Variables – Java vs Javascript
Variables are critical to any programming language. It is where you store temporary data. Not all data needs to be stored in the database, whatever doesn’t need to be stored in the database and is needed temporarily during your program execution are stored in variables. Variables in Javascript differ from variables in Java in quite…
-
Java vs Javascript – Say Hello World!
One of the complaints about Java programming language is that it is verbose. Imagine you are new to programming. And you want to learn to program. The first thing most of us traditionally do is to print “Hello World!” . And to do this in Java you need to go through a lot of ordeal:…
-
try catch block in Java vs Javascript
In both Java and JavaScript, the try-catch block is used to handle exceptions that may occur in the code. The basic structure of a try-catch block in both languages is similar: a block of code is put in a “try” block, and any exceptions that are thrown in that block are caught and handled in…
-
Median of Two Sorted Arrays
Problem : Given two sorted arrays find the median of the sorted arrays when merged. Find a solution in less than O(n) time complexity where n is the length of the merged array. Also don’t use extra space – Space complexity should be O(1) What is median? Median is the middlemost element of a sorted…
-
Delete Node in a Linked List given only the node
Problem: You are given a node to delete from a linked list. But you are not given the head node. Delete it in O(1) time and O(1) space complexity. Constraints: For example, Given the linked list : 1 -> 4 -> 7 -> 8 And the node 7 to be deleted The output should be…
-
Course Schedule II
Problem : Given an integer array representing prerequisites of different courses and the total number of courses , find out the order in which the courses should be taken. For example, if the given input is [1,0] It means to take course 1 you should have completed course 0. Or in other words, Course 0…