Core Software Engineer Interview Questions (Java focused)
Pros of Not Using an ORM framework
- Full Control Over SQL - Custom Query Optimization - may be easier to debug since queries arent hidden
Why is java considered to be high performance and better than other traditionally interpreted languages
1. Bytecode - when u write java code it gets compiled into byte code which is a step closer to machine code 2. JIT compilation - JVM uses a feature called JIT compilation which means while your program runs the JVM converts frequently used bytecode into machine code 3. Efficient Memory use - java has built in memory management and garbage collection
What Memory storages are available with the JVM
1. Class(Method) Area 2. Heap 3. Stack 4. Program Counter Register 5. Native Method Stack
Benefits of method overriding
1. Customization - can customize methods in subclasses to provide specific behaviors while keeping consistent method signature 2. Flexibility - allows for greater flexibility in OOP making it easier to manage and extend code
What are the key characteristics of a java bean
1. Encapsulation - they encapsulate multiple properties in a single object. Internal state of a bean is usually private and access is provided through public getter and setter methods 2. No argument constructor - must have no argument constructor to allow for easy instantiation 3. Serializable - should implement serializable interface, this allows beans to be serialized and deserialized, which is useful for saving the state of an object or for transferring it over a network
Why is Java not a pure object oriented language?
1. Primitive data types: Pure Object Oriented Language treat everything inside the program as objects. Full OOP Languages don't support primitive datatype(like int, char, float, bool, etc.). 2. Static Keyword: When we declare a class as static, then it can be used without the use of an object in Java. If we are using static function or static variable then we can't call that function or variable by using dot(.) or class object defying object-oriented feature.
what are the features and uses of a java bean?
1. Reusability - they can be used across different applications and contexts promoting modular design 2. Framework integration - Many java frameworks rely on java beans for configuration, data transfer, and component representation 3. Event handling - they can be designed to handle events, making them useful in GUI apps where users need to trigger specific responses 4. Introspection - they can be inspected at runtime, allowing tools and frameworks to analyze their properties, methods, and events
Benefits of multithreading in java
Efficiency - makes better use of cpu resources. while one thread is waiting another thread can keep running responsiveness- programs can stay responsive to user input even while doing heavy tasks in the background Improved efficiency: Multithreading makes better use of CPU resources by allowing threads to run while others are waiting (e.g., for I/O operations). • Responsiveness: It allows programs to remain responsive during long-running tasks, as you mentioned. • Parallelism: Multiple threads can execute in parallel on multi-core processors, leading to better performance in certain applications. • Resource sharing: Threads can share the same memory space, which makes data exchange faster than in separate processes.
what is an API and how does it work?
an API is an application programming interface, which is a set of rules and protocols that allows different software applications to communicate with each other. APIs defines the methods and data formats that applications can use to request and exchange information. How does it work: When a client application makes a request to an API, the API processes that request, interacts with the server or database if needed and returns the appropriate response
real world example of a SOAP API
banking systems, like the communication between different financial institutions for transactions or payment processing. Because SOAP offers additional security and built-in standards, it's preferred in these secure environments.
Example of a java bean?
class person - implements serializable - has name and age fields that are private - has getter and setter methods for the instance variables - has a no argument constructor
Why is java dynamic, how does it work, and what are the benefits
dynamic loading in java means classes and interfaces can be loaded into the program while running not just when it starts how it works: Instead of needing to know all the classes your program will use before it runs java can load classes as needed Benefits: - allows java to be more flexible/adaptable by allowing new features/components without restarting the entire program - also saves memory because not all classes are loaded at once only those that are actually needed
Define what goes in the Program counter register on a JVM
PCR is a small piece of memory that tracks what the jvm is currently doing . It holds the address(location) of the next instruction in the bytecode that the JVM will execute
What are the main concepts of OOP in ajva
1. inheritance 2. polymorphism 3. abstraction 4. encapsulation
left join
Returns all rows from the left table, with matched rows from the right (NULL if no match).
What is the difference between JVM, JRE, and JDK?
- JVM interprets byte code into machine code and allows java programs to run on any machine regardless of the underlying OS or hardware. Makes java platform independent and architecture neutral. - JVM is part of the JRE. - JRE (java runtime environment) is a software package that provides everything needed to run java applications. - JRE includes JVM, libraries and other components required to run java programs - JRE allows u to execute java bytecode but does not let you create or compile java programs - JDK (Java development kit) is the complete toolkit for developing java applications. - JDK includes JRE and additional tools needed for writing/compiling java programs - JDK includes javac, development tools like debuggers, and libraries for creating java apps
What is method overloading?
- compile time polymorphism - method to be executed determined at compile time based on method signature -when two or more methods are shared in the same class with a different signature - when an error occurs it is caught at the compile time of the program - may or may not require inheritance - occurs within the class - return types being different is not considered overloading, parameters need to be different
Benefits of method overloading
- improved readability - flexibility - can create methods that perform similar tasks but accept different types of numbers of inputs
What is a classloader?
- part of the JRE - during execution of the bytecode, it is responsible for dynamically loading java classes and interfaces to JVM. - Because of classloader Java run time system doesn't need to know about file and file systems
Why use a framework?
- speeds up development by providing pre built functionality - Makes code easier to maintain because framework enforces structure and best practices - frameworks often designed to handle large scale applications making it easier to grow and scale your application
Java Top 11 Features
1. SIMPLE - java syntax simple to understand 2. PLATFORM INDEPENDENT - java is platform independent, so can run same program in any software and hardware will get the same result. WORA (write once run anywhere) 3.Interpreted and Compiled - java is interpreted as well as a compiler based language. javac compiles into byte code, JVM interprets bytecode and translates into machine code 4. ROBUST - features like garbage collecting and exception handling make the language robust 5. OBJECT ORIENTED - supports OOP 6. SECURE - In simple terms, Java is considered secure because you can share applications as bytecode without giving away the original source code. This protects the code and reduces the risk of unauthorized access or changes. 7. HIGH PERFORMANCE - faster than other traditionally interpreted languages 8. DYNAMIC - supports dynamic loading of classes and interfaces 9. MULTITHREADED - can deal with multiple tasks at once by defining multiple threads 10. DISTRIBUTED - able to access files by calling the methods from any machine connected 11. ARCHITECHTURE NEUTRAL - it is not dependent on the architecture
Benefits of inheritance
1. code reusability- dont need to rewrite methods already defined in parent class 2. organization - helps organize classes in a hierarchical way. Can group related classes together making code easier to understand and manage 3. Polymorphism - inheritance enables polymorphism allowing objects of different classes to be treated as objects of a common superclass. Which can simplify code and increase flexibility
Lifecycle of java bean
1. instantiation - javabean instantiated using no argument constructor. This can happen directly through code or through framework that handles instantiation for u. Person person = new Person(); 2. Property Initialization - after instantiation properties of java bean can be set using the setter methods. This step may also involve dependency injection when using frameworks person.setAge(30); person.setname("isa"); 3. Usage - the java beanis used in the application when its properties can be access or modified through getter and setter methods String name = person.getName(); int age = person.getAge(); 4. Event Handling (if applicable) - if the bean is designed to handle events (such as in GUI apps) it may register event listeners during this phase person.addChangeListener(new CHangeListener(){ public void stateChanged(ChangeEvent e){ // handle the event } }); 5. Serialization (if applicable ) - if the bean is to be persisted (saved) or transmitted for example across a network, it can be serialized using the serializable interface ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("person.ser")); out.writeObject(person); out.close(); 6.Destruction - once bean is no longer needed and there are no references to it, it becomes eligible for garbage collection. In managed environments like spring beans may also have specific lifecycle management where the frame work can destroy beans explicitly
java compilation/interpretation/execution process
1. java source code (.java) -(javac)-> 2. Java bytecode (.class) -(JVM for specific OS which uses JIT)-> 3. .exe(windows), .out(Linux), .dmg(MAC) -> execution
Cons of using an ORM framework
1. performance overhead - auto generation of SQL queries may not always be optiomized 2. less control over SQL 3. Hidden query generations 4. Difficulty handling complex queries
pros for using an ORM framework
1. simplifies databse operations 2. Automatic mapping 3. manages relationships between tables 4. easier to maintain 5. reduce sql errors 6. caching and performance optimizations 7. transactional support 8. cross database compatibility - abstracts database specific syntax so allows cross communication like from postgresql and mysql
What is a SOAP API?
A SOAP API (Simple Object Access Protocol API) is a protocol for exchanging structured information between systems over the internet. It's a way for applications to communicate with each other, typically using XML (a format for structuring data). SOAP is more strict and formal than other API types (like REST), and it follows a specific set of rules for sending and receiving messages.
How can JDBC and REST APIs work together
A java application can use JDBC internally to interact with a postgres database while exposing its functionality through REST API for external clients. The application can serve as a REST API by creating endpoints (using something like Spring Boot) that external clients can interact with. the rest api exposes data and services over HTTP, abstracting away the direct database interaction.
What is an API key, and how is it used?
An API key is a unique identifier passed in API requests to authenticate the calling application or user. It helps the API know who is making the request and if they have permission to access the data or services. It's commonly used to control access, track usage, and prevent abuse.
What is the difference between authentication and authorization in APIs?
Authentication is the process of verifying the identity of a user or system (who you are). Authorization, on the other hand, determines what resources or actions the authenticated user is allowed to access (what you are allowed to do). Authentication happens first, followed by authorization.
explain this characteristic of REST APIs: Cacheable
Cacheable - responses from the server can be cached on the client side improving efficiency and reducing server load
Why is java considered portable
Due to it being platform independent and architecture neutral
explain this characteristic of REST APIs and its benefits: Stateless
Each API request contains all the necessary information so the server does not need to remember any previous requests. Each call is independent. - Efficiency - the server doesnt need to track what every user has been doing, which means less memory and resources required - Scalability - because the server doesnt keep track of any state, it can handle many users simultaneously without needing store their session data. - Consistency - each request is independent so theres no risk of the server getting confused by trying to remember past interactions.
How does multithreading work in java? how do you create a thread and start a thread ?
When you run a java program it starts with one main thread and you can create additional threads to handle other tasks allowing them to run simultaneously To create a thread you must extend the Thread class or implement the runnable interface to start a thread call thread .start()
explain this characteristic of REST APIs: Resources
Everything in a REST API is treated as a resource, Typically represented as URL. . API provides ways to access and manipulate these resources via their URs
Define what goes in the Class Method area of the JVM
Holds information about classes - runtime constant pool (constants used by classes) - details about fields - code for methods
What is method overriding?
If a subclass provides a specific implementation of a method that is already provided by its parent class, it is known as Method Overriding. It is used for runtime polymorphism and to provide the specific implementation of the method. Always needs inheritance. Needs same signature as method in parent class. Allows for dynamic behavior tailored to the subclass. - @Override isnt necessary but best practice. - dynamic polymorphism - method to be executed is determined at runtime based on object type not reference type. - Access Modifiers for overridden methods in subclass must be same or more accessible than the method in the super class
What is JVM ?
JVM is Java Virtual Machine which is a run time environment for the compiled java class files. The JVM is a java interpreter that is responsible for loading verifying and executing the bytecode created in java. Provides features like memory management, garbage collection, and system calls
Is JVM platform independent?
JVM is not platform independent however the byte code JVM executes can be created on any System
What does it mean to say java is platform independent ?
Java apps can run on any OS without needing to change the source code. Emphasis on software environment or OS compared to hardware architecture for Architecture neutral
wha tis a java bean?
Java beans are reusable software components that follow a specific convention for creating and manipulating objects. Primarily used in enterprise applications and GUI frameworks
what does it mean when we say java has distributed features? What are the benefits of these distributed features
Java can work across multiple computers or devices and access resources like files from another machine. Java has built in features that allow it to connect to different machines over a network (like internet or local network ) - done by javas networking capabilities Benefits include flexibility since you can access resources from anywhere making ur application more versatile and collaboration since different systems can work together easily sharing data and resources
Why is java considered secure
Java is considered secure because you can share applications as bytecode without giving away the original source code. This protects and reduces the risk of unauthorized access or changes.
What is JIT, how does it work and why is it good
Just in time compilation JIT compilation means when u run a java program the JVM reads the bytecode and interprets it, the JVM notices which parts of the bytecode are used the most and converts it into native machine code while the program is still running Its good because after the initial slower interpretation the program can execute quicker.
Real world example for method overloading
Library class with a list of book objects. These book objects have different attributes such as title, author and genre. We can use method overloading to create search methods which search for certain books based on different input/parameters. One search method could have jut title another could have title and author etc
what is maven?
Maven is a project management and comprehension tool. Maven provides developers a complete build lifecycle framework. Development team can automate the project's build infrastructure in almost no time as Maven uses a standard directory layout and a default build lifecycle.
inner join
Most common type of join; includes rows in the query only when the joined field matches records in both tables.
Can a static method be overridden?
No, a static method cannot be overridden. It is because the static method is bound with class whereas instance method is bound with an object. Static belongs to the class area, and an instance belongs to the heap area. Static methods are resolved at compile time so method that gets called depends on the reference type not he object type
What is an ORM frame work?
ORM (Object-Relational Mapping) framework is a tool that automates the conversion (or mapping) between Java objects and relational database tables. Essentially, it allows developers to interact with a database using Java objects instead of writing raw SQL queries. The framework handles the behind-the-scenes work of generating SQL queries, managing relationships between objects, and syncing data between the application and the database.
What are the differences/similarities between java and C++ when it comes to: 1. platform 2. application 3. hardware 4. global scope 5. not supporting 6. OOP 7. Inheritance Tree
Platform: - c++ is platform independent - java is also platform independent Application: - c++ is mainly used for system programming - Java is mainly used for application programming Hardware: - c++ is more interactive with hardware - java is not so interactive with hardware Global Scope: - c++ supports global and namespace scope - java does not support global scope Not supporting: - c++ doesnt support multithreading, documentation comments, and unsigned right shift (>>>) - java doesnt support goto statement, Pointers (giving progreammers power of memory management is powerful but risky), Call by reference, structures and unions, multiple inheritance, virtual functions OOPS: - c++ is an object oriented language. Not a single root hierarchy - java is also OO. Is a root hierarchy as everything gets derived from a single class Inheritance Tree: - c++ always creates a new inheritance Tree - java uses a single inheritance tree as classes in java are the child of object classes in java
What is a REST API
REST stands for Representational state transfer API. A REST API is a way for different software systems to communicate with each other over the internet. REST APIs use HTTP (hypertext transfer protocol, same protocol used by web browsers to load web pages) to send and receive requests and responses. REST APIs are stateless meaning each request from a client to a server must contain all necessary info to understand and complete the request. REST APIs use HTTP methods to define actions on resources making them simple to use
What is rate limiting in APIs and why is it important?
Rate limiting controls how many requests a client can make to an API within a given time frame. This prevents abuse, ensures fair usage, and protects the API server from being overwhelmed by too many requests. If the limit is exceeded, the API might return an error or a message to try again later.
explain this characteristic of REST APIs: Uniform Interface
Rest APIs use communication standards HTTP methods such as: - GET - to retrieve data - POST - to send data - PUT - to update an existing resource - DELETE - to delete a resource
right join
Returns all rows from the right table, with matched rows from the left (NULL if no match).
FULL JOIN
Returns all rows when there is a match in either table (NULL if no match).
What is SOA
SOA (Service-Oriented Architecture) is an architectural pattern in computer science that focuses on building software applications as a collection of loosely coupled services. Each service is designed to perform a specific business function and can communicate with other services over a network. SOA promotes the idea of reusability, interoperability, and scalability in software design.
Explain this key future of a SOAP API: WSDL (Web Services Description Language)
SOAP APIs use WSDL to describe the available functions and how clients should interact with the API. It's like a contract that defines what operations the API offers and what data is required.
Explain this key future of a SOAP API: Uses XML for Messages
SOAP messages are always in XML format. This makes SOAP very strict about how data is structured, which ensures consistency.
Real world example for method overriding
Say we have an account class which represents an account a user has with a bank. In that account class we a field balance and we have a calculateInterest method which returns 0 . We can then extend this account class from a savingsAccount class, with a field interest rate. we can then override the calcualteInterest method to return the accounts balance * interest rate. We could also have a checking account class which doesn't need to override interest method since checking accounts don't usually earn interest.
Key Concepts of SOA:
Services: service is a self-contained unit of functionality that can be accessed remotely. Loose Coupling: changes to one service do not heavily impact others Interoperability: SOA allows different applications and services, possibly built with different technologies, to work together. This is achieved through standard communication protocols and data formats. Reusability: Services are designed to be reusable across different applications, reducing redundancy and speeding up development. Discoverability: Services can be discovered and accessed easily, often through a service registry where available services are listed. Standard Protocols: SOA relies on standard protocols and data formats to facilitate communication between services.
real world example of a REST API
The Twitter API is an example of a RESTful API. Developers use it to fetch tweets, post tweets, and search for specific content on Twitter. When you request data (like a tweet), the response usually comes back in a simple format like JSON, making it easy to work with.
explain this characteristic of REST APIs: Client Server Architecture
The client(front-end or another service) sends requests, and the server(back-end) responds with the requested data or action. The two systems are kept separate.
Define what goes in the heap on a JVM
The heap is where java creates and stores objects. Whenever a new object is created it stored on the heap. Heap is used for memory management during the programs execution.
Define what goes in the stack on a JVM
The stack is like temporary storage space for method execution. It keeps track of - data needed for methods - partial results from calculations - information to return to the correct spot in the program after a method finishes
Give an example of an API in use
Travel apps like Booking.com or Expedia use multiple APIs to gather hotel information, flight data, or car rental options. When you search for a hotel room, they don't store all the hotel details in their own database. Instead, they communicate with different providers via APIs and combine the responses into a single result list you can browse.
Explain this key future of a SOAP API: Protocol-Based
Unlike REST, which is an architectural style, SOAP is a formal protocol that includes rules for how messages should be formatted and processed. This ensures reliability and security
Is Java Platform Independent if so how?
Yes java is a platform independent language . Javac compiles program to form a bytecode or .class file. This file is platform independent and needs a JVM to execute. JVM abstracts away system specific details making sure Java programs can run on various platforms without modification.
What is HTTP
hyper text transfer protocol; governs the way in which websites and web servers are accessed by web browsers, by conforming to the same standards all browsers can access all websites
Can you override a final method?
if a method is declared as final in the super class it can not be overridden in any subclass
Left and Right tables in joins
left table is first in from clause, right table is second in join clause
What is multithreading in java
multithreading means a program can perform multiple tasks/ paths of execution at the same time. Java uses threads to allow multithreading
what is a framework?
pre-built structure of code, tools, and libraries that provides a foundation for developing software applications. It offers reusable components and sets of rules or guidelines to help developers build software more quickly and efficiently.
CROSS JOIN
returns the Cartesian product of both tables, meaning it returns all possible combinations of rows from both tables.
Define what goes in the Native method stack on a JVM
special area in memory used when java needs to run native methods, which are functions written in other programming languages. stores: - Info about the native method like details about the function calls and any data needed to execute them - parameters being passed to native methods and the results returned by them How it works: when java program calls a native method the JVM uses the native method stack to handle that call. It stores necessary details so the native code can run properly and return results back to them
What does it mean for java to be architect neutral?
the ability of java bytecode to run on any type of computer architecture without needing to be rewritten. For example java byte code can run on any machine with a JVM regardless of whether the machine uses intel or ARM processors
Explain what a thread is in java
threads are like separate paths of execution within a program
Define Inheritance in java
when an object that belongs to a subclass acquires all the properties and behavior of a parent object that is from the super class. Inheritance provides code reusability. Use extends key word to create a subclass/child class that can use all fields and methods of the parent class