Dijkstra's algorithm allows us to find the shortest path from one vertex in a graph to all other vertices in the graph. It is a great algorithm for finding the shortest path in an explicit graph (that is, a graph that is defined using an adjacency list or an adjacency matrix). However, if the graph is implicit (we don't have the actual graph, just rules for how it can be created), then Dijkstra's algorithm can be problematic.
In my opinion, you can use either of the two approaches, as it depends on the problem.
You can refer the following link which solves the fifteen puzzle in Java using A* and Dijkstra's algorithm:
Interested in learning Artificial Intelligence? Learn more from this Artificial Intelligence Online Course!