Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views

Java Interview Questions Part - 1

Java interview questions

Uploaded by

Swati Chouhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
17 views

Java Interview Questions Part - 1

Java interview questions

Uploaded by

Swati Chouhan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 5
Know Program Java Interview Question Part-1 1. What is Java? Java is the high-level, object-oriented, robust, secure programming language, platform-independent, high performance, Multithreaded, and portable programming language. It was developed by James Gosling in June 1991. It can also be known as the platform as it provides its own JRE and API 2. List the features of Java Programming language. There are the following features in Java Programming Language. Simple: Java is easy to learn. The syntax of Java is based on C++ which makes it easier to write the program in it. Object-Oriented: Java follows the object-oriented paradigm which allows us to maintain our code as the combination of different type of objects that incorporates both data and behavior. Portable: Java supports read-once-write-anywhere approach. We can execute the Java program on every machine. Java program (.java) is converted to bytecode (.class) which can be easily run on every machine. Platform Independent: Java is a platform independent programming language It is different from other programming languages like C and C++ which need a platform to be executed. Java comes with its platform on which its code is executed. Java doesn't depend upon the operating system to be executed. Secured: Java is secured because it doesn't use explicit pointers. Java also provides the concept of ByteCode and Exception handling which makes it more secure. Robust: Java is a strong programming language as it uses strong memory management. The concepts like Automatic garbage collection, Exception handling, etc. make it more robust. Architecture Neutral: Java is architectural neutral as it is not dependent on the architecture. In C, the size of data types may vary according to the architecture (32 bit or 64 bit) which doesn't exist in Java. Interpreted: Java uses the Just-in-time (JIT) interpreter along with the compiler for the program execution. High Performance: Java is faster than other traditional interpreted programming languages because Java bytecode is "close" to native code. It is still a little bit slower than a compiled language (e.g., C++). Multithreaded: We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi-threading is that it doesn't occupy memory for each thread. It shares a common memory area. Threads are important for multi-media, Web applications, etc. Distributed: Java is distributed because it facilitates users to create distributed applications in Java. RMI and EJB are used for creating distributed applications. This feature of Java makes us able to access files by calling the methods from any machine on the internet. Dynamic: Java is a dynamic language. It supports dynamic loading of classes. It means classes are loaded on demand. It also supports functions from its native languages, i.e., C and C++. 3. Why is Java not a pure object oriented language? Java supports primitive data types - byte, boolean, char, short, int, float, long, and double and hence it is not a pure object oriented language. 4. How is Java different from C++? e C++ is only a compiled language, whereas Java is compiled as well as an interpreted language. e Java programs are machine-independent whereas a c++ program can run only in the machine in which it is compiled e C++ allows users to use pointers in the program. Whereas java doesn't allow it. Java internally uses pointers. e C++ supports the concept of Multiple inheritances whereas Java doesn't support this. And it is due to avoiding the complexity of name ambiguity that causes the diamond problem. 5. 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. Thus, a certain level of abstraction is furnished by not including pointers in Java. Moreover, the usage of pointers can make the procedure of garbage collection quite slow and erroneous. Java makes use of references as these cannot be manipulated, unlike pointers. 6. What do you understand by Java virtual machine? Java Virtual Machine is a virtual machine that enables the computer to run the Java program. JVM acts like a run-time engine which calls the main method present in the Java code. JVM is the specification which must be implemented in the computer system. The Java code is compiled by JVM to be a Bytecode which is machine independent and close to the native code. 7. What is the difference between JDK, JRE, and JVM? JDK JRE JVM It stands for Java It stands for Java Runtime | It stands for Java Virtual Development Kit. Environment. Machine. Itis the tool necessary | JRE referstoaruntime | Itis an abstract machine. It to compile, document | environment in which Java is a specification that and package Java bytecode can be provides a run-time programs. executed. environment in which Java bytecode can be executed It contains JRE + It's an implementation of ] JVM follows three notations: development tools. the JVM which physically Specification, exists. Implementation, and Runtime Instance. .8. How many types of memory areas are allocated by JVM? 1 Class(Method) Area: Class Area stores per-class structures such as the runtime constant pool, field, method data, and the code for methods. Heap: It is the runtime data area in which the memory is allocated to the objects. Stack: Java Stack stores frames. It holds local variables and partial results, and plays a part in method invocation and return. Each thread has a private JVM stack, created at the same time as the thread. A new frame is created each time a method is invoked. A frame is destroyed when its method invocation completes. Program Counter Register: PC (program counter) register contains the address of the Java virtual machine instruction currently being executed Native Method Stack: It contains all the native methods used in the application. 9. What is JIT compiler? Just-In-Time(JIT) compiler: It is used to improve the performance. JIT compiles parts of the bytecode that have similar functionality at the same time, and hence reduces the amount of time needed for compilation. Here the term “compiler” refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU. 10. Explain public static void main(String args[]) in Java. 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 as 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. Save for Future use Part-2 Coming Soon Follow for More Knowledge & Information Buy Java Notes and Start Learn

You might also like