Wednesday, April 17, 2024

Java Basic Concepts For Interview

Don't Miss

What Is The Is

Top 12 commonly asked Important Java Interview Questions on OOPs Concepts | TalentSprint

IS-A relationship is another name for inheritance. When we inherit the base class from the derived class, then it forms a relationship between the classes. So that relationship is termed an IS-A Relationship.

Example – Consider a Television . Now another Smart TV that is inherited from television class. So we can say that the Smart iv is also a TV. Because CRT TV things can also be done in the Smart TV.

So here IS-A Relationship formed. .

Give Some Advantages Of Orm

The automatic code is generated to reduce the overall data access time based on the data model defined.

The complete requirements of an application are managed by the automated code generated by the ORM, which means that there is no need for any extra code, and the overall data access process is made faster and optimized.

  • Vendor Independent
  • The generated code is independent of the vendor, which increases the overall portability of an application.
    • Maintainability

    The code is well tested and generated by the ORM, and only a developer can understand the code perfectly.

    Describe The Java Platform Module System Introduced In Java 9

    Java 9 introduced a new concept and component called ‘Module’ which adds a higher level of aggregation over packages. A module consists of a group of related packages and resources which are reusable. In addition, the module specifies the list of external modules that it is dependent on, and also list of its packages that it makes available to other modules.

    Java 9 divides the JDK into several modules that support different configurations. The Java command ‘java –list-modules’ lists out all the modules in the JDK. Modularization in JDK enables to greatly reduce the runtime size of Java application. For example, if you have a java application for IoT devices and does not have the need for Java GUI classes, then you can create a specific runtime that does not include the GUI modules.

    Also Check: How To Practice For Interview Questions

    How You Get Interested To Work With Spacex

    When we started to apply for such a big company, we must have a vision and also something which generates enthusiasm and motivation to work with such companies. Everyone has some vision which generates interest to work with the SpaceX. This can be answered by following way:

    “When I was a kid, I always being very excited when I heard about galaxies, planets, and astronauts. This excitement got increased day by day, and I started to search about those things on internet. After my Intermediate I did engineering with astronomy, and then I heard about SpaceX, at that time only I decided to work with SpaceX, and now I am here to live my dream.”

    What Is The Difference Between Overloading And Overriding

    Java Coding Interview Cheat Sheet ~ Cheat Sheet

    Overloading is a compile-time polymorphism feature in which an entity has multiple implementations with the same name. For example, Method overloading and Operator overloading.

    Whereas Overriding is a runtime polymorphism feature in which an entity has the same name, but its implementation changes during execution. For example, Method overriding.Image

    You May Like: How To Pass Coding Interview

    There Are Two Integer Arrays A And B Of Size N Given There Are N Gas Stations Along A Circular Route Where The Amount Of Gas At Station I Is A You Have A Car With An Unlimited Gas Tank And It Costs B Of Gas To Travel From Station I To Its Next Station You Begin The Journey With An Empty Tank At One Of The Gas Stations

    Return the minimum starting gas station’s index if you can travel around the circuit once, otherwise return -1.

    You can only travel in one direction. i to i+1, i+2, ⦠n-1, 0, 1, 2.. Completing the circuit means starting at i and ending up at i again.

    The question says that we have two arrays of int. The first one is cost, and another one is gas. We have a car and need to travel to “n” places where n is the above two arrays’ length.

    Now, according to the question, we can start from a point. Let’s say 3, so that means to reach the next point, we need gas greater than the cost at 3.

    See the example:

    Suppose the gas array is:

    And the cost arrays is:

    Here, we can see that the 3rd term from gas is: 4 .

    And the same for the cost is 1, so to go for the 5th position our gas should be greater than the cost. As we can see in this case, it is as 4 > 1.

    Here you see that this much gas is used to go to the next point. Even after reaching there, you will leave with 3 gas as 4-1=3.

    So, at the next point, you will initially have 3 units of gas.

    Now, the question is asking from which point we should start so that we can traverse all the points.

    Now, let’s take the gas array and cost array as following:

    gas =

    cost=

    Now, let’s start from the first element that is index 0.

    So, the gas in our car after first travel will be = gas-cost = 1-2=-1.

    Since it would be a negative number, that means we can’t traverse using the 0 index.

    Now, let’s start from the second element, that is the index 1

    Describe In Brief Oops Concepts

    OOPs is an abbreviation for Object-Oriented Programming Language which entirely deals with an object. The main aim of OOPs is to implement real-world entities such as objects, classes, inheritance, polymorphism, and so on. Simula is considered the first object-oriented programming language. The most popular programming languages are Java, Python, PHP, C++, and many others.

    The following are the OOPs concepts that are included in Java:

    Also Check: Resume Format For Job Interview

    Q17 What Are The Important Methods Of Java Exception Class

    Methods are defined in the base class Throwable. Some of the important methods of Java exception class are stated below.

  • String getMessage This method returns the message String about the exception. The message can be provided through its constructor.
  • public StackTraceElement getStackTrace This method returns an array containing each element on the stack trace. The element at index 0 represents the top of the call stack whereas the last element in the array represents the method at the bottom of the call stack.
  • Synchronized Throwable getCause This method returns the cause of the exception or null id as represented by a Throwable object.

  • String toString This method returns the information in String format. The returned String contains the name of Throwable class and localized message.
  • void printStackTrace This method prints the stack trace information to the standard error stream.
  • What Do You Mean By Stringjoiner Class In Java Se 8 How Can We Achieve Joining Multiple Strings Using Stringjoiner Class

    Java Interview Questions and Answers | Java Tutorial | Java Online Training | Edureka

    In Java SE 8, a new class was advanced and practiced in the java.util package which is called as StringJoiner class. With the help of this class, a user can merge various strings by separating them with some delimiters. StringJoiner class also helps in adding prefix and suffix to the strings.

    In this program, we will add delimiter “,” in between the various distinguished given strings. According to the question, we have to join many different strings. For this, we will take the help of add method in order to add them. Finally, after that we will print the String Joiner.

    Java8StringJoiner.java

    Output:

    Gaurav,Tanmay,Harsh,Abhishek,Akash

    Recommended Reading: How To Prepare Yourself For A Job Interview

    What Are The Non

    Java – Data Types

    Java data types form the building blocks of a Java program and is an important and core topic in Java programming language. Java data types interview questions are frequently asked in Java programming interviews on topics such as primitive data types, wrapper classes, scope of primitive data type, memory footprint of primitive data types, pass by reference vs pass by value etc.

    Following are some frequently asked questions in Java – Data Types

    What Are Some Of The Key Methods In String Class

    Following are some of the commonly used methods in the String class

    toCharArray – Returns an array of the string’s characters

    chatAt – Returns the character at a specific index position of the string

    equals – Returns true if this string matches the text of another string object.

    *** See complete answer and code snippet in the Java Interview Guide.

    You May Like: How To Dress For A Video Interview

    What Is The Importance Of Reflection In Java

    • The term reflection is used for describing the inspection capability of a code on other code either of itself or of its system and modify it during runtime.
    • Consider an example where we have an object of unknown type and we have a method fooBar which we need to call on the object. The static typing system of Java doesn’t allow this method invocation unless the type of the object is known beforehand. This can be achieved using reflection which allows the code to scan the object and identify if it has any method called fooBar and only then call the method if needed.
    Method methodOfFoo = fooObject.getClass.getMethod methodOfFoo.invoke 
    • Using reflection has its own cons:
    • Speed Method invocations due to reflection are about three times slower than the direct method calls.
    • Type safety When a method is invoked via its reference wrongly using reflection, invocation fails at runtime as it is not detected at compile/load time.
    • Traceability Whenever a reflective method fails, it is very difficult to find the root cause of this failure due to a huge stack trace. One has to deep dive into the invoke and proxy method logs to identify the root cause.
  • Hence, it is advisable to follow solutions that don’t involve reflection and use this method as a last resort.
  • Name The Memory Areas That Are Allocated By Jvm And Explain The Class Loader In Jvm

    Java String Interview Questions and Answers

    There are totally five memory areas that are allocated by the JVM, and they are:

    • Native Method Stack

    ClassLoader: class loader is a subschema of JVM which is used to load class files. Whenever we run Java programs, the data will be first loaded from the classloader. There are mainly three in-built classloaders in JVM, they are:

    • Application Classloader
    • Extension Classloader

    Don’t Miss: What Language To Use For Coding Interviews

    Why Do You Want To Work At Amazon / Why Have You Chosen Amazon

    This is one of the first standard questions you will be asked at the HR interview session. But most people don’t have a great answer. We know that there is no right answer to this question, but the candidate must avoid general statements like “this is a great company.” If you want to say that, it is okay, but first, you have a great explanation to prove your point.

    Here, we are providing some standard answers according to different career perspectives. Following are some best possible answers:

    An Engineer answer:

    I would like to work at Amazon because I think I can help the company open a new business opportunity in the area of home automation. . Since the Alexa division is working on home automation, I can extend my Master’s research project regarding home automation, smart meters and Big Data.

    A Finance Manager’s Answer:

    I would like to work at Amazon because it is one of the leading global online retailing companies with 136 billion USD Net Sales and is 12th on the Fortune 500. It is a fast-growing company and a pioneer in the internet retail sector, which has doubled its sales in the past four years. This is a place I would like to work because I know I would have a chance to utilize my capabilities.

    A Sales Manager’s or Product Manager’s Answer:

    I want to work for Amazon for the following reasons:

    Java Interview Questions & Answers For Developers

    For a Java enthusiast who is looking to attend a Java interview anytime soon, here are the most popular interview questions and answers that might come your way. We have tried to include the top frequently asked Java interview questions as well as their answers to help freshers and experienced professionals with their job interviews. Here are some of the Java interview questions for experienced and freshers.

    Q1). Java Interview Questions- Explain the difference between JDK, JRE, and JVM.

    Ans:-

    JDK stands for Java Development Kit and is the tool used to compile, package and document Java programs.

    JRE stands for Java Runtime Environment and is a runtime environment that is a prerequisite to run java byte-code.

    JVM stands for Java Virtual Machine and is a specification that facilitates a run-time environment in which Javas bytecode can be implemented.

    Q2).Java Interview Questions- What makes Java a platform-independent programming language?

    Ans:- Java is platform-independent because it provides the feasibility to run and compile the program in one platform and execute the program on any other platform of your choice.

    Q3). Java Interview Questions- Would it be correct to say that Java is not 100% Object-oriented?

    Ans:- Yes, it would be correct to say that Java is not 100% Object-oriented because it utilizes eight kinds of primitive data types and they are – Boolean, byte, char, int, float, double, long, short. These data types are not objects.

    Ans:-

    You May Like: Preparation For Google Interview For Software Engineer

    What Are The Differences Between Constructor And Method Of A Class In Java

    Constructor
    Constructor is used for initializing the object state. Method is used for exposing the object’s behavior.
    Constructor has no return type. Method should have a return type. Even if it does not return anything, return type is void.
    Constructor gets invoked implicitly. Method has to be invoked on the object explicitly.
    If the constructor is not defined, then a default constructor is provided by the java compiler. If a method is not defined, then the compiler does not provide it.
    The constructor name should be equal to the class name. The name of the method can have any name or have a class name too.
    A constructor cannot be marked as final because whenever a class is inherited, the constructors are not inherited. Hence, marking it final doesn’t make sense. Java throws compilation error saying – modifier final not allowed here A method can be defined as final but it cannot be overridden in its subclasses.
    Final variable instantiations are possible inside a constructor and the scope of this applies to the whole class and its objects. A final variable if initialised inside a method ensures that the variable cant be changed only within the scope of that method.

    What Is Autoboxing And Unboxing

    Java Interview Questions And Answers | Java Programming Interview Questions And Answers |Simplilearn

    Autoboxing is the automatic conversion of primitive data types into their corresponding wrapper classes by Java compiler. Java compiler applies autoboxing when a primitive data type is assigned to a variable of the corresponding wrapper class…

    *** See complete answer and code snippet in the Java Interview Guide.

    Java Interview Guide has over 250 REAL questions from REAL interviews. Get the guide for $15.00 only.Java – Variables

    Java variables is an important, fundamental and core java programming topic. Many FAQs in Java interviews are based on your knowledge of Java variables. These include questions on topics such as primitive variables vs reference variables, variables types, static vs non-static variables, access modifiers and non-access modifiers that can be applied to variables, scope of variables, transient variables, volatile variables, variables vs primitive data types etc.

    Following are some frequently asked questions in Java – Variables

    Recommended Reading: Amazon Senior Product Manager Interview Questions

    Q4 Explain Bean In Spring And List The Different Scopes Of Spring Bean

    Beans are objects that form the backbone of a Spring application. They are managed by the Spring IoC container. In other words, a bean is an object that is instantiated, assembled, and managed by a Spring IoC container.

    There are five Scopes defined in Spring beans.

    • Singleton: Only one instance of the bean will be created for each container. This is the default scope for the spring beans. While using this scope, make sure spring bean doesnt have shared instance variables otherwise it might lead to data inconsistency issues because its not thread-safe.
    • Prototype: A new instance will be created every time the bean is requested.
    • Request: This is same as prototype scope, however its meant to be used for web applications. A new instance of the bean will be created for each HTTP request.
    • Session: A new bean will be created for each HTTP session by the container.
    • Global-session: This is used to create global session beans for Portlet applications.

    In case you are facing any challenges with these java interview questions, please comment on your problems in the section below.

    What Are The Different Types Of Resultset

    ResultSet is categorized by the direction of the reading head and sensitivity or insensitivity of the result provided by it. There are three general types of ResultSet.

    Type
    The cursor can move in the forward direction only.
    ResultSet.TYPE_SCROLL_INSENSITIVE The cursor can move in both the direction . The ResultSet is not sensitive to the changes made by the others to the database.
    ResultSet.TYPE_SCROLL_SENSITIVE The cursor can move in both the direction. The ResultSet is sensitive to the changes made by the others to the database.

    Recommended Reading: What Are Some Interview Tips

    Q7 Can You Explain The Java Thread Lifecycle

    The java thread lifecycle has the following states-

    New-

    When a thread is created, and before the program starts the thread, it is in the new state. It is also referred to as a born thread.

    Runnable

    When a thread is started, it is in the Runnable state. In this state, the thread is executing its task.

    Waiting

    Sometimes, a thread goes to the waiting state, where it remains idle because another thread is executing. When the other thread has finished, the waiting thread again comes into the running state.

    Timed Waiting

    In timed waiting, the thread goes to waiting state. But, it remains in waiting state for only a specified interval of time after which it starts executing.It remains waiting either till the time interval ends or till the other thread has finished.

    Terminated

    A thread is said to be in this state once it terminates. It may be because the thread has completed its task or due to any other reason.

    More articles

    Popular Articles