JPA is a standard for ORM. It is an API layer that maps Java objects to the database tables. All you need is to annotate your Domain object with @Entity.
In Spring Boot, Spring Data JPA brings the goodness of Spring Data and JPA together.
In the JDBC world we have to embed sql queries inside the codebase to access the database, JPA hides all that complexity by providing many CRUD related methods via JpaRepository.
Let’s take a look
In this post, I am discussing how we can create a simple API with Spring Boot. This post discusses about Repository, Controller/Resource and Model layer.
Let’s get to it. 🚀
Prerequisite: Make sure you have Java 11 and maven installed.
Head over to _start.spring.io_ from your favourite browser and create a starter project. Add these three dependency from the Add Dependency tab on right pane.
JPA : JAVA Persistence API. Provides lot of methods to interact with database.
H2 : In memory relational database.
Spring Web : Uses Apache Tomcat as default embedded container.
Click on Generate at the bottom…
Coffee and software engineers match made in heaven, right? Well, that might be an overstatement but we have to agree that nothing beats a good cup of coffee to kick start your morning.
We all have read, watched, and talked about our office setup with a cool keyboard, mouse, and expensive headsets but coffee. I feel coffee deserves an article as well since it is an integral part of our dev space, at least for most of us.
I live in Coffee capital, Seattle where rain consumes most of the year. …
Timsort was implemented by Tim Peters in 2002, it has been a standard sorting algorithm for Python since Python 2.3. Python’s sorted and list.sort function uses Tim sort. Java uses Timsort in JDK for sorting non primitive types. Android platform and GNU Octave also uses it as a default sorting algorithm.
Timsort is a stable algorithm and beats every other sorting algorithm in time. It has O(nlogn) time complexity for worst case unlike quick sort and O(n) for best case scenarios unlike merge sort and heap sort.
In real world scenarios, most of the times input array is naturally ordered…
Shuffling cards is an essential part of every card game. There are many techniques for shuffling cards but overhand and riffle are the most popular ones.
In this shuffle a set of cards are transferred from bottom of the deck to the top of the deck and the same process gets executed recursively.
What happens when we run Arrays.sort() in Java? which sorting algorithm Java uses in background?
Since Java 7 release back in 2011, default sorting algorithm used is DualPivotQuickSort which is an enhancement over classic quick sort algorithm.
Dual pivot quick sort is a combination of insertion sort and quick sort. Insertion sort has faster runtime when the number of elements to be sorted is small, Double pivot quick sort uses this fact thus when the number of elements are <= 47 Java performs insertion sort under the hood.
When input size array is larger than 47 Java uses Double pivot…
Find duplicates inside a sorted array?
This is an extension of problem we have discussed in an earlier post.
I like this problem more because there iss more thinking involved and it forces us to write down the algorithm without using an extra space.
First Hint to solve this problem is how could we utilize the fact that input array is SORTED?
Whenever I see SORTED in a problem statement ‘Binary Search’ is the first thing that comes to my mind but that won’t work in this case because we have to find all the duplicates that exists inside the…
In my last post
I wrote about finding duplicates inside an array of integers. What if input is a string instead of integers? Could we solve the problem in same way we did before?
String is essentially an array of characters so we still could use HashTable/ Set like before to store chars instead this time.
Although algorithm wise we didn’t learn new anything but now we know that strings are essentially an array of chars and we could utilize that fact going forward in string related problems.
dev.to is where software developers stay in the loop and…
Whenever I prepare for the interviews I start with “Arrays and strings” and then move to Linkedlist, trees and eventually find myself lost in plethora of topics that I don’t know much about like Dynamic programming, Graphs etc.
So here we go again, hopefully I get through most of them this time, more importantly understand better what I know already hence writing here.
Problem: Finding duplicates inside an array?
Solution: Let’s draw a simple example of what is expected in this problem.
What are the concerns and questions I have as soon as I hear/read this problem.
I personally gets excited and worried both at the same time when nodejs major version gets released. Node community sure do follow a very aggressive release cycles, almost every 6 month there’s a new release of Node.
Unfortunately, I fall in the category of latecomers where I am working on a Node Project which nodejs version 4.x.x. in production but great community of node got us covered there too. Node version manager a.k.a ‘nvm’ worked effortlessly in my case to maintain different version of node.
Learner, Philomath. Engineer by choice, humorous by nature. Big fan of technology.