Skip to main content

Want to Crack Java Coding Interview? Here is 4 Steps to follow - BlogonCode

Coding Interview in Java - Top four things to follow

Point to prepare before going to coding interview in Java

As a Developer, we all have to go through coding interview for any level job. So here we will seen how we can crack coding interviews.

Point to prepare before going to coding interview in Java :

  1. Java in-built classes and its methods
  2. Java collection framework and its hierarchy
  3. Data structure and algorithms
  4. Follow coding standards

1. Java in-built classes and its methods

Java have so many in-built classes and its method like, String, StringBuffer, StringBuilder, Array, etc.

These classes and its methods is so useful in our every coding life. So before coding interview, we must have to gain knowledge about classes and its frequently used methods.

  1. String : length(), split(), charAt(), indexOf(), equals(), trim().
  2. Array : sort(), length (not a method).
  3. Math : abs(), pow(), max(), min().
  4. System  
  5. Scanner

These are just a few examples of Java in-built classes and their methods. Java has a rich set of classes and libraries to help us to perform a variety of tasks.

2. Java collection framework and its hierarchy

Collection is must to know in Java. We can not imagine java language without collection framework.

Learn more about collection framework and its hierarchy :

Some of the main components of the Java Collection Framework include:

  1. Interfaces : The framework includes several key interfaces, including Collection, List, Set, Map, SortedSet, SortedMap, and Queue.

  2. Classes : The framework also includes several implementation classes, such as ArrayList, LinkedList, HashSet, TreeSet, HashMap, and TreeMap.

  3. Algorithms : The framework provides a set of algorithms for sorting, searching, and manipulating collections, such as sort(), reverse(), shuffle(), and min().

  4. Iterators : The framework provides an efficient way of iterating through collections with the Iterator interface and its implementation classes.

Learn more about Iterator in Java :

3. Data structure and Algorithms

  1. Arrays and Strings:

    • Common string operations such as reversal, palindrome check, string compression, etc.
    • Sorting algorithms like Bubble Sort, Insertion Sort, Quick Sort, and Merge Sort.
    • Searching algorithms like Linear Search and Binary Search.
    • Array data structure such as Dynamic Array, ArrayList, and 2D Array.
  2. Linked Lists:

    • Singly Linked List, Doubly Linked List, and Circular Linked List.
    • Linked List operations such as insertion, deletion, reversal, and merging of two linked lists.
  3. Stacks and Queues:

    • Stack operations such as push, pop, peek, and isEmpty.
    • Queue operations such as enqueue, dequeue, and isEmpty.
  4. Trees:

    • Types of trees such as Binary Tree, Binary Search Tree, AVL Tree, and Heap.
    • Tree operations such as insertion, deletion, traversal, and searching.
    • Applications of trees like searching for a specific node, finding the minimum or maximum node, and creating a balanced tree.
  5. Graphs:

    • Types of Graphs such as Undirected Graph, Directed Graph, Weighted Graph, and Unweighted Graph.
    • Graph algorithms such as DFS, BFS, Dijkstra's Algorithm, and Prim's Algorithm.
  6. Recursion:

    • Understanding the concept of Recursion and how it can be used to solve problems in a simpler manner.
    • Common Recursion problems like Tower of Hanoi, Fibonacci Series, and Backtracking.

4. Follow coding standards

  1. Naming conventions : Use descriptive and meaningful names for variables, methods, and classes. Java uses CamelCase for variables, methods, and classes.

  2. Indentation and White Space : Use proper indentation to make the code more readable. Follow consistent white spacing and line breaks.

  3. Use of Braces : Always use braces for the control statements, even for single-line statements.

These are some of the basic standards to follow while coding in Java. 

 

 

 

 

 

 

 

 

 

 

Comments

Popular posts from this blog

Queen's Attack II HackerRank Solution in Java with Explanation

Queen's Attack II Problem's Solution in Java (Chessboard Problem)   Problem Description : You will be given a square chess board with one queen and a number of obstacles placed on it. Determine how many squares the queen can attack.  A queen is standing on an n * n chessboard. The chess board's rows are numbered from 1 to n, going from bottom to top. Its columns are numbered from 1 to n, going from left to right. Each square is referenced by a tuple, (r, c), describing the row r and column c, where the square is located. The queen is standing at position (r_q, c_q). In a single move, queen can attack any square in any of the eight directions The queen can move: Horizontally (left, right) Vertically (up, down) Diagonally (four directions: up-left, up-right, down-left, down-right) The queen can move any number of squares in any of these directions, but it cannot move through obstacles. Input Format : n : The size of the chessboard ( n x n ). k : The number of obstacles...

Sales by Match HackerRank Solution | Java Solution

HackerRank Sales by Match problem solution in Java   Problem Description : Alex works at a clothing store. There is a large pile of socks that must be paired by color for sale. Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are. For example, there are n=7 socks with colors socks = [1,2,1,2,1,3,2]. There is one pair of color 1 and one of color 2 . There are three odd socks left, one of each color. The number of pairs is 2 .   Example 1 : Input : n = 6 arr = [1, 2, 3, 4, 5, 6] Output : 0 Explanation : We have 6 socks with all different colors, So print 0. Example 2 : Input : n = 10 arr = [1, 2, 3, 4, 1, 4, 2, 7, 9, 9] Output : 4 Explanation : We have 10 socks. There is pair of color 1, 2, 4 and 9, So print 4. This problem easily solved by HashMap . Store all pair of socks one by one in Map and check if any pair is present in Map or not. If pair is present then increment ans variable by 1 ...