There are several ways to create an array in Java, for example, you can declare the array without initializing it, or you can create and initialize the array in the same line. If you want to make an array with values, then you need to first decide which type of array you want to create? e.g., do you want a String array, which can contain String objects like "abc," "def," or do you want to create an int array that contains int values like 10, 20, etc. In Java, you can create an array of any type, including primitives like byte, int, long, and objects like String, Integer, and other user-defined objects. Let's some code to make a new array in Java. 1. Creating String array in Java There are three main ways to create a String array in Java, e.g. here is a String array with values : String[] platforms = {"Nintendo", "Playstation", "Xbox"}; and here is a String array without values : String[] games = new String[5]; This array can hold 5 String objects because its length is 5. It's mandatory to define the length of a variety while making, and you cannot change the length once created. You can also do something like this : String[] actors = new String[5]{"Hero", "Heroine", "Friend", "Villain", "Dragon"}; All there are correct ways to make an array in Java. Though, if you are not familiar with an essential data structure like an array and linked list, then I suggest you first go through these best data structure and algorithms online courses. It's a very important topic for any programmer be it a core Java developer or Java web developer and you just can not afford to ignore this. How to create an Int array in Java? You can use the same syntax as shown above to create an int array, all you need to do is replace String with int values as shown below : making an int array with values int[] primes = {2, 3, 5, 7}; int array without values : int[] even = new int[5]; length of this array is 5, hence it can only hold 5 int values. If you don't assign values then by default they hold the default value of their type like int array will have zero in every index, and the String array will have null. You can further see these best Java online courses learn more about different types of the array in Java. How to access array elements in Java? You can access array elements using index, e.g. primes[0] will return the first element from an array that is referenced by the prime variable. Remember, the array index starts with zero. If you want to iterate over an array, i.e. wants to go access every element then you can use a loop, e.g. for, while or a do-while loop. You can also use advanced for loop in Java, which allows you to iterate over array without index as shown below : for(String str : platforms){ System.out.println(str); // Nintendo, Playstation, Xbox } The minimum index in the array is zero, and the maximum index is length - 1. That's all about how to make an array in Java. You have also learned how to initialize the array at the time they are created and how to access them with and without index using advanced for a loop. Though, there are many ways to create an array in Java and even more ways to loop over them. For example, you can also use while, do-while, and classic for loop to iterate over an array in Java. Other Java array tutorials you may like Do you want to learn more about the array data structure? The most important Data structure for a programmer - If Yes, here are a couple of more articles which you can explore to learn about Array better: How to create an array from ArrayList of String in Java (tutorial) Top 30 Array-based Coding Problems from Interviews (questions) 7 Best Udemy courses to learn Data Structure and Algorithms (courses) How to remove duplicates from an unsorted array in Java? (solution) 10 Data Structure Courses to Crack Programming Interviews (courses) Best of Data Structure Problems from Interviews (questions) 10 Courses to learn Data Structure and Algorithms in Java (courses) How to find all pairs whose sum is equal to a given number in an array? (solution) 10 Courses to learn Java for Beginners (courses) How to reverse an array in place in Java? (solution) 10 Algorithms Books Every Programmer Should Read (books) 10 Free Data Structure and Algorithm Courses for Beginners (courses) Top 20 Searching and Sorting Interview Questions (questions) How to make a binary search tree in Java? (solution) 10 (Free) Online Courses to Learn Data Structure and Algorithms in Java (courses) 50+ Data Structure and Algorithms Interview Questions (questions) Thanks for reading this article so far. If you like this article then please share it with your friends and colleagues. If you have any questions or feedback then please drop a note. P. S. - If you are looking to learn Data Structure and Algorithms from scratch or want to fill gaps in your understanding and looking for some free courses, then you can check out this list of Free Algorithms Courses on HackerNoon to start with.
A collection of frequently asked linked list interview questions from Programming Job interviews for beginners and experienced Java, C++, and Python Programmers.
300 Core Java Interview Questions | Set 1, OOPs interview questions. With assurance of 90% core java interview questions, there are given 201 core java interview questions and answers with java, .net, php, database, hr, spring, hibernate, android, oracle, sql, asp.net, c#, python, c, c++ etc.
we will discuss the difference between Method and constructor in Java language. This is a very important concept in Java for students or programmers.
Java Method is very much similar to a normal method or a function written within a class definition. Java method is basically a set of statements group together to perform a specific task. This method is included in a class. An object instantiated from a class can call methods of that class. Every Java method
A handy Java Cheat Sheet is useful for the aspiring Java developers and contains ready-to-use codes for application development.
Polymorphism vs Overloading vs Overriding Someone asked me the other day, what are the difference between Polymorphism and Overriding in Java and the similar difference between Polymorphism and Overloading. After explaining to him personally, I thought to write a blog post about it and here we are. Well, they are not two different things, Polymorphism is an object-oriented or OOP concept much like Abstraction, Encapsulation, or Inheritance which facilitates the use of the interface and allows Java program to take advantage of dynamic binding in Java. Polymorphism adds flexibility to your code which makes it more extensible and maintainable. Polymorphism is also a way through which a Type can behave differently than expected based upon which kind of Object it is pointing. Overloading and overriding are two forms of Polymorphism available in Java. Both overloading and the overriding concept are applied to methods in Java. Since Polymorphism literally means taking multiple forms, So even though you have the name of the method the same in the case of overloading and overriding, an actual method called can be any of those multiple methods with the same name. Let's see some more details on method overloading and overriding to understand how polymorphism relates to overloading and overriding and how they are different. Btw, if you are new to Java and Object-Oriented programming then I highly recommend you to join a comprehensive course like Java Programming for Complete Beginners - Java 17 by Ranga Karnam of In28Minutes on Udemy. This 30-hour course is great to learn both Java and OOP fundamentals from scratch. Polymorphism and Overriding? Overriding is a form of polymorphism that is used in Java to dynamically bind the method from the subclass in response to a method call from a subclass object referenced by superclass type. Method overriding is bonded using dynamic binding in Java. Suppose you have two methods size() in both base class and derived class and base class variable is pointing to an object which happens to be subclass object at runtime then method from subclass will be called, I mean, the overridden method will be called. This allows programming for interface than implementation, a popular OOP design principle because Polymorphism guarantees to invoke the correct method based upon the object. Method overriding is key for many flexible design patterns in Java, like Strategy and State Design Patterns in Java. If you want to learn more about design patterns in Java then I highly recommend you to join this Design Patterns in Java course by Dmitri Nestruck on Udemy. It's a great course to learn the modern implementation of classic Java patterns, I highly recommend every Java programmer to join this course to learn patterns for writing better code. Polymorphism and Overloading Method overloading is another form of Polymorphism though some people argue against that. In the case of overloading, you also got multiple methods with the same name but different method signatures but a call to correct method is resolved at compile time using static binding in Java. Overloading is a compile-time activity as oppose to Overriding which is runtime activity. Because of this reason overloading is faster than method overriding in Java. Though beware of an overloaded method that creates conflict e.g. methods with only one parameter like int and long etc. See What are method overloading in Java for example and complete details. An Example of Polymorphism in Java An example of Polymorphism in Java Let's see a short example of Polymorphism in Java. In this example, the Pet variable behaves polymorphically because it can be either Cat or Dog. this is also an example of method overriding because the makeSound() method is overridden in subclass Dog and Cat. import java.util.ArrayList; import java.util.List; abstract class Pet{ public abstract void makeSound(); } class Cat extends Pet{ @Override public void makeSound() { System.out.println("Meow"); } } class Dog extends Pet{ @Override public void makeSound() { System.out.println("Woof"); } } Let's test How the Polymorphism concept works in Java: /** * * Java program to demonstrate What is Polymorphism * @author Javin Paul */ public class PolymorphismDemo{ public static void main(String args[]) { //Now Pet will show How Polymorphism work in Java List pets = new ArrayList(); pets.add(new Cat()); pets.add(new Dog()); //pet variable which is type of Pet behave different based //upon whether pet is Cat or Dog for(Pet pet : pets){ pet.makeSound(); } } } Output: Meow Woof In Summary, you can not compare Polymorphism with method overloading or override. Polymorphism is the ability of a variable to behave differently based upon which kind of Object it is referring to. They are Java programming language's way to implement polymorphism in language. Other Java programming and OOP tutorials You may like My favorite courses to learn object-oriented programming 5 difference between Hashtable and HashMap in Java 5 Free Object-Oriented programming course for beginners What is a factory method design pattern in Java Top 5 Courses to Learn Design Patterns in Java 10 design pattern interview questions in Java – Answered What is the Factory method design pattern in Java What is the Observer design pattern in Java How to implement the Singleton pattern in Java How to implement the Producer-Consumer pattern in Java 5 Free Data Structure and Algorithms Courses Difference between HashMap and ConcurrentHashMap in Java 7 best OOP design pattern courses for Java developers 10 Java Coding Interview Questions and Answers for Java beginners. 5 Free Spring Framework Courses for Java Developers Difference between TreeSet and HashSet in Java 10 Free Courses to learn Java for Beginners and Experienced Programmers Thanks for reading this article so far. If you like this object-oriented programming interview question and my explanation then please share them with your friends and colleagues. If you have any questions or feedback then please drop a note. P. S. - If you are serious about learning object-oriented programming and looking for a free online course to start with then you can also check this FREE Object Oriented Programming (OOPs) for JAVA Interviews course on Udemy. It's completely free and you just need a free Udemy account to join this course.
The for loop is executed when the Boolean expression evaluated until the condition is satisfied. - For loop in Java programming language
An array is one of the fundamental data structures and most of the other advanced data structures like lists, hash tables are built using arrays. Good knowledge of fundamental data structures like the array, linked list, a binary tree is not just essential for writing better code but also doing well on Programming Job interviews. Array-based questions are quite popular in Java interviews. There are two types of questions you will find, first which are based upon array implementation in Java, and second which are based upon how to use an array data structure to solve some coding problems. The first type of question is quite popular in the telephonic round of Java interviews and the second is usually asked on written tests and face-to-face interviews. In this article, I am going to share some of the frequently asked array-based questions from Java interviews, which include both array concepts questions which are based upon how you use an array in Java programming language, and second is general array-based coding problems. These questions are mostly collected from Java interviews for junior and intermediate programmers, who have 0 to 5 years of working experience in Java. Some tricky questions like the question no 2 and 15 are also good for senior and more experienced Java professionals. In fact, one of my friends didn't get question 15 right, he was actually surprised by the fact that you can make an array volatile in Java. Btw, if you are new to the Java Programming world, there is no better way to get familiar yourself with the essential data structure in Java by joining The Complete Java MasterClass, which covers the Java Collection framework, where you can find the standard implementation of all important data structure in Java. Java Array Concept Interview Questions Here are some interview questions based upon the array data structure in Java. You need to have good knowledge of how an array is implemented and work in Java to answer these questions. Since an array is one of the most used data structures, it's expected from programmers of all levels (including beginners and experienced) to have a good grasp of array concepts. These questions are mostly asked in a telephonic round of Java interviews. Your answer to these questions must be focused and to the point, without any added syntactic sugar. Question 1: What is an array? Can you change the size of the array once created? [answer] An array is a fundamental data structure to store objects and primitive values. You have different types of array, like 1-dimension, 2-dimension, and N-dimensional array. No, you cannot change the size of the array once created. If you need a dynamic array, consider using the ArrayList class, which can resize itself. Question 2: Can you store String in an array of Integer in Java? compile-time error or runtime exception? [answer] This is a tricky question. The answer is both yes and no. You cannot store a string in an array of primitive int, it will result in a compile-time error as shown below, but if you create an array of Object and assign String[] to it and then try to store Integer object on it. The compiler won't be able to detect that and it will throw ArrayStoreExcpetion at runtime. int[] primes = new int[10]; primes[0] = "a"; //compile time error Object[] names = new String[3]; names[0] = new Integer(0); // ArrayStoreException at runtime Question 3: What is the difference between ArrayIndexOutfOBounds and ArrayStoreException? [answer] The ArrayIndexOutOfBoundsException comes when your code tries to access an invalid index for a given array, like a negative index or higher index than length - 1. While, ArrayStoreException comes when you have stored an element of a type other than the type of array, as shown in the above example. Question 4: Can you use Generics with an array? [answer] No, you cannot use the Generic feature with an array, that's why sometimes List is a better choice over an array in Java, which is also recommended by Joshua Bloch in his class Java book, Effective Java, a must-read for writing good code in Java. Question 5 : Is it legal to initialize an array int i[] = {1, 2, 3, 4, 5}; [answer] Yes, it's perfectly legal. You can create and initialize an array in the same line in Java. Question 6: Difference between b[] and []b in Java? [answer] You can declare an array in Java by either prefixing or suffixing[] with a variable. There is not much difference between them if you are not creating more than one variable in one line, but if you do then it creates different types of variables, as shown in the following example : int a[], b; // first is int array, second is just int variable int[] c, d; // both c and d are integer array Question 7: What is a two-dimensional array in Java? [answer] An array of the array in Java. You can declare them like int[][] primes = new int[3][3] which is a matrix of 3x3. Question 8: Do you have a three-dimensional array in Java? [answer] Yes, Java supports the N-dimensional array. Actually, a multi-dimensional array in Java is nothing but an array of array, for example, a two-dimensional array is just an array of a one-dimensional array. Question 9: How to iterate over an array in Java? [answer] You can either use classical for loop with the index or advanced foreach loop introduced in Java 5 to iterate over an array in Java. If you need the index to select some element or do something else, use for loop otherwise advanced foreach loop is better. It's less error-prone as you don't need to deal with the index. Question 10: What is the difference between an array and a linked list? [answer] One key difference between an array and linked list data structure is, Array requires contiguous memory for its element but linked list elements can be scattered in memory, which means it would be difficult to create a big array but your linked list can grow easily. An array is good for searching elements if you know the index, but adding and removing elements in an array is expensive as compared to the linked list. If you are interested, you can further check out Data Structures and Algorithms: Deep Dive Using Java course on Udemy to learn more about basic data structure and algorithms. Question 11: How to sort an array in Java? [answer] You can sort an array in Java by using the Arrays.sort() method. Arrays is a utility class that contains lots of static utility methods to operate on arrays. This method is overloaded and you can optionally provide a Comparator implementation to sort the array in a custom order. Question 12: How to copy an array in Java? [answer] You can either manually copy elements of an array by iterating over them, or you can use System.arrayCopy() method to copy elements from one array to another. This is a powerful method that provides fast copy and also allows you to copy the entire or part of the array. Question 13: How to access elements of an array in Java? [answer] You can access elements of an array using the index in Java. It starts from 0, so the first element is stored in location zero and the last element has an index length - 1. Trying to access an invalid index in Java, like a negative index or index higher than size will result in ArrayIndexOutOfBoundsException in Java. Question 14: How to search an array to check if an element exists there? [answer] You can search an element inside an array by using either a linear search or binary search. Later is faster but you need to sort the array before performing a binary search on it. The Arrays class from the java.util package provides a binarySearch() method to search an element in an array. Alternatively, you can also convert the array to ArrayList and use its contains() method to find out if an element exists or not. But, if you want to do it without using an API method, you can also check out this post to implement the binary search algorithm in Java. Question 15: Can you make an array volatile in Java? [answer] This is another tricky question in Java. Yes, you can make an array volatile in Java, but you only make the variable that is pointing to array volatile. If an array is changed by replacing individual elements that happen before the guarantee provided by volatile variables will not hold. Anyway, if you are seriously preparing for a Java interview then you have to do more than just preparing for array-based questions. I suggest you take a look at this Java Interview Guide, which contains 200+ Java questions and answers, good enough to clear any Java interview. Question 16: Where does an array stored in memory? [answer] An array is created in the heap space of JVM memory. Since an array is an object in Java, even if you create an array locally inside a method or block, an object is always allocated memory from the heap. Now that we have seen many arrays concept-based questions from Java interviews, let's move on to the second part of this article, where we'll see some array-based coding problems. Btw, If you want to prepare more Java-specific questions then you can also take a look at the Java Programming Interview Exposed, which contains lots of questions from Java and related technology like Maven, JUnit, Servlet, JSP, Android, and others. Array-based Java Coding Interview Problems Some array-based coding interview questions, which require building some logic to solve the problem. These questions are mainly asked to check your problem-solving skills apart from your command of a programming language. Actually, once you know the logic, you can solve these problems in any programming language like C, C++, Python, Ruby or JavaScript, or even Haskell and Golang, it's all up to you. Problem 1: How to find a missing number in an array of 1 to 100 in Java? [solution] You have given an array of integers that contains numbers from 1 to 100, but exactly one number is missing, how do you find that number? You can use an additional data structure. Problem 2: How do you find all pairs whose sum is equal to a given number from an integer array in Java? [solution] You have given an array of int primitives and a number, you need to find all pairs in an array whose sum is equal to a given number e.g. if an array is {1, 2, 3, 4, 5} and given sum is 6 then your program should return {2, 4} and {1, 5}. The classic Cracking the Coding Interview book by Gayle Laakmaan Mcdowell also has a solution for this solution and you can find more coding problems there. Problem 3: How do you remove duplicates from the array in Java? [solution] You have given an array, which could be an array of numbers or Strings, or any objects. Some objects are added multiple times in an array, you need to remove those elements from an array. You don't know how many duplicates are there. You can use an additional data structure and memory to solve this problem. Problem 4: How do you reverse an array in Java? [solution] Given an array of String or integer, how do you reverse the array, so that the first element becomes last and the last element becomes first like if the given array is {1, 2, 3, 4} then your program should reverse it as {4, 3, 2, 1}. You can use additional memory but reversing the array in place will get a bonus point. Problem 5: How to find duplicates numbers in an array of integers in Java? [solution] You have given an array {1, 1, 2, 3, 3, 4}, write a program to return duplicate elements like 1 and 3 because they have appeared more than once in an array. Problem 6: How to find the top two numbers from an integer array in Java? [solution] You have given an integer array e.g. { 3, 4, 5, 6, 7}, you need to find the top 2 numbers from this array like your program should print 6 and 7. That's all about array concepts interview questions in Java. I have shared questions on array fundamentals in Java as well as some array-based coding problems from interviews. It's important to practice both kinds of questions. You can expect array concept questions on the phone round of Java interviews and array-based coding problems in the face-to-face interviews or written tests. These questions are mainly for beginner and intermediate Java programmers, someone who has 2 to 5 years of experience working in core Java. Array concept questions are mainly for Junior programmers and freshers. If you think your data structure and algorithm skill is lacking, you can also check out the following resource to revise algorithm concepts: Other Data Structure and Algorithms You may like 10 Courses to Crack Programming Job Interviews (courses) 50+ Data Structure and Algorithms Problems from Interviews (list) 5 Books to Learn Data Structure and Algorithms in-depth (books) How to reverse an array in Java? (solution) 75+ Coding Interview Questions for Programmers (questions) How to remove duplicate elements from the array in Java? (solution) How to implement a recursive preorder algorithm in Java? (solution) How to implement a binary search tree in Java? (solution) Postorder binary tree traversal without recursion (solution) How to print leaf nodes of a binary tree without recursion? (solution) Recursive Post Order traversal Algorithm (solution) My favorite free courses to learn data Structure in-depth (FreeCodeCamp) Iterative PreOrder traversal in a binary tree (solution) How to count the number of leaf nodes in a given binary tree in Java? (solution) Recursive InOrder traversal Algorithm (solution) 10 Free Data Structure and Algorithm Courses for Programmers (courses) 100+ Data Structure Coding Problems from Interviews (questions) Thanks for reading this article so far. If you like this Java Array tutorial then please share it with your friends and colleagues. If you have any questions or feedback then please drop a comment. P. S. - If you are looking for some Free Algorithms courses to improve your understanding of Data Structure and Algorithms, then you should also check these free data structure and algorithms courses on Udemy. It's authored by a Google Software Engineer and Algorithm expert and it's completely free of cost.
Java coding interview questions answers Java coding interview questions are mostly some programming exercises which is asked to be solved in the java programming language in a limited time during any core Java or J2EE interview. No matter whether you have 2 years of experience or 4 years of experience, there is always some coding interview question in the Java programming job you are applying for. Actually, questions related to Java Coding are increasingly getting popular in Java interviews for two reasons, first its difficult to crack Java coding interview questions than answering fact-based questions like Why String is immutable in Java or Why main is static in Java etc. Second reason of popularity of Coding question in Java interviews is read need of good developers who are required to do a lot of coding in projects rather than doing some maintenance works. Since Java is front line language for any server-side application, and as the complexity of the business process and need of performance is increasing, its obvious that the amount of coding skill required in Java programmers are getting increased with every passing day, which effectively means Java coding questions are top of any list of core Java interview question. These Coding interview questions are collected from various Java programming interviews, from friends and colleagues, and can be a good starting point to refresh your coding skills before appearing on any Java interviews. These basics Java Programs and logical questions can also be a good resource for learning to program and improving your problem-solving skills in Java. 16 Programming Assignments, Homework, and Coding Interview questions answers in Java Here are my list of 10 Java coding interview questions and answers, which is good to prepare before appearing on any Java interviews. As I said Java coding questions are mostly based on programming, logical analysis and problem-solving skill and are on top of any list of tough Java interview questions, so better to get it right in first place. Anyway, you may be able to solve and find answers of these Java coding questions by yourself, but if you stuck do a google, and you can get many alternative ways to solve these problems. Sometimes knowing more than one way to solve any programming question or coding problem in Java also helps to impress the interviewer. This list mainly contains basic programs asked on Interviews. 1. Write a Java program to replace certain characters from String like public String replace(String str, char ch) This is a tricky Java coding interview question and it was asked in one of the written test my friend had appeared recently. This Java coding question can be solved in multiple way like by using charAt() or substring() method, but any approach throws couple of follow-up question like you may be asked to write two version to solve this coding exercise, one by using recursion and other by using Iteration. They may also ask you to write JUnit test for this function which means handling null, empty string etc. By the way this programming question is quite common on technical interviews not just Java but also C, C++ or Scala, but knowing API definitely helps to produce better solution quickly. 2. Write a Java program to print different kind of patterns like Triangular pattern, box pattern, Pyramid patter of stars, numbers or alphabets. This is one of the popular Java homework assignment as well as popular program to learn programming and coding. The trick to solve all pattern questions are using loops. You need to know how to nest loops into each other as well as how to use continue and break to come out from inner and outer loop. You also need to understand how to use print() and println() methods to print characters in same line and different lines. In the past, I have showed you how to print left and right triangular pattern and pyramid pattern of stars as well as pyramid pattern of alphabets. Here are a couple of patterns you can try printing to improve your coding skill in Java. 3. Write a Java program to print Fibonacci series up to 100? This is one of the most popular coding interview questions asked in Java programming language. Even though, a Writing program for Fibonacci series is one of the basic Java program, not every Java developer get it right in interview. Again interview can ask to solve this programming interview question, by using recursion or Iteration. This Java programming question also test your problem-solving skills and if you come up with an original solution, that may even help. See here for complete code example of Fibonacci series in Java 4. FizzBuzz problem : Write a Java program that prints the numbers from 1 to 50. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz" This is also one of the classical programming questions, which is asked on any Java programming or technical interviews. This question is very basic but can be very trick for programmers, who can't code, that's why it is used to differentiate programmers who can do coding and who can't. Here is a sample Java program to solve the FizzBuzz problem : public class FizzBuzzTest{ public static void main(String args[]){ for(int i = 1; i <= 50; i++) { if(i % (3*5) == 0) System.out.println("FizzBuzz"); else if(i % 5 == 0) System.out.println("Buzz"); else if(i % 3 == 0) System.out.println("Fizz"); else System.out.println(i); } } } You can also see this post to solve FizzBuzz in Java 8 using functional programing, lambda and stream. 5. Write a Comparator in Java to compare two employees based upon there name, departments, and age? This is a pure Java based Coding exercise. In order to solve this Java coding or programming interview question, you need to know What is a Comparator in Java and how to use compare method in Java for sorting Object. Sorting is one of the most logical and practical question on technical interview and ability to sort Java object is must to code in Java. This article helps you to solve this Java coding question by explaining how to sort object in Java using Comparable and Comparator. Just remember that Comparable has compareTo() method and use to sort object based upon there natural order e.g. numeric order for number, and alphabetic order for String, while Comparator can define any arbitrary sorting. A good follow-up question can also be the difference between Comparator and Comparable in Java, so be ready for that. You can also see these Java Interview Courses for better preparation, it includes all important topics and questions to quickly prepare for your next Java interview. 6. Design a vending machine in Java which vends Item based upon four denomination of coins and return coin if there is no Item. (solution) This kind of Java coding interview question appears in written test and I believe if you get it right, you are almost through the Interview. These kinds of problem-solving questions in Java are not easy, you need to design, develop and write JUnit test within 2 to 3 hours and only good Java developers, with practical coding experience, can solve this kind of Java programming question. What helps you is to keep practicing your coding skill even before interview. See this programming exercise in Java to get yourself going. I personally like to ask programming questions, which test your object oriented design skills like designing ATM machine, designing parking lot or implementing logic for Traffic Signal controller. 7. Write a Java program to check if a number is Armstrong or not ? Another popular logical coding interview questions in Java, which is based on programming logic. In order to answer this programming question, you need to know what is Armstrong number, but that is not a problem because question may specify that and even provide sample input and output. The key thing to demonstrate is logic to check if a number is Armstrong or not. In most cases, you can not use utility methods defined by logic and you need to produce logic by yourself by using basic operators and methods. By the way, this is also one of the basic programming questions and I have already provided a solution for this. I suggest seeing this Java program to find Armstrong Number in Java to answer this coding question 8. Write a Java program to prevent deadlock in Java? Some of the programming or coding interview question is always based on a fundamental feature of Java programming language like multi-threading, synchronization, etc. Since writing deadlock proof code is important for a Java developer, programming questions which requires knowledge of concurrency constructs becomes popular coding question asked in Java Interviews. The deadlock happens if four conditions is true like mutual exclusion, no waiting, circular wait and no preemption. If you can break any of this condition than you can create Java programs, which are deadlock-proof. One easy way to avoid deadlock is by imposing an ordering on acquisition and release of locks. You can further check How to fix deadlock in Java to answer this Java programming questions with coding in Java 9. Write Java program to reverse String in Java without using API functions? Another classic Java programming or coding exercise mostly asked on 2 to 5 years experienced Java interviews. Despite being simple answering this coding question is not easy, specially if you are not coding frequently. Its best to prepare this programming question in advance to avoid any embarrassment during interviews. I suggest to see this post which shows How to reverse String using recursion in Java 10. Write a Java program to find if a number is a prime number or not? (solution) One more basic Java program, which made it's way to Interviews. One of the simplest coding question and also a very popular Java programming exercise. The beauty of these kinds of logical questions is that, they can really test the basic programming skills or a coder, programmer or developer. Not just problem solving, you can also check there coding style and thought process. By the way. you can also check the Java Programming Interview Exposed for many of such Java coding interview questions. It also covers other important topics e.g. Spring, Hibernate, Java Fundamentals, Object-oriented programming etc. 11. How to Swap two numbers without using a third variable in Java? This Java program might require just four lines to code, but it's worth preparing. Most of the programmers make the same kind of mistakes while writing solutions for this program like Integer overflow, they tend to forget that an integer can overflow if its limit is exceeded, which is not very big. Sure shot way to answer these programming questions is to use the XOR trick to swap numbers, as mentioned in that blog post. 12. Create a Java program to find the middle node of the linked list in Java in one pass? Any list of programming questions is incomplete without any questions from a linked list, arrays, and string, these three forms bulk of coding questions asked on Java interviews. The trick to solving this problem is to remember that the last node of the linked list points to null and you can trade memory with speed. Sometimes your approach to come to a two-pointer solution really matters, by taking rational steps as mentioned above, you can sound more intelligent, a problem solver, and genuine. A quick solution to this programming question can be found here. 13. How to find if a linked list contains a cycle or not in Java? (solution) Another programming question is based on a linked list. By the way, this coding question is a bit tricky than the previous one, but this can also be solved using two pointer approach. If the linked list has a cycle, then the fast pointer will either catch the slow pointer or point to null. If you want to practice more such questions based upon the linked list, array, and String and asked in various companies before, then I suggest you check the Cracking the Coding Interview, it contains more than 190 questions from various tech companies, startups, and service-based companies like Infosys, TCS, and Wipro in India. 14. Implement Producer Consumer design Pattern in Java using wait, notify, and notifyAll method in Java? Similar to deadlock-related programming interview questions, this is also used to test programmers' ability to write bug-free concurrent programs in Java. These coding questions can be difficult if you haven't used wait and notify before, you can confuse yourself as hell on different aspects like which condition to check, on which lock you should be synchronized, etc. I suggest following here to answer this multithreading-based programming interview question. 15. Write a Java program to calculate the Factorial of a number in Java? This Java coding interview question is also based on a list of basic Java programs for beginners. As usual, you better remember how to calculate factorial and how to code solutions using loop and recursive method calls. For a complete code solution of this programming question, see the Java program to calculate factorial 16. How to design a Trade Position Aggregator or Portfolio Management Software in Java? This is another interesting object oriented design problem which is asked to Java programs. In this program you need to create a core Java application which can calculate trade position in real time. Live trades will be fed to system, both buy and sell and it needs to update the position on real time. Position means how many shares of a particular company a particular account is holding. You need to support both multiple accounts and multiple trading symbol. You can try this problem yourself but if you stuck you can see my solution to create Trade aggregator in Java for a step by step guidance. These are some of the Java coding interview questions and answers, which appear frequently on Java Programming interviews. I have included links, with some of my blog posts, which discusses answers of these Java coding question, but you can also find answers by doing google yourself. Please share what kind of Programming, logical, Problem solving or coding-related questions, asked to you in Java interviews? Other Java and Coding Interview questions from Java67 blog 10 tricky Java interview questions - Answered 189 Coding Interview Questions from Amazon, Google, and Microsoft 10 Linux and UNIX interview questions - Answered Best Java Collection interview questions answers for practice Top 40 Java Telephonic Interview Questions Top 20 Hibernate Interview Questions with Answers Top 21 Spring MVC Interview Questions Top 10 RESTful Web Services Interview Questions Top 30 Java OOP Interview Questions with Answers 10 Java Developer Interview Courses to Prepare Next Interview Thanks for reading this article so far. If you like these Java Programming Coding Interview Questions then please share them with your friends and colleagues. If you have any questions or suggestions then please drop a note.
An updated list of OOPs Interview Questions and Answers 2024. Practice your OOPs knowledge with this list of top OOPs Interview Questions.
When the world is witnessing the immersive expansion in the field of technology, Java has been consistently playing one-sided games in programming. That s why it s been almost three decades and still, ev ery beginner is being asked to start learning this programming language today. Perhaps, if you re not at the
Hello guys, if you are a JavaScript developer learning Data Structure and Algorithms and looking for the best online course to learn Algorithms and Data Structure in JavaScript, then you have come to the right place. In the past, I have shared free classes to learn JavaScript and data structure Algorithms, and today, I will share the best courses to learn Data Structure and Algorithms. These courses have been created by expert instructors like Colt Steele, Andrei Neagoie, and Stephen Grider and are trusted by thousands of developers. They are also very affordable, especially the Udemy courses you can buy for just $10 on Udemy sales which happens every now and then. Data structures are one of the most important parts of programming. Every primary programming language has data structures. But what are data structures, and why they are essential? In simple words, Data structures are a way of storing and efficiently organizing data. They help in keeping and managing data, and this is the reason for their importance. Data should be handled carefully. The data structures are brilliant in handling data. There are various data structures in programming. Linked lists, binary trees, stacks, and queues are the most commonly used data structures. The concept of all the data structures is the same in all programming languages. The data structures are always considered a challenge because they require proper attention and guidance. The programmers should understand the working of each data structure properly with practice. Moreover, data structures are one of the most asked topics in job interviews. So in this article, we will list the top six online courses from Udemy, Pluralsight, Coursera, and other popular websites which will help you learn and understand data structures in JavaScript. So what are we waiting for, let's jump into the best online courses to learn Data Structures and Algorithms in JavaScript programming language in 2024: 6 Best Online Courses to learn Data Structure and Algorithms in JavaScript in 2024 Here is a list of the best courses to learn Data Structure and Algorithms in JavaScript. The list includes both a comprehensive and crash course to learn Data structure and algorithms. They are created by experts like Colt Steele, Andrei Neagoie, Stephen Grider and chosen from websites like Udemy, ZTM Academy, and Eduonix. Thousands of developers have already joined these courses to learn Data structure and Algorithms from scratch and improve their knowledge, and you can do the same. 1. 70+ JavaScript Challenges: Data Structures & Algorithms This is a brand new course to learn Data Structure and Algorithms in JavaScript by solving challenges and. In this course, you will be solving 70+ coding challenges from beginner, intermediate and advanced levels which will help you to master data structures like stacks, queues, linked lists, trees, maps and hash maps in JavaScript. It also cover sorting algorithms like bubble sort, insertion, merge and quicksort. You will also learn how to ace coding interviews by learning how to solve problems with iteration, recursion, array methods & more. You will also get full sandbox with explanations and Jest tests for every challenge which makes learning really interesting. Overall one of the best online course to learn data structure and algorithms with JavaScript in 2024 The best thing about this course is that it is created by none other than Brad Traversy one of the best instructor in the world to learn JavaScript. Well, this may sound too much but having gone through Brad's awesome courses like the Modern JavaScript From The Beginning 2.0 - 2024 Revamp and 50 Projects In 50 Days - HTML, CSS & JavaScript I am a huge fan of Brad and I am sure once you join the course you will also become one like many others. Talking about social proof, more than 1,833 students have joined this course because it is just launched last month and at the moment it has on average 4.9 rating out of 5 which makes it higher rated data structure and algorithms course for JavaScript developer on Udemy. 2. JavaScript Algorithms and Data Structures Masterclass by Colt Steele - Udemy This is a course for those individuals who want to learn data structures in JavaScript, sorting algorithms, searching algorithms, and other concepts related to data structures. Moreover, the course is also for those individuals who want to learn how to tackle data structure questions in job interviews. Overall, this course has everything, from data structure implementation to job interview questions. Requirement Basic knowledge of JavaScript This is a huge course with total video content of nearly twenty-two hours. So if you are prepared to dive deep into these concepts, this course is perfect for you. This course is also updated now to add coding challenges, a new feature of Udemy which allows you to practice coding challenges in your browser. Also, I must say that Colt steel is a great instructor, and he makes learning fun and engaging. Having attended his famous web developer bootcamp course, I was quick to join this course, and I wasn't disappointed at all. 3. The Coding Interview Bootcamp: Algorithms + Data Structures by Stephen Grider - UdemyThis is another high-rated Udemy course to learn Data Structure and Algorithms in JavaScript. As mentioned earlier, data structures are one of the most asked topics in job interviews. The data structures are challenging to learn and even more challenging when asked about in job interviews. With the "Coding Interview Bootcamp: Algorithms + Data Structures" course at Udemy, you will be fully prepared for any question regarding data structures in JavaScript. The instructor focuses on the questions asked in interviews with examples and coding challenges. Requirement Basic knowledge of JavaScript Over sixty-two thousand students have enrolled in this course, making it one of the most popular JavaScript data structures courses. It is a comprehensive course with total video content of thirteen hours. Also, I must say that Stephen is one of the best Udemy instructors; having attended his Modern React and Redux course, I had no second thought to check this one, and I am glad I did. 4. Learning Data Structures in JavaScript from Scratch - Udemy This is one of the best courses at Udemy to learn data structures in JavaScript. The instructor focuses on three essential data structures in this course - A linked list, binary search tree, and hash tables. The linked list and binary search tree are the most popular data structures. The instructor explains these two data structures in-depth with suitable examples. The hash table is a bit of an advanced-level data structure. It is explained very nicely how to create and work with hash tables in JavaScript. Requirement Basic knowledge of JavaScript It is a beginner-level course with total video content of nearly four hours. If you can't connect with Colt Steele or Stephen Grider for some reason, you can try out this course. It's another highest-rated algorithm course on Udemy. 5. Data Structures for Coding Interviews in JavaScript [Educative] This is one of the best courses to learn the data structure in JavaScript for coding interviews. This differs from other courses mentioned in this list because it's a text-based, interactive course from Educative, a new online platform that allows you to run code directly in your browser. This means you don't need to download any software or set up your own environment; you can run code right in your browser. This takes away the initial main and accelerates learning. The data structures covered in this course are arrays, lists, stacks, queues, linked lists, dictionaries, sets, hash maps, binary trees, and graphs. Moreover, there are separate sections for sorting and searching algorithms. Requirement Basic knowledge of JavaScript This course contains a detailed review of all the common data structures. It provides implementation-level details in JavaScript to allow beginners to become well equipped with all the different data structures they can leverage to write better code! And, if you like the Educative platform and their interactive courses like Grokking the System Design Interview, Grokking the Object-Oriented Programming interview, then consider getting an Educative Subscription which provides access to their 250+ courses for just $14.99 per month. It's very cost-effective and great for preparing for coding interviews. 6. Master the Coding Interview: Data Structures + Algorithms by Andrei Neagoie This is one of the best courses to learn data structure and algorithms from a coding interview point of view. The data structures covered in this course are arrays, linked lists, stacks, queues, trees, hash maps, and graphs. The instructor explains every data structure nicely and also describes how to perform various operations with examples. This is a long course with a total content of fourteen hours. So if you want to learn data structures in detail, go for this course. Requirement Basic knowledge of JavaScript If you want to learn Data Structure and Algorithms for coding interviews and in-depth and learn all the major data structures in JavaScript, then "Master the Coding Interview: Data Structures + Algorithms by Andrei Neagoie" at ZTM Academy is a perfect choice. By the way, you would need a ZTM membership to watch this course, which costs around $29 per month and provides access to many super engaging and practical courses like his Python and JavaScript interview courses. If you are a constant learner like me, I suggest you go for membership rather than buying a single course, you will save money and make learning easy, as you don't need to purchase classes every time you want to learn something new. That's all about the best online courses to learn Data Structure in JavaScript in 2024. If you want to become a master of JavaScript, you have to learn and understand data structures properly. They are crucial for job interviews also. In this article, we have listed the top five courses that will help you understand data structures in JavaScript. Moreover, some of these courses will also prepare you for job interviews. These courses are selected from reputed educational websites. So make go through each of them and then make your choice accordingly. Other Programming Resources you may like 10 Free Courses to learn Data Structure and Algorithms 50+ Data Structure and Algorithms Interview Questions 10 courses for Programming/Coding Job Interviews 75+ Coding Interview Questions for Programmers 30+ Array-Based Questions from Interviews 30+ LinkedList Based Java Interview Questions Grokking Algorithms - Book Review 21 String Programming Questions from Interviews 10 Data Structures and Algorithms Courses for Interviews 50 Common coding problems from interviews How to solve scenario-based Algorithms Interview Questions Top 5 Data Structure and Algorithms Books for Programmers 100+ Coding Problems and a few tips for Coding interviews 7 Best Courses to learn Data Structure and Algorithms in-depth 10 Free Data Structure and Algorithm courses 25 System Design Interview Questions for Programmers Top 5 Courses to learn Software Architecture Thanks for reading this article so far. If you like these best JavaScript Algorithms and Data structure online courses, please share them with your friends and colleagues. If you have any questions or feedback, then please drop a note. P. S. - If you are keen to learn Data Structure and Algorithms in JavaScript but looking for a free online course to start with, then you can also check out this free data structure course from Udemy. It's completely free, and you just need an Udemy account to join this course.
Welcome back to our fourth lesson in our five […]
Java collections quick reference guide for interviews, Java collections cheat sheet, Java collections study materials for freshers...
By this article, get to know the importance of Polymorphism in Java with its advantages, its characteristics & explore the two types of Java Polymorphism.
Hello guys, whether you are preparing for Java developer interview or any other Software Developer Interview, a DevOps Interview or a IT support interview, you should prepare for SQL and Database related questions. Along with Data Structure, Algorithms, System Design, and Computer Fundamentals, SQL and Database are two of the essential topic for programming or technical Job interview. In the past, I have shared many questions related to MSSQL questions, Oracle Questions, MySQL questions, and PostgreSQL questions and in this article, I am going to share both theory based and query based Database and SQL Interview questions with to the points answers. This article mainly contains two types of interview questions, first which is based ANSI SQL and applicable to all major database, and the second database specific questions e.g. some questions are based on Oracle database, some are MySQL specific and many are based upon SQL Server. Depending upon candidate's experience in the respective database, you can ask database specific questions as well. For example, If a candidate says that he has worked for 4 years in SQL server, you can ask about ISNULL() and COALESCE(), and if he has worked a couple of years in Oracle database, then you can ask about MERGE statement and how to write pagination query in Oracle. 21 Basic SQL Interview Questions and Answers Now, let's start with the basic SQL interview questions which covers essential SQL concepts like joins, aggregation, indexes, primary and foreign keys, SQL commands like SELECT and DELETE and much more. 1. Give two differences between primary and unique key constraint? Primary key constraints create a clustered index and don't allow null, while the unique key creates non-clustered and can be null. Another difference is that one table can have only one primary key while it allows having many unique keys. This is one of the easiest questions you can get on any SQL interview, so don't fluff it, it might be the interviewer's weed out question. 2. How many clustered index a table can have? Only one and that's why only one primary key per table. You can create a clustered index while creating a table or you can add it later. 3. How many non-clustered indexes per table? As many you want but must be under the limit your vendor enforce e.g. SQL Server allows around 280 indexes, but beware of consequences of adding many indexes on table, it might be able to help you search faster but it has space overheads as well as makes your insert and update slower due to additional time is taken to update indexes. 4. What is the difference between truncate and delete? (answer) truncate fast, and should be used to remove all data from a table without removing the metadata e.g. index, while delete removes rows one by one and much slower than truncate. delete also create a log and can blow up log segment if you try to clear a large table using delete clause. 5. What is the difference between primary and candidate key in SQL? (answer) There can be more than one column which can uniquely identify a row, all of these columns are a candidate to become primary key, but apart from those who become primary key or part of it, rest of them are known as candidate keys. 6. What is the difference between UNION and UNION ALL in SQL? (answer) The union is a special keyword which is used to combine the result of two SQL query e.g. suppose you have to ask all red and blue color balls then you can write two queries to get different color balls and can combine them using the union. Now both can be used to combine but UNION removes duplicate rows while UNION ALL keeps it. A row is considered duplicate if all columns have the same values. remember UNION is based upon data so the name of columns can be different. 7. What is the fastest way to empty a table in SQL? (answer) In my opinion, truncate is the fasted command to empty a table without dropping it. Alternative can be to DROP and recreate the table. Delete can also be used to clear table but it is much slower than truncate, you should only use delete command to remove only selective rows, as truncate doesn't support conditional delete. 8. What is the difference between INNER and OUTER JOIN in SQL? (answer) INNER join is used to retrieve matching rows from multiple related tables while OUTER JOIN is used to retrieve all data from one table and matching records from another table. There are two types of outer join like LEFT and RIGHT outer join depending upon the all the data you need from that table. Here is a nice diagram which illustrate the difference between difference JOINS in SQL 8. What is the difference between WHERE and HAVING clause in SQL? (answer) Though both where and having are used to filter rows there is a subtle difference between them which become obvious during grouping. Conditions on WHERE clause is used to filter rows before grouping while HAVING clause is used to filter rows after grouping. Also, HAVING can only be used along with GROUP BY clause but WHERE can be used with or without GROUP BY. 9. What is referential integrity? (answer) Referential integrity is a relational database feature which makes integrity in a relation between two tables. For example, If we have two table Parents and Childs, where ParentID is a foreign key in Childs table, referential integrity prevents you from adding rows in child table a with parent which doesn't exist in Parents table. It can also be used to remove all children if the parent is removed from the primary table. 10. What is normalization? (answer) 11. If I have a column that will only have values between 1 and 250 what data type should I use 12. How do you enforce that only values between 1 and 10 are allowed in a column 13. How do you represent one to one relationship? ( implemented as a single table and rarely as two tables with primary and foreign key relationships) 14. How do you represent one to many relationships? (splitting the data into two tables with primary key and foreign key relationships) 15. How do you represent many to many relationships? (answer) (implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table 16. How do you count unique rows in an SQL table? (answer) (by using count() and distinct) 17. What is the inner join, when should you use it? (answer) 18. What is outer join, when should you use it? 19. What is NULL in SQL? How do you test for NULLs? (answer) (NULL and nothing are different in SQL) 20. What is the result of NULL=NULL and NULL<> NULL? (answer) (for null checking we use "is null" or "is not null" by the way NULL=NULL IS NULL NULL<> NULL IS NULL) 21. What are 12 rules of Tedd Codd? ( these rules forms basis of RDBMS) (answer) Seriously I don't remember all those rules so I don't bother asking it but I have seen it asked many times, good luck if you are asked. 22. What is the difference between count(*) and count(employee_name)? (answer) (former will return a count of all row, later will return only not null row) 23. The difference between view and table? (answer) (A table is a basic storage for your data in the database. A view is a stored query that appears to be a table. For example: Create view ABC as select from all_tables) 24. Where do you want to use a view? (answer) (to hide a very complex or frequent join. Instead of typing in the join every time you join multiple tables, you could create a view that would store that query for you) 24. What is the ANSI way of writing join? (answer) 25. What is Equijoin? (answer) equijoin also called an inner join is a join where matching condition between two table is equal "=". That is where a column (or multiple columns) in two or more tables match. For our example: SELECT emp.ename, dept.name FROM emp JOIN dept ON emp.deptno = dept.deptno26. What is the difference between union and join, when to use what? 25 Advanced SQL Interview Questions with Answers 27. What is the difference between clustered and non-clustered index? A clustered index is a special type of index that reorders the way records in the table are physically stored. Therefore a table can have only one clustered index. The leaf nodes of a clustered index contain the data pages A non-clustered index is a special type of index in which the logical order of the index does not match the physical stored order of the rows on disk. The leaf node of a non-clustered index does not consist of the data pages. Instead, the leaf nodes contain index rows. 28. Benefits and drawbacks of indexing? 29. You have a SQL script and suddenly your script is taking more time to execute than its normal time? what will you do? 30. If you want to delete a large amount of data which command you use truncate or delete? (truncate because truncate doesn't log while in case of delete log segment can be blown if there are too many rows to delete) 31. What is a correlated subquery, how is it different with the normal subquery? 32. What is the four isolation level? 33. What is the DUAL table in Oracle database? 34. What is bind variables and why they should be used? 35. How does Index work in SQL? 36. Does the order of index matters in a Query? 37. Difference between DROP, TRUNCATE and DELETE in SQL DROP will remove both schema and index, no trigger will be fired and cannot be rolled back. TRUNCATE will only remove all data but again no trigger will be fired and can't be rolled back. DELETE will remove data, a trigger will be fired and can be rolled back. 38. What is database statistics? How does it affect query performance? Database statistics are data used by indexes to make your query faster. When you run insert and update command, your database statistics getting out-of-sync, making your query slower, even with right index. To keep your database statistics up-to-date, it's necessary to run update statistics command in SQL Server periodically, mostly after inserting or updating a large number of data into tables. 39. Does order of columns matter in a composite index? Composite indexes (also known as multiple or concatenated indexes) are special types of the index which use more than one column. Yes, the order of columns in concatenated index matter, because it decides whether the index will be used or not in case you only supply one column in WHERE clause. 40. You have a composite index of three columns, and you only provide values of two columns in WHERE clause of a select query? Will Index be used for this operation? Answer: If the given two columns are secondary index column then the index will not invoke but if the given 2 columns contain a primary index( the first col while creating index) then the index will invoke. In your case, the composite index would not work because of the column not included in the where clause. Still you want to use an index you give an index hint like below: select /*+ INDEX(TABLE_NAME IDX_NAME) */ * from table_name; After imposing the force index you can read the explain plan and verify the cost, if an index scan is costlier than the FTS then it's not a good idea to go with index 41. Is there a way we can suggest database use a particular index in SQL Query? Yes, by using index hint, as shown in the following query will ensure that SQL server will use an index: select /*+ INDEX(TABLE_NAME IDX_NAME) */ * from table_name; SQL Query Interview Questions No SQL interview is complete without asking queries. Most of the time it's the SELECT query which you need to write, but be prepared with INSERT or UPDATE queries as well. In this section, we will look at some of the frequently asked SQL queries from programming interviews. 42. Write SQL query to find the third highest salary of an employee without using TOP or LIMIT keyword? 43. Write SQL query to print the name of an employee and their manager? 44. Write SQL query to find all employees joined between date1 and date2? 45. How do you write pagination SQL query in Oracle? 46. How would you select all last names that start with S 47. How would you select all rows where the date is 20221127 SQL Performance Interview Questions 48. If your SQL query takes more time to fetch the record than what should we do to solve it? hint: like DB tuning or indexing kind 49. Between Select Count() /Count(1) — Which one is faster in SQL? Later is faster in PL/SQL but both are almost equivalent in T-SQL. PL/SQL that using count(1) to find the row count was much more high-performing than using count(), as count() fetches all the rows into memory before getting the exact count. I want to know whether this holds true for T-SQL as well, or are the two just the same? 50. If in EMP table I have null EMP_Name, so when we do Order by EMP_Name, then which values come first The one with NULL will come first mysql> select emp_name, dept_id from employee order by dept_id; +----------+---------+ | emp_name | dept_id | +----------+---------+ | Ram | NULL | | Jack | 1 | | John | 2 | | Alan | 3 | +----------+---------+ 4 rows in set (0.00 sec) the default ordering is ascending and NULL comes first. 51. You have one Query which fetches the values from table A and inserts into B. but if the A has null row than which exception occurs. 52. What happens if you don't close the cursor? It depends on whether you declared the cursor locally or globally (and what the default is in your environment - default is global but you can change it). If the cursor is global, then it can stay "alive" in SQL Server until the last piece of code is touched in the scope in which it was created. For example, if you call a stored procedure that creates a global cursor, then call 20 other stored procedures, the cursor will live on while those other 20 stored procedures are running until the caller goes out of scope. I believe it will stay alive at the session level, not the connection level, but haven't tested this thoroughly. If the cursor is declared as local, then it should only stay in scope for the current object (but again, this is theoretical, and I haven't done extensive, low-level memory tests to confirm). Not closing a cursor will keep locks active that it holds on the rows where it is positioned. Even after closing a reference is kept to the data structures the cursor is using though (so it can be reopened) These structures are Microsoft SQL Server specific (so it is not just memory space or handles or so) and depend on what the cursor is actually doing, but they will typically be temporary tables or query result sets. Not deallocating AFAIK only has to do with performance. The aforementioned resources will remain allocated and thus have a negative effect on server performance. That's all about 50+ SQL and Database Interview Questions with Answers for Software Engineers, Programmers, and Database Administrator of 1 to 3 years and up to 5 years of experienced. I have tried to include questions from different topics to provide you a better preparation. If you think a topic or question is missed feel free to suggest in comments and I will include them in this article, The ultimate goal is to make this article useful for anyone preparing for SQL and Database interview questions. Other Interview Question Articles You may like to explore 21 Git Concept Interview Questions with Answers 40+ Object-Oriented Programming Questions with Answers 20 Software Design and Pattern Questions from Interviews 17 Spring AOP Interview Questions with Answers 17 Java Debugging Interview Questions with Answers 10 Oracle Interview Questions with Answers 30 JavaScript Interview Questions with Answers 12 SQL Query Interview questions with solutions 10 Java Locking and Multithreading questions 25 Recursion Interview questions with answers 130+ Java Interview Questions with Answers 20 Algorithms Interview Questions for Software Developers 20+ Spring Boot Interview Questions with Answers 20 JUnit Interview Questions with Answers 50 SQL and Database Interview Questions for Beginners 15 Cyber Security Interview Questions with Answers 25+ Spring Security Interview Questions with Answers 35 Python Interview Questions for 1 to 2 years experienced Thanks for reading this article so far. All the best for your Software Engineering and Development interviews and if you have any questions which don't know answer or any doubt feel free to ask in comments. P. S. - If you are new to SQL and Database and looking for best resources to learn both SQL concepts and commands with examples then you can also checkout this list of best free SQL courses for beginners. It contains best free courses to learn SQL and Database from Udemy, Coursera, and other popular websites. A great resource for beginners.
The RoadMap for Java Developers in 2020. The 2020 Java Developer RoadMap. Mandatory skill for any Java developer in 2020. Java Developer RoadMap 2020.
Get to know the about Abstraction in Java with real-life examples along with description of abstract classes & methods in Java with their syntax & examples.
Java OOP Cheat Sheet is useful for the aspiring Java developers and contains ready-to-use OOPs concept codes for the application development.
Data Abstraction in java is the process of hiding unimportant data and provide only an important one. Learn the Java abstract class and methods with example
Java OOPs Concepts, OOPs, (Object-Oriented Programming), procedure-oriented vs object-oriented, java oops concept with examples, oops features, object, class, inheritance, polymorphism, abstraction and encapsulation.
Learn about OOPs concepts in Java. See Classes & objects in Java with example. Also see polymorphism, inheritance, encapsulation, abstraction
Hello guys, if you are doing a code review and see a SELECT * in production code, would you allow it? Well, its not a simple question as it looks like but let's find out pros and cons about using SELECT * in a production SQL query and then decide. I have read many articles on the internet where people suggest that using SELECT * in SQL queries is a bad practice and you should always avoid that, but they never care to explain why? Some of them will say you should always use an explicit list of columns in your SQL query, which is a good suggestion and one of the SQL best practices I teach to junior programmers, but many of them don't explain the reason behind it. Unless you explain some reasons why one should not use SELECT * in queries, it's difficult to convince many SQL developers, many of whom have started learning SQL by doing SELECT * from EMP in the Oracle database. In this article, I will try to bridge that gap by giving some practical reasons why using SELECT * in the SQL query is not a good idea. 7 Reasons why using SELECT * in a Production SQL Query is a Bad Practice Without wasting any more of your time, here are my seven reasons which explain why using the SELECT star in a SQL query is a bad practice and you should avoid it. 1. Unnecessary IO By using SELECT * you can be returning unnecessary data that will just be ignored but fetching that data is not free of cost. This results in some wasteful IO cycles at the DB end, since you will be reading all of that data off the pages, then perhaps you could have read the data from index pages. This can make your query a little bit slow as well. See these free SQL and Database courses to learn more. 2. Increased network traffic SELECT * returns more data than required to the client which in turn will use more network bandwidth. This increase in network bandwidth also means that data will take a longer time to reach the client application which could be SSMS or your Java application server. 3. More application memory due to this increase in data, your application may require more memory just to hold unnecessary data which it will not be used but coming from Microsoft SQL Server or any other database you are connecting to. 4. Dependency on Order of Columns on ResultSet When you use the SELECT * query in your application and have any dependency on the order of columns, which you should not, the ordering of the result set will change if you add a new column or change the order of columns. 5. Breaking Views while adding new columns to a table When you use SELECT * in views then you create subtle bugs if a new column has been added and the old one is removed from the table. Why? because your view will not break but start returning an incorrect result. To avoid that, you should always use WITHSCHEMABINDING with views. This will also prevent you from using SELECT * in views. 6. Conflict in JOIN Query When you use SELECT * in the JOIN query, you can introduce complications when multiple tables have columns with the same name like status, active, name, etc. On a simple query, this might be fine but when you try to order by one of these columns or use the query in a CTE or derived table, you will need to make some adjustments. See Microsoft SQL for Beginners to learn more about JOINs in SQL Server. 7. Copying data from one table to other When you use SELECT * into INSERT .. SELECT statement, which is a common way to copy data from one table to another, you could potentially copy incorrect data into the incorrect column if the order of column is not the same between two tables. Some programmers think that using SELECT * vs SELECT 1 in your EXISTS code is faster because the query parser had to do extra work to validate the static value. That might have been true long ago but nowadays parser has become smart enough to know that within an EXISTS clause, the SELECT list is completely irrelevant. That's all about why you should not use SELECT * in a Production SQL query anymore. It's always better to use the explicit column list in the SELECT query than a * wildcard. It not only improves the performance but also makes your code more explicit. It also helps you to create maintainable code, which will not break when you add new columns to your table especially if you have views that refer to the original table. Other Programming Articles you may like to explore: 10 Things Java Developers Should Learn 20 Books Java Programmers Can Read Kotlin or Java? Which is better for Android developers? 10 Everyday tools for Java Programmers Python or Java? Which language is better to start with? 5 Courses to Learn Java 9 Better 10 highest paying technical jobs programmers can do 3 JVM Languages Java Developers should Learn Top 5 Courses to learn SQL and Database Top 5 Courses to learn MySQL for Beginners Top 5 Courses to learn PostgreSQL for Beginners Top 5 Courses to learn Microsoft SQL Server for Beginners Thanks for reading this article so far. If you think that these points make sense then please share with your friends and colleagues. If you have any questions or feedback then please drop a comment. P. S. - If you are keen to learn and improve your SQL skills but looking for free resources to start with, you can also check out this list of Free SQL and Database Courses for Programmers and Developers.
Spring is one of the most popular framework and most widely used to develop Java Web application using MVC framework. Due to its immense popularity its expected from Java guys to know how to use Spring framework and how it works. Most of the Java development position uses Spring, Hibernate along with core Java and JEE web technologies like Servlet, JSP, and JSF. In this article, I will be sharing some frequently asked Spring interview question for Java JEE developers. It will contain questions from different Spring modules like Spring MVC, Spring core, the concept on which Spring is built e.g. IOC and DI and Spring security. 26 Spring Framework Interview Questions and Answers for 5 Years Experienced Here is my list of top 20 Spring framework interview questions and answers for Java and JEE developers having 0 to 4 years of experience. 1. What is Spring framework? What is the main advantage of using Spring? Spring is a Java based framework which provides essential features required by Java application out-of-the-box e.g. dependency injection, transaction control, JDBC and JMS helper classes. Provides support to integrate with other frameworks e.g. Hibernate, out-of-box web security features using Spring security etc. 2. What is difference between @Component, @Controller, @Repository, and @Serverice annotation in spring? All three are Spring beans but their responsibility is different depending upon the layer they are used, for example @Controller is used in presentation layer, @Service is used in service layer, and @Repository is used in Data access layer. If you wan to learn them in depth, you can also read my earlier article about the same topic, here 3. What is different bean scope for Spring beans? singleton, prototype, request, and session 4. What is the difference between singleton and prototype bean scope? singleton means just one instance shared between every client who calls the getBean() method, prototype means every time getBean() is called a new instance of the bean is get created. 5. Does spring beans are thread-safe? No, spring doesn't provide any thread-safety guarantee, but prototype beans are thread-safe because they are not shared between multiple threads but singleton beans are not thread-safe. 6. What is the default scope of bean in Spring framework? The default scope is the singleton, which means if you declare bean without specifying scope then it will be a singleton. 7. How does the Spring bean post processor work? Here is a nice diagram which explains how exactly the Spring BeanPostProcessor work in Spring Framework 8. What is dependency injection? Dependency injection is a design pattern in which object's dependency is provided to it rather than object gathering its dependency and increasing coupling between modules. Spring framework provides a DI container which can be used to manage dependency of objects. 9. What is the difference between Dependency injection (DI) and Inversion of Control (IOC)? Both are similar thing but first is pattern of providing dependency to object while second is a concept where role of creating object or passing dependency is reversed from developer to framework like Spring or Google Guice. 10. What are the different types of dependency injection (IoC) supported by Spring? Spring support two main types of dependency injection, constructor injection and setter injection. In former dependencies are passed via constructor and in case of later, dependencies are passed via setter methods. 11. What is the difference between Setter and Construction injection? Differences comes from the fact that in case of setter injection, you call setter methods to pass dependencies while in case of constructor, you pass dependencies via constructor. This also means that in case of setter injection, dependencies are passed after object is created while in case of constructor injection, dependencies are passed when object is created. That's why constructor injection is often used to pass mandatory dependencies without which object cannot function and setter injection is passed additional or optional dependencies. 12. When should you use setter vs constructor injection in Spring? Use constructor injection to pass mandatory dependencies without which object cannot work while use setter injection to pass additional dependencies after object is created. 13. What is the difference between BeanFactory and ApplicationContext? Both are responsible for creating and managing beans in spring framework but later has more functionality and provide internationalization support. Here are few more differences between BeanFactory and ApplicationContext in Spring framework: 14. What are different spring modules? There are many projects or modules in spring framework like Spring Boot, Spring Data JPA, Spring Security, Spring Cloud etc. 15. What are the lazily instantiated beans in Spring framework? This means beans are not created and initialized until they are required by any object or code. 16. What are inner beans in Spring framework? A bean inside another bean is called the inner bean in spring Framework. 17. What is auto wiring means in Spring? Normally, many Java developer defines the relationship between bean using setter and constructor injection in Spring configuration file e.g. applicationContext.xml but Spring also provides an option to figure out relationship and dependency by itself, this is known as auto-wiring in Spring. 18. What are the different types (modes) of auto-wiring supported by Spring? Spring support XML based auto-writing or Java based auto-wiring 19. What is annotation auto-wiring? How do you enable it in Spring? Annotation auto-wring lets you annotated property for auto-wiring. You can use @Autowried annotation to annotate a property in Spring. Depending upon which Spring version you are suing it may not be turned on in the Spring container. So, before you can use the annotation-based wiring, you need to enable it by using context:annotation-config 20. Can you list down some limitations of autowiring in Spring? 21. What is @Required annotation does in Spring? (answer) The @Required annotation is used to specify the mandatory dependency of a bean. Spring container throws BeanInitializationException if the @Required annotated bean property has not been populated. 22. What is DispatcherServlet in Spring MVC? The DispatcherServlet is a core of Spring MVC, it's the front controller which handles all the HTTP requests and responses. 23. What is the difference between WebApplicationContext and ApplicationContext? WebApplicationContext is an extension of ApplicationContext for the web application. It has more features required for web application e.g. it is capable of resolving themes, and that it knows which servlet it is associated with. 24. What are the two types of transaction management supported by Spring? Spring support both declarative and programmatic transaction management. @Transaction annotation is used for declaration transaction management. 25. What do @Controller and @ReuestMapping annotation do in Spring MVC? Both @Controller and @RequestMapping are Spring MVC specific annotations, former is used to make a class controller while later is used to map the request with a method. Another difference between @Controller and @RequestMapping is that @Controller is applied at class level while @RequestMapping is applied at method level. 26. What does the ViewResolver do in Spring MVC? The ViewResolver is used for resolving view corresponding to request or response URL. It usually defines the prefix and suffix to resolve the view component. 27. How can you use List, Set, and Map in Spring configuration file? This questions is for you to answer, let me know how will you do that in comments 28. How do you use a properties file in the Spring configuration file? This is another question for you to answer, think about @PropertySource 29. What is difference between Spring Framework and Spring Boot? (answer) While both are part of big Spring framework umbrella, Spring Framework is commonly referred to the framework which provide essential Dependency injection and Inversion of control functionality along with Spring Framework core API. Spring Framework was introduced to solve the problem associated with Java development and Spring boot is introduced later to solve the problem associate with Spring Framework development, I mean making it easier to create Java application using Spring Framework. That's why its auto-configure a lot of things for you and its bit opinionated which may or may not suit your purpose That's all about Spring Interview questions and answers for 3 to 5 years experienced Java programmers and developers . These questions will help you in your telephonic round of interviews as well as face-to-face interviews. Even if you are not an expert, you will get some basic idea of some important features of Spring framework, which is a very sought-after job skill for Java developer positions. If you can learn to Hibernate along with Spring then it will further boost your chance to get a Java web developer job. Other Java and Spring articles you may like 15 Spring Data JPA Interview Questions with answers (questions) 5 Courses to learn Spring Cloud and Microservices (courses) 13 Spring Boot Actuator Interview questions (Spring actuator question) 15 Spring Cloud Interview Questions for Java developers (answers) Top 5 Courses to learn Microservices in Java? (courses) 15 Microservices Interview questions (answers) 5 Course to Master Spring Boot online (courses) 10 Spring MVC annotations Java developers should learn (annotations) Top 5 Books and Courses to learn RESTful Web Service (books) 3 ways to change Tomcat port in Spring Boot (tutorial) 5 Spring Boot Annotations for full-stack Java developers (tutorial) 10 Tools Java Developers use in their day-to-day life (tools) 10 Courses to learn Spring Security with OAuth 2 (courses) 10 Advanced Spring Boot Courses for Java Programmers (courses) 3 Best Practices Java Programmers can learn from Spring (best practices) 5 courses to learn Spring Boot and Spring Cloud ( courses) Thanks for reading this article so far; if you find these Spring boot Actuator interview questions and answers useful, please share them with your friends and colleagues. P. S. - If you want to learn about Spring Boot and look for a free Spring Boot online course, I also recommend you join one of these free Spring Framework online courses on Udemy. It's one of the best free courses to learn Spring Boot for Java developers.
The linked list is a popular data structure for writing programs and lots of questions from a linked list are asked in various Programming Job interviews. Though Java API or JDK provides a sound implementation of the linked list data structure as java.util.LinkedList, a doubly-linked list, you don't really need to implement a linked list of your own for writing production code, but all these interview questions require you to code a linked list in Java for solving coding problems. If you are not comfortable creating your own a linked list, it would be really difficult to solve questions like reversing a linked list or finding the middle element of a linked list in one pass. The Java 5 release also brought another twist on the linked list based questions from Java interviews, now Interviewers expect you to write a type-safe implementation of the linked lists using Generics. This raises difficulty level as writing a parameterized class is not easy in Java, and it requires a good understanding of Generics fundamentals like how Generics works and how to use it for creating your own type-safe class. Btw, this question also offers you an opportunity to become a better programmer, solving data structure-based questions are a lot better than trying trivial examples, It not only helps to improve programming skill but also prepares you for Java interviews. Btw, if you are not familiar with the linked list data structure itself, I suggest you first go through a comprehensive online course on Data Structure and Algorithms to at least get an understanding of basic data structures like an array, linked list, binary tree, hash tables, and binary search tree. That will help you a lot in solving coding problems. How to implement a linked list in Java using Generics A linked list is a data structure that is used to store data in the form of nodes. As opposed to an array, which stores data in a contiguous memory location, linked list stores data at different places. Each node contains data and a reference part, the reference part contains an address or next node. In the short linked list is a list of nodes, which are linked together. It complements array data structure by solving the problems array has like it needs contiguous memory and insertion and deletion is very difficult in an array. Instead, you can easily add or remove elements from a linked list which makes it an ideal data structure for your growing needs. If you are interested to learn more about array vs linked list data structure, please see the difference between the linked list and array in Java for more differences. In order to create a linked list in Java, we need two classes a Node and a SinglyLinkedList class which contains the address of the first element and various methods to operate on a linked list. There are mainly two kinds of a linked list, a Singly and Doubly linked list. The singly linked list allows you to traverse in one direction, while the doubly linked list allows you to traverse in both forward and reverse directions. In this example, we will implement a singly linked list, with an append() method which inserts elements at the tail. Btw, If you are not very familiar with a linked list data structure itself or want to learn more about how linked list works and its pros and cons, you should first read a comprehensive online course on data structure and algorithms like these best Data Structure and Algorithms courses from Udemy and Coursera. Java Program to implement a Singly linked list I have already shared the implementation of the linked list without generics in an earlier post of unit testing linked list in Java, and now we will see a type-safe, parameterized implementation of a singly linked list using Generics. Here is our Java program to create your own, type-safe linked list in Java. package datastructure; /** * Type Safe implementation of linked list in Java with Generics. * This example creates a singly linked list with append(), * isEmpty() and length() method. * @author Javin */ public class SinglyLinkedList { private Node head; // Head is the first node in linked list public boolean isEmpty(){ return length() == 0; } public void append(T data){ if(head == null){ head = new Node(data); return; } tail().next = new Node(data); } private Node tail() { Node tail = head; // Find last element of linked list known as tail while(tail.next != null){ tail = tail.next; } return tail; } @Override public String toString(){ StringBuilder sb = new StringBuilder(); Node current = head; while(current != null){ sb.append(current).append("-->"); current = current.next; } if(sb.length() >=3){ sb.delete(sb.length() - 3, sb.length()); // to remove --> from last node } return sb.toString(); } public int length() { int length = 0; Node current = head; // Starts counting from head - first node while(current != null){ length ++; current = current.next; } return length; } // Node is nested static class because it only exists // along with linked list // Node is private because it's implementation detail, // and should not be exposed private static class Node { private Node next; private T data; public Node(T data) { this.data = data; } @Override public String toString() { return data.toString(); } } } Now, let's create a sample program to test this linked list implementation. How to test Singly linked list in Java /** * Java program to create singly linked list of String and Integer type, * to check type safety. * @author Javin */ public class LinkedListTest { public static void main(String args[]) { // Creating Singly linked list in Java of String type SinglyLinkedList singlyLinkedList = new SinglyLinkedList(); singlyLinkedList.append("Java"); singlyLinkedList.append("JEE"); singlyLinkedList.append("Android "); //singlyLinkedList.append(2); // compile time error System.out.println("Singly linked list contains : " + singlyLinkedList); System.out.println("length of linked list : " + singlyLinkedList.length()); System.out.println("is this linked list empty : " + singlyLinkedList.isEmpty()); SinglyLinkedList iList = new SinglyLinkedList(); iList.append(202); iList.append(404); //iList.append("one"); // compilation error // Trying to insert String on integer list System.out.println("linked list : " + iList); System.out.println("length : " + iList.length()); } } Output Singly linked list contains: Java-->JEE-->Android the length of linked list: 3 is this linked list empty: false linked list: 202-->404 Length: 2 That's all on how to make a linked list in Java using Generics. As a follow-up question, the Interview may ask you to implement a circular linked list or implement a doubly linked list in Java. You can also use them as an exercise to improve your coding skills. Apart from implementing a different kind of linked list, the Interviewer is also interested in implementing various methods like inserting a node at the start, middle, and end of a linked list, delete a node from the start, middle, and end of a linked list, sorting elements of a linked list, searching a node in a linked list, etc. If you have time, you can practice a lot of coding problems on the linked list here, but remember first to start with implementing a singly linked list in Java. Other Array related coding Interview Questions for practice: How to implement a Binary Search tree in Java? (solution) How to check if a linked list contains a loop or cycle in Java? (answer) How to reverse a linked list in Java? (solution) How to reverse a linked list without recursion in Java? (solution) How to find the Kth element from the tail of a linked list? (solution) Top 30 linked list coding problems from Interviews (questions) Top 10 Algorithms courses for Java Programmers (courses) How to remove duplicates from an array in Java? [solution] 30+ Array-based Coding Problems from Interviews (questions) How to check if an array contains a number in Java? [solution] 10 Free Data Structure and Algorithms Courses for Programmers [courses] Write a program to find the missing number in an integer array of 1 to 100? [solution] How do you reverse an array in place in Java? [solution] 50+ Data Structure and Algorithms Coding Problems from Interviews (questions) 10 Algorithms Books Every Programmer should read [books] 10 Algorithms courses to Crack Coding Interviews [courses] Thanks for reading this article so far. If you like this article then please share it with your friends and colleagues. If you have any questions or doubt then please let us know and I'll try to find an answer for you. As always suggestions, comments, innovative and better answers are most welcome. P. S. - If you are looking for some Free Algorithms courses to improve your understanding of Data Structure and Algorithms, then you should also check this list of free Data Structure and Algorithms courses for beginners and experienced programmers.
OOPs concepts in Java aim to implement reliable working methods with its characteristics and ability to reusability of programs with better security and privacy.
Spring Tutorial provides basic and advanced concepts of Spring Framework. Our Spring Tutorial is designed for beginners and professionals both with steps.