1. why java is not 100% object-oriented?
Java is not fully object-oriented because it supports primitive data types like int, float, byte, long, etc., which are not objects.
2. does java use pointers?
Java doesn’t have pointers, java has references. We don’t use pointers in java explicitly but JVM uses pointers internally.
3. What is Class and Object?
Class:
- A class is a group of objects which have common properties.
- It is a template or blueprint from which objects are created.
- It is a logical entity.
Object:
- An object is a real-world entity that has a state and behavior .
- An object is a run-time entity.
- An object is an instance of a class.
4. What if I write static public void instead of public static void?
The program compiles and runs correctly because the order of specifiers doesn't matter in Java.
5. Explain Encapsulation
The process of binding data member and corresponding methods into a single unit is nothing but encapsulation.
Eg: Every java class is an example of encapsulation.
Encapsulation = Data Hiding + Abstraction
Advantage:
The main advantage of encapsulation is we can achieve security.
Disadvantage:
It increases the length of the code and slows down execution.
Eg: Every java class is an example of encapsulation.
Encapsulation = Data Hiding + Abstraction
Advantage:
The main advantage of encapsulation is we can achieve security.
Disadvantage:
It increases the length of the code and slows down execution.
6. Pointers are used in C/ C++. Why does Java not make use of pointers?
Pointers are quite complicated and unsafe to use by beginner programmers. Java focuses on code simplicity, and the usage of pointers can make it challenging. Pointer utilization can also cause potential errors. Moreover, security is also compromised if pointers are used because the users can directly access memory with the help of pointers.
7. Explain the use of final keyword in a variable method and class.
final variable :
When a variable is declared as final in Java, the value can’t be modified once it has been assigned. If any value has not been assigned to that variable, then it can be assigned only by the constructor of the class.
final method:
A method declared as final cannot be overridden by its children's classes.
final class:
No classes can be inherited from the class declared as final. But that final class can extend other classes for its usage.
When a variable is declared as final in Java, the value can’t be modified once it has been assigned. If any value has not been assigned to that variable, then it can be assigned only by the constructor of the class.
final method:
A method declared as final cannot be overridden by its children's classes.
final class:
No classes can be inherited from the class declared as final. But that final class can extend other classes for its usage.
8. What is the current version of java?
Java 17 LTS is the latest long-term support release for the Java SE platform9. What is the main objective of garbage collection?
The main objective of this process is to free up the memory space occupied by the unnecessary and unreachable objects during the Java program execution by deleting those unreachable objects.10. What are the differences between arrayList and Vector?
Array List | Vector |
---|---|
Methods are non-synchronized | Methods are synchronized |
Not thread safe Thread safe | Thread safe |
Performance is high | Performance is low |
Tags
Post a Comment
0 Comments