0% found this document useful (0 votes)
7 views3 pages

Java OOP Concepts and Exception Handling

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

Java OOP Concepts and Exception Handling

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java

1. Explain OOPS concepts.


2. What is transient keyword.
The transient keyword in Java is used to avoid serialization. If any object of a data
structure is defined as a transient , then it will not be serialized.
Serialization is the ​process of converting an object into a byte stream.

3. What is serialization and deserialization in java.


Serialization is a mechanism of converting the state of an object into a byte stream.
Deserialization is the reverse process where the byte stream is used to recreate the actual
Java object in memory. ... So, the object serialized on one platform can be deserialized on a
different platform.

4. What is static keyword and how is it used in java


the keyword static indicates that the particular member belongs to a type itself, rather than
to an instance of that type.
This means that only one instance of that static member is created which is shared across
all instances of the class.
uses:-
static keyword is mainly used for memory management. It can be used with variables,
methods, blocks and nested classes.
It is a keyword which is used to share the same variable or method of a given class.
Basically, static is used for a constant variable or a method that is same for every instance
of a class.

5. What is exception handling in java?


The Exception Handling in Java is one of the powerful mechanism to handle the runtime
errors so that the normal flow of the application can be maintained.
In this tutorial, we will learn about Java exceptions, it's types, and the difference between
checked and unchecked exceptions
1) Checked Exception
The classes that directly inherit the Throwable class except RuntimeException and Error
are known as checked exceptions.
For example, IOException, SQLException, etc. Checked exceptions are checked at
compile-time.

2) Unchecked Exception
The classes that inherit the RuntimeException are known as unchecked exceptions.
For example, ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException,
etc. Unchecked exceptions are not checked at compile-time, but they are checked at runtime.
3) Error
Error is irrecoverable. Some example of errors are OutOfMemoryError, VirtualMachineError,
AssertionError etc.
6. What are runtime and compile time exceptions
7. What is difference between checked and unchecked exceptions in java.

8. Explain Try Catch and Finally blocks.


Try We specify the block of code that might give rise to the exception in a special
block with a “Try” keyword.
Catch When the exception is raised it needs to be caught by the program. This is done
using a “catch” keyword.
So a catch block follows the try block that raises an exception. The keyword catch
should always be used with a try.
Finally Sometimes we have an important code in our program that needs to be executed
irrespective of whether or not the exception is thrown.
s This code is placed in a special block starting with the “Finally” keyword. The Finally
block follows the Try-catch block.
Throw The keyword “throw” is used to throw the exception explicitly.
Throws The keyword “Throws” does not throw an exception but is used to declare
exceptions. This keyword is used to indicate that an exception might occur in the program or
method.

9. What is Method overloading and overriding


10. What is super class/interface for exception
11. What is super class/interface for collection
12. Difference between list and set
13. Difference between HashMap and Hashtable
14. How HashMap works internally
15. What is hash code in java?
16. Explain override equals method
17. What is the difference between comparable and comparator?
18. Mention methods provided by list and map interfaces.
19. Is collections thread safe? If not, how can we make them thread safe?
20. What is java 8 features
21. What is latest version in java and what is its new features.
22. What are streams and what is its advantages.
23. What are some java pre-defined functional interfaces?
24. What are various categories of predefined functional interfaces.
25. What is an optional class.
26. What is a functional Interface and how it is used?
27. Explain about string constant pool in java.
28. What is heap dump in java refer to?
29. What are the methods present in Object class.
30. What are marker interfaces
31. What is multithreading in java
32. What is thread in java and what are two ways we can implement thread in java.
33. What is the difference between class lock and object lock?
34. What is wait() sleep() notify() notifyAll() in multithreading.
35. What is difference start and run methods.

Java Programming Questions


String manipulation questions :
Write a program for string palindrome
Write a program to reverse a string
Write a program to eliminate duplicate characters in a string
Write a program to find highest occurred character
Write a program where input is a string – Testing output T2e1s1i1n1g1
Rest API
1. What are Rest API’s?
2. What are the advantages of microservices architecture over a monolithic application?
3. What different http methods supported by rest api.
4. How do we implement security for rest API’s?
5. What are various design principles we need to follow while developing a rest API?
6. What is the difference between put and Post?
7. What is service discovery and how can we achieve it?

Common questions

Powered by AI

The 'transient' keyword in Java is used to indicate that a field should not be serialized. By marking a field as transient, it prevents the serialization of that particular field's data, therefore, it won't be part of the serialized object's byte stream. This can be useful for skipping sensitive information or reducing the size of serialized data .

Java 8 facilitates functional programming through features such as lambda expressions, which allow passing behavior as a function rather than using anonymous class implementations. Stream APIs provide functional-style operations on collections, enabling processing sequences of elements conveniently and expressively. Moreover, Java 8 introduced functional interfaces such as Predicate and Function as well as default and static methods in interfaces to support lambda expressions and method references .

Checked exceptions in Java are the exceptions that the compiler requires methods to handle explicitly, either through a try-catch block or by using the 'throws' keyword. They are subclasses of Exception, excluding RuntimeException. Unchecked exceptions are derived from RuntimeException, where the compiler does not enforce handling them. They typically represent programming logic errors and may occur during runtime, such as NullPointerException or ArithmeticException .

Java offers several mechanisms for making collections thread-safe. The legacy 'Vector' and 'Hashtable' classes are synchronized but less efficient. The 'Collections.synchronizedList()' and similar methods can wrap standard collections, providing synchronized access. Java also provides concurrent collections in the 'java.util.concurrent' package, such as 'ConcurrentHashMap', which are designed for high concurrency while maintaining safety and performance .

Exception handling in Java maintains the normal flow of an application by catching runtime errors and managing them using try-catch blocks. This process allows the program to continue executing past errors instead of crashing. Try blocks contain code that might cause exceptions, while catch blocks handle them. 'Finally' blocks can contain code that needs to be executed regardless of exceptions, ensuring resource cleanup or error logging .

The 'wait()', 'notify()', and 'notifyAll()' methods facilitate inter-thread communication by allowing threads to coordinate their actions. 'wait()' releases the object's monitor and waits until another thread calls 'notify()' or 'notifyAll()' on the same object. 'notify()' wakes a single waiting thread, whereas 'notifyAll()' wakes all threads waiting on that object's monitor, though only one will acquire the monitor and proceed once it's available .

Enhancing REST API security in Java involves implementing token-based authentication mechanisms, such as OAuth2, to ensure that only authorized users can access the resources. Using HTTPS ensures that data transmitted between the client and the server is encrypted. Input validation and sanitization prevent injection attacks, while rate limiting curbs potential abuse by regulating traffic. Implementing role-based access control and logging for monitoring and auditing are additional best practices .

Method overloading and overriding are key demonstrations of polymorphism in Java. Overloading allows methods to have the same name but different parameters, enabling compile-time polymorphism where the method to be executed is determined at compile time based on the method signature. Overriding allows a subclass to provide a specific implementation of a method already defined in its super class, supporting runtime polymorphism by determining the method to use at runtime depending on the object's actual class .

The 'static' keyword is crucial for memory management in Java as it associates variables, methods, or blocks with the class rather than with instances of the class. This means only one copy of a static member is created, conserving memory as it is shared across all instances. This facilitates features like utility functions and constants that shouldn't be duplicated per object instance .

Java's serialization and deserialization processes enhance cross-platform capabilities by converting an object's state into a standardized byte stream during serialization, which can be transferred over a network and reconstructed into the original object state through deserialization on a different platform . This ability ensures that a Java object serializes on one platform and deserializes on another, promoting interoperability across various systems and environments.

You might also like