Basic Java Interview Questions

Categories: EDUCATION

Q.1. What is Java?

Ans. Java is a class-based, object-oriented programming language with minimal implementation dependencies. A general-purpose programming language, Java allows programmers to write once and run anywhere (WORA), meaning compiled Java code can execute on all Java-supported platforms without recompilation. Java applications are usually compiled to bytecode that works on any JVM, regardless of computer architecture.

 

Q.2. List the features of Java programming language.

Ans. (i) Java is a language that is considered simple to learn. One fundamental notion of OOP Java must be understood.

(ii) Java offers a secure feature that aids in the development of a virus-free and tamper-proof system for users.

(iii) OOP is an abbreviation for Object-Oriented Programming language. OOP denotes that everything in Java is considered an object.

(iv) Java is not compiled into a platform-specific machine; rather, it is compiled into platform-independent bytecode. The Virtual Machine that operates the platform interprets this code.

 

Q.3. How is Java different from C++?

Ans. Java and C++ are both object-oriented programming languages, but they have some key differences.

(i) Platform independence: Java is a platform-independent language, while C++ is a platform-dependent language. This means that Java code can run on any platform that has a Java virtual machine (JVM), while C++ code can only run on the platform that it was compiled for.

(ii) Memory management: Java uses automatic memory management, while C++ requires manual memory management. This means that Java programmers do not need to worry about allocating and freeing memory, while C++ programmers need to be careful to manage memory correctly to avoid memory leaks.

(iii) Safety: Java is a safer language than C++. This is because Java has built-in security features that help to protect applications from malicious code. For example, Java does not allow direct access to the operating system, which makes it more difficult for attackers to exploit security vulnerabilities.

(iv) Performance: Java is typically not as fast as C++. This is because Java uses a virtual machine, which adds an extra layer of abstraction between the code and the hardware. However, Java applications are typically more portable and secure than C++ applications.

In general, when creating secure, manageable, and portable apps, Java is a great option. When creating high-performance programs that need direct access to the operating system, C++ is an excellent option.

 

Q.4. Explain JDK, JRE and JVM?

Ans.

JDK: 

(i) It stands for Java Development Kit.

(ii) It is the tool necessary to compile, document and package Java programs.

(iii) It contains JRE + development tools.

 

JRE:

(i) It stands for Java Runtime Environment.

(ii) JRE refers to a runtime environment in which Java bytecode can be executed.

(iii) t’s an implementation of the JVM which physically exists.

 

JVM:

(i) It stands for Java Virtual Machine.

(ii) It is an abstract machine. It is a specification that provides a run-time environment in which Java bytecode can be executed.

(iii) JVM follows three notations: Specification, Implementation, and Runtime Instance.

 

Q.5. Explain public static void main(String args[]) in Java.

Ans. main() in Java is the entry point for any Java program. It is always written as public static void main(String[] args).

 

public: Public is an access modifier, which is used to specify who can access this method. Public means that this Method will be accessible by any Class.

static: It is a keyword in java which identifies it is class-based. main() is made static in Java so that it can be accessed without creating the instance of a Class. In case, main is not made static then the compiler will throw an error as main() is called by the JVM before any objects are made and only static methods can be directly invoked via the class. 

void: It is the return type of the method. Void defines the method which will not return any value.

main: It is the name of the method which is searched by JVM as a starting point for an application with a particular signature only. It is the method where the main execution occurs.

String args[]: It is the parameter passed to the main method.

 

Q.6. What is classLoader in Java?

Ans. The Java ClassLoader subset of JVM loads class files. The classloader loads Java programs first. Three classloaders are built into Java:

(i) Bootstrap ClassLoader

(ii) Extension ClassLoader

(iii) System/Application ClassLoader

 

Q.7. Why Java is platform independent?

Ans. Java is called platform independent because of its byte codes which can run on any system irrespective of its underlying operating system.

 

Q.8. Why Java is not 100% Object-oriented?

Ans. Java is not 100% Object-oriented because it makes use of eight primitive data types such as boolean, byte, char, int, float, double, long, short which are not objects.

 

Q.9. What are wrapper classes in Java?

Ans. Wrapper classes convert the Java primitives into the reference types (objects). Every primitive data type has a class dedicated to it. These are known as wrapper classes because they “wrap” the primitive data type into an object of that class. Refer to the below image which displays different primitive type, wrapper class and constructor argument.

 

Q.10. What are constructors in Java?

Ans. In Java, constructor refers to a block of code which is used to initialize an object. It must have the same name as that of the class. Also, it has no return type and it is automatically called when an object is created.

 

There are two types of constructors:

 

1. Default Constructor: In Java, a default constructor is the one which does not take any inputs. In other words, default constructors are the no argument constructors which will be created by default in case you no other constructor is defined by the user. Its main purpose is to initialize the instance variables with the default values. Also, it is majorly used for object creation. 

2. Parameterized Constructor: The parameterized constructor in Java, is the constructor which is capable of initializing the instance variables with the provided values. In other words, the constructors which take the arguments are called parameterized constructors.

Top articles
What is European Union Published at:- PLAB (Professional and Linguistic Assessments Board) Sample Questions Set-93 Published at:- 7 Tips for Passing the PLAB Exam on Your First Attempt Published at:- Reasons Why Online Learning is the Future of Education Published at:- B tech Computer Science Published at:- BSc Nursing government colleges Published at:- Pharmacy examining board of Canada exam Published at:- Study Tips for MBA Students Published at:- MBA Recommendation Letter Tips Published at:- MBA Application Resume Tips Published at:- MBA Application Essay Tips Published at:- MBA Admissions Essay Examples Published at:- The Importance of Practice Papers and Mock Tests for ICSE Board Exam Preparation Published at:- The Do's and Don'ts of Board Exam Preparation Published at:- Unveiling the Best Practices for Solving ICSE Board Exam Sample Papers Published at:- UP Board Exam Date 2024 Class 10: Exam Schedule Published at:- Navigating Success: A Comprehensive Guide to GATE 2024 Preparation Published at:- Exploring India's Cultural Diversity on Republic Day: Traditions and Festivities Published at:- Creating a Sustainable Future Through Global Education Published at:- Ultimate Guide to Online Bachelor of Education Programs in 2024 Published at:- 5 Scholarships and Financial Aid Opportunities for Bachelor of Education Students in 2024 Published at:- Future of Cryptocurrency: Trends and Predictions for 2024 Published at:- Green Highway Signs: A Comprehensive Guide Published at:- Basic Java Interview Questions Published at:- Business ENVIRONMENT with Consumer Protection Multiple Choice Question MCQ Published at:- Consumer Protection in Business Environment Multiple Choice Question MCQ Published at:- Government Policies for Business Growth Multiple Choice Question MCQ Published at:- Business Growth for Government Policies Multiple Choice Question MCQ Published at:- Important Days and Events (MCQs) Published at:- Books and Authors (MCQs) Published at:- Business Law (MCQs) Set-1 Published at:- Business Law (MCQs) Set-2 Published at:- Business Law (MCQs) Set-3 Published at:- Business Law (MCQs) Set-4 Published at:-