Interview Questions On Programming Basics
Interview Questions On Programming Basics
Question 1:
What is procedure-oriented programming? Explain how application developed with
procedure oriented approach?
1) Procedure Oriented Programming contains step by step procedure to execute.
2) Here, the problems get decomposed into small parts and then to solve each part one or more
functions are used.
3) Thus in POP approach, the problem is viewed as a sequence of things to be done, such as,
input taking, calculating and displaying.
For example,
Considering that we have to take two values from user and then to display the summation of the
inputted values. In POP approach this problem may be decomposed as following,
1) First take an input and put it under one variable, here taking as a.
2) Then take another input and put it under another variable, here taking as b.
3) Now define a variable, such as c, as c = a + b.
4) Now display c.
Question 2:
What is object oriented programming? Explain how application developed with object
oriented approach?
1) Object-oriented refers to a system or software methodology that is built on the concepts of
logical objects.
2) Object-oriented based system is modeled and created through the use of objects, where
each object has specific attributes and the relative methods these methods are called to
manipulate or utilize such a system.
3) The essence of object-oriented is that each of the created objects can be reused in the same
and other programs and applications.
Question 3:
Procedure oriented programming Vs Object oriented programming
Question 4:
What is Interpreter? Explain how interpreter works?
1) An interpreter converts each statement of the program line by line into machine code. It
means an interpreter translates the one line at a time into machine language and executes
it. Then moves towards the next line this goes on till the end of the program.
2) Interpreter stops and highlights the problem and will not move to next line when any errors
are encountered. An interpreter requires a less storage space in primary memory than a
compiler.
Question 5:
What is Compiler? Explain how compiler works?
1) The purpose of compiler is same as interpreter but unlike interpreters which translate
the source program line by line, which translate the entire program into machine codes.
2) If source program contain errors, the compiler highlights a list of errors at the end of
the execution of the program. I.e. a compiler translates the whole program before
execution.
3) A compiler is a larger program and occupies more memory space. It is costlier than
interpreter.
Question 6:
What is the difference between Interpreter and Compiler?
Question 7:
What is source code, object code and byte code?
Source Code
Source code is the source of a computer program. It contains declarations, instructions,
functions, loops and other statements, which act as instructions for the program on how to function.
Object Code
1) Object code is usually produced by a compiler that reads some higher level computer
language source instructions and translates them into equivalent machine language
instructions.
2) It should be noted that object files may require some intermediate processing by the
operating system (OS) before the instructions contained in them are actually executed by
the hardware.
Byte Code
1) Java byte code is the resulting compiled object code of a Java program. This byte code can
be run in any platform which has a Java installation in it.
2) The Java byte code is not completely compiled, but rather just an intermediate code sitting
in the middle because it still has to be interpreted and executed by the JVM installed on the
specific platform such as Windows, Mac or Linux.
Interview Questions on Java Basics
Question 1:
What is Java? What is the design goal of Java project?
Java is simple, high performance, object-oriented, robust, secure, multi-threaded, and platform
independent programming language to develop software that can be used for gaming, web,
business, desktop, database, and other applications.
Design goal of Java language project
Write once, run anywhere (WORA) – that means java program can run anywhere and on
any platform. When java code is compiled it is converted into byte code. Now this byte code is
needed to run using JVM, no need of source code and recompilation.
Question 2:
List out Java features or Buzz words of Java?
Question 3:
Explain, why Java is a secured language to develop application?
1) Java runs all of its programs inside a sandbox of its own called the Java Virtual Machine
so that any errors or crashes do not harm the external operating system, thus making it
secure and efficient at the same time.
2) The class-loader adds the security by separating the package for the classes of the local file
system especially from those which are imported from the network sources.
3) The code fragments are checked by byte-code verifier for illegal codes which can violate
access right to objects.
Question 4:
What is platform dependency? Explain, why C programs are platform dependent?
1) When we compile C code on windows, the Compiler which is running on the windows
system will generate .exe file which is only understood by windows platform, not by the
other platforms.
2) If you want to run the same source code on another platform (for example Linux) then you
need to download the compiler which will compile the code for that particular platform
(Linux) only.
3) This is the reason C is platform dependent means you have to download or use compiler
according to the platform on which you are running C code.
In the below diagram, a C program is written and saved with the name “hello.c”. It is compiled
on Windows+32bit platform. The language compiler compiles the source code and produces the
executable code (.exe) for Windows+32bit. The executable code generated for Windows+32bit
would not execute on another platform like Linux+32bit.
Question 5:
What is platform independency? Explain, how Java shows platform independency?
Platform Independent
Platform-independent means a program compiled on one machine can be executed on any machine
in the world without any change.
In the below diagram, the same program “hello.c” is copied onto different platforms like
Windows+32bit and Linux+64bit and compiled according to the local platforms. Native code
generated by the compilers execute on computers of similar platforms. As the same code is used
to produce different builds for different platforms this approach is called Write Once, Compile any
Where (WOCA).
Question 6:
What is Architectural neutral? Explain how Java supports this feature?
1) A language or technology is said to be Architectural neutral which can run on any available
processors in the real world without considering their development and compilation.
2) Java consider as an architectural neutral language because of compiler generates an
architecture-neutral byte code.
Question 7:
Why Java is called as a Portable language?
1) Portable means able to be easily carried or moved, so Java programs are portable means
you can write at one platform(Hardware +Operating System) and can carry to and run on
the platforms which support JVM, that's why it is called Write Once Run
Anywhere(WORA).
2) It is the combination of both Platform independent + Architecture neutral.
Question 8:
What Robust means? Why Java called as a Robust language?
Robust means inbuilt capabilities to handle errors/exceptions.
Java is robust because of following
a) Built-in Exception handling.
b) Strong type checking i.e. all data must be declared an explicit type.
c) Automatic garbage collection.
d) First checks the reliability of the code before Execution etc.
Question 9:
Explain, how Java shows/having high performance?
1) This language uses Bytecode which is faster than ordinary pointer code so Performance of
this language is high.
2) Garbage collector, collect the unused memory space and improve the performance of the
application.
3) It support multithreading, because of this time consuming process can be reduced to
executing the program.
4) Java provides high performance with the use of “JIT – Just In Time compiler”, in which
the compiler compiles the code on-demand basis, that is, it compiles only that method
which is being called. This saves time and makes it more efficient.
Question 10:
Explain about Java software components?
Java software contains
Java Development Kit (JDK)
Java Runtime Environment (JRE)
Java Virtual Machine (JVM)
Just In Time Compiler (JIT)
Java Development Kit (JDK)
The Java Development Kit is a software development environment used to create Java
applications.
Java Development Kit contains two parts.
1) One part contains the utilities like javac, debugger and some jar files which helps in
compiling the source code (.java files) into byte code (.class files) and debug the programs.
2) The other part is the JRE, which contains the utilities like java which help in
running/executing the byte code.
3) As a developer we want to write programs and run them, then you need the JDK
installation.
Question 12:
Explain about JVM with its functionality and architecture?
We can define JVM in three ways:
1) A specification that specifies the working of Java Virtual Machine. The one who provides
the implementation is independent to choose the algorithm.
2) An Implementation called the Java Runtime Environment (JRE).
3) A Runtime Instance that creates a JVM instance when you write a command on the
command prompt to run the java class.
Working of JVM
1) JVM (Java Virtual Machine) behaves as a run-time engine to run Java applications. JVM
calls the main method present in Java code.
2) When we compile a .java file, the compiler generates the .class files(contains byte-code)
with the same names as that of the class present in a .java file.
3) When we run a .class file, it goes through various steps.
Class/method area
It is a part of JVM that contains the information of types/classes loaded by class loader. It also
contains the static variable, method body etc.
Heap
It is a part of JVM that contains object. When a new object is created, memory is allocated to the
object from the heap and object is no longer referenced memory is reclaimed by garbage collector.
Java Stack
It is a part of JVM that contains local variable, operands and frames. To perform an operation,
Byte code instructions takes operands from the stack, operate and then return the result in to the
java stack.
Program Counter
For each thread JVM instance provide a separate program counter (PC) or pc register which
contains the address of currently executed instruction.
Execution Engine
It is a part JVM that uses Virtual processor (for execution), interpreter (for reading instructions)
and JIT (Just in time) compiler (for performance improvement) to execute the instructions.
Question 12:
Why JVM is virtual?
When JRE installed on your machine, you got all required code to create JVM. JVM is created
when you run a java program,
For example, if you create a java program named FirstJavaProgram.java.
To compile use
javac FirstJavaProgram.java
To execute use
java FirstJavaProgram.
When you run second command – java FirstJavaProgram, JVM is created. That’s why it is virtual.
Question 13:
What is a class loader/class loader sub system explain about it?
Java ClassLoader
It is the component of JVM Architecture that loads classes in memory. Every JVM consists of a
ClassLoader. Three built-in ClassLoaders in Java are:
Bootstrap ClassLoader
This is the classloader which is the super class of Extension ClassLoader. It loads the rt.jar file.
Extension ClassLoader
It is the ClassLoader which loads the jar files present in the directory. This is the child Bootstrap
ClassLoader and parent of System ClassLoader.
System/Application ClassLoader
It is the ClassLoader which loads the class files from the classpath. This is the child of the
Extension Classloader.
The Three important functions of ClassLoader are Initialization, Loading, Linking.
Initialization
1) This operation involves the assignment of all static variables with their specific values in
the block of the program.
2) In this phase, there is an assignment of all static variables with their values defined in the
code and static block.
3) The execution takes place from top to bottom in a class and from parent to child in the class
hierarchy.
Loading
1) This operation loads files from secondary memory into the main memory (RAM) for
execution. The ClassLoader reads the .class file, generates the corresponding binary data,
and saves it in the method area.
2) JVM stores some information for each .class file in the method area. This information is:
1) The fully qualified name of the loaded class and its immediate parent class.
2) Whether .class file is related to interface or an enum or a class.
3) Modifier, Variables and Method information, etc.
3) After loading the .class file, JVM creates an object of type Class to represent this file in the
heap memory.
4) The programmers can use this Class object for getting class level information like the name
of the class, parent name, methods, and variable information, etc.
5) To get this object reference we can use the getClass() method of Object class.
Linking
This operation combines different files in the main program together. It performs verification,
preparation, and (optionally) resolution.
1) Verification: The Verification phase checks the correctness of the .class file. It means that
it checks that the file formation and generation is by a valid compiler or not. If the
verification fails then we get a java.lang.Verify Exception.
2) Preparation: JVM allocates memory for class variables and initializes the memory to
default values.
3) Resolution: Resolution is the process of replacing symbolic references with direct
references. It uses searching into the method area to locate the referenced entity.