Common Interview Questions and Answers for freshers are prepared by 10+ years experienced industry experts. Common Interview Questions and Answers are very useful to the Fresher person who is looking for the new challenging job from the reputed company. Our Interview Questions and answers are very simple and have more examples for your better understanding. By this Common Interview Questions and Answers, many students are got placed in many reputed companies with high package salary. So utilize our Interview Questions and answers to grow in your career.
Python Interview Questions and Answers
Q1) What is Python? What are the benefits of using Python?
- it is so easy to understand and easy syntax.
- Python has a scope in automation, data science, data analysis etc.
- Python provides less complexity in writing the code as compare to other languages like java, C#.
- Python has a large library bank.
Q2) What is PEP 8?
Answer: PEP 8 is the style guide to follow the coding practice to write the consistently understandable code.
Q3) What is pickling and unpickling?
Answer: Is short pickling is converting python object into byte stream and unpickling is the reverse of pickling, pickle is the module in python which helps to do this job. And even we can use two methods is dumps and loads for that.
Q4) How Python is interpreted?
Answer: There are concept of complier and interpreter but programing language codes are not machine level code so first python language code will be converted into machine code like byte code and then it will be interpreted if any fall happens in terms of error then the code will throw an error difference between interpreter and compiler is compiler compile full set of code even the code has some error and all the errors will be thrown in logs whereas interpreters stop interpreting code as soon as any error is occurred.
Q5) What are Python decorators?
Answer: Before understanding decorator we should understand function completely in python that’s is we can pass function as parameters, function can return and function, we can write nested function in python and most important functions are same as object in python, so decorators are the tool which allows the programmer to change the behavior of existing functions.
Q6) What is the difference between list and tuple?
Answer: The one main difference between list and tuple is enough to understand that list are mutable and tuples are immutable.
Q7) What is the meaning of immutable?
Answer: The data type which are declared once and cannot be modified those are mutable and which data types are provide the feature to update any point of time are comes under mutable data types and this is only the concepts of immutability.
Q8) How are arguments passed by value or by reference?
Answer: n python arguments are neither pass by value not pass by reference. Python is object centered language and everything in python is an object. So the python treatment with any data types are on the basis of assignment and its depends on the name.
Q9) What are the built-in type does python provides?
Answer: There so many built-in types are there in python like.
None, long, int, str, float, long, list tuple, set, dict, range, xrange and etc.
Q10) What is lambda in Python?
Answer: Lambda in python provides the way of writing the expression which returns the function object and then that function object can be called as function to execute the expression.
Q11) Why lambda forms in python does not have statements?
Answer: Lambda cannot contains the statements inside because the syntactic structure of the python cannot handle the nested statements in an expression because lambda has two part separated by “:” one is argument passing and another is for executions of expressions.
Q12) What is pass in Python?
Answer: Pass is key word in python which is used when statement is required but not executions are required so we can use pass key word, pass key word is mostly used with class and functions, function if not code need to write in that and class when no methods are required to write in that class.
Q13) In Python what are iterators?
Answer: Iterators is an object in python that provide the facility to traverse through the containers all those containers like list, tuple, set can be irritable using iterators in python.
Q14) What is unit test in Python?
Answer: Unit testing in python is as same as in other programing languages, testing of the smallest unit of the code is called unit testing and the smallest unit of the code is nothing but functions. We can use pyunit frame works to write the unit test.
Q15) In Python what is slicing?
Answer: All the data types which are sequence provided one feature that is slicing as by the name it is clear that slice something and in python we have slicing operator “:”
And by using “:” operator we can get the slice from any sequence. For example we Have list like
Q16) What is docstring in Python?
Answer: Doc string is nothing but a way of documentations for class, function and different modules in python.
Q17) How can you copy an object in Python?
Answer: There are two types of copy we can do of an object:
- Deep copy
- Shallow copy
To make the copy of an object we use copy module in python.
There are two method copy and deep Copy, copy function do shallow copy and deep Copy function do deep copy.
Q18) What is the difference between the shallow copy and deep copy in python?
Answer: As we know we have two methods to do copy of an objects when we do shallow copy the we copy an object and both main object and shadow object refers the same data so if any change will reflects where deep copy creates the individual copy of shadow object and change in shadow object does not reflect to the main object.
Q19) What is negative index in Python?
Answer: Python containers provide the feature to of slicing with positive and negative index both.
Containers index starts with 0 index and the n size container will have n-1 index is last index. For negative index –n is first index and – (n-1) will be second index.
Q20) How you can convert a number to a string?
Answer: Converting any data type into other data type is known as type conversion and in python we can convert data type by wrapping with class name.
For example: a = 10 and for converting b = str(a)
Q21) What is module and package in Python?
Answer: Modules are nothing a code which is written for a specific purpose, it can be a class or functions. And we can design different useful modules in a python package that can be used by importing the package it self.
Q22) Mention what are the rules for local and global variables in Python?
Answer: By default writing a variable outside functions and class are global variable, and the variable inside function body or in class body are local variable of those components.
If we want to use global variable in function then we have to explicitly mention variable with global key word.
Q23) Explain how to delete a file in Python?
os.remove() it remove a file.
Os.rmdir() it removes a directory.
Shutil.rmtree() delete a directory and all container.
Q24) Mention the use of // operator in Python?
Answer: The division value in which if output is quotient then digits after decimal places are removed. But if one value is negative then output will be floored means rounded away from zero.
Examples: 9//2 = 4 and 9.0//2.0 = 4.0, -11//3 = -4, -11.0//3 = -4.0
Q25) Mention the use of the split function in Python?
Answer: Split method returns the list of strings after dividing by delimiter.
word = “my, name, is khan”
output:[‘my’, ‘name’ ‘is’, ‘khan’]
Q26) Explain what is Flask & its benefits?
Answer: Flask is a python frame work which helps us to easily work on rest API backend development and even it is used to do the web development.
Flask provides the configuration capability by creating the application instance and a lot more routing related stuffs can be done easily by using flask annotations.
Q27) Mention what is the difference between Django, Pyramid, and Flask.
Answer: Flask is a micro frame work and used for small applications pyramid and Django are large framework and used for large applications pyramid provides the flexibility to use any of the tool and Django also do the same and even Django provides the Its own ORM also.
Q28) How python manage memory?
Answer: Python always stores the objects the private heap of the program and all the objects will located there python maintains the immutability concepts with many data types to use the memory in optimized way.
Python uses its own garbage collector to clear the unreferenced data objects.
Q29) How can you share variables across modules?
Answer: Sharing the members in between the modules are required to keep the members in any python file and we can import the python file itself to use those.
Q30) What are generators in Python?
Answer: There are lots of efforts are required to create iterators in python so we can simply use generators functions to create the iterators. We can write the function with yield instead of return keyword to return multiple values in python.
JAVA Interview Questions and Answers
Q1) Why Java is platform independent?
Answer: Java is platform independent language because the language execution convert it to the byte code and the byte code can be understandable by any of the platform so once the java code is compiled in one platform can be execute in any platform using JVM. And JVM is the immediate interface which can execute java byte code to different platform.
Q2) Why Java is not 100% Object-oriented?
Answer: Java is object oriented programing language because it supports primitive data types which are not considered as object.
Q3) What are wrapper classes in Java?
Answer: Java has the concepts of wrapper class, wrapper classes can wrap the primitive types and then we can use the primitive types as object because all the collection modules like list, set stores the objects. So with the wrapper classes we can store the object of primitives in collections.
Q4) What are constructors in Java?
Answer: Constructors is special method of a class that get called when we create the object of class.
Q5) What are the type of constructor in java?
Answer: There are three types of constructors in java.
- Parametrized constructor.
- Non Parametrized constructor.
- By default constructor.
Q6) What is singleton class in Java and how can we make a class singleton?
Answer: Singleton is a kind of design pattern in java which can restrict to create multiple object of a class in java.
Suppose if we want to create only one object at a time of a class then we can make the class as singleton.
Q7) What is the difference between equals() and == in Java?
Answer: Equals() and == both are used to compare the object but Equals method check the value of object and compare and == operator check the has code meaning the location of the object in memory and give result.
Q8) What is a package in Java?
Answer: Package is provides us a feature to avoid the naming collision in class. Because we cannot create two class with same name in a single package.
Q9) Why pointers are not used in Java?
Answer: Java does not have concepts of pointers. Reason one is because of security issue with pointer java does not use pointer because pointers are used for direct memory location manipulation.
Q10) What is JIT compiler in Java?
Answer: JIT compiler is a just in time compiler and it comes with JVM. So when java code once complied then it will be generating byte code and it can be possible to run that code in any platform. JIT compiler is responsible to communicate with JVM at run time and compile the byte code to machine level code it known as second compiler also.
Q11) Difference between String, String Builder, and String Buffer.
Answer: String is immutable and String Builder and String Buffer are mutable so if we need mutability then we can use string buffer or string builder.
String buffer is thread safe and String Builder in not a thread safe so we need to provide thread safety with data then we can use string buffer.
Q12) What are access modifiers in Java?
Answer: Access modifiers are nothing but the keyword in java which are used to provide the access scope of the members of the class. Public, private, protected and default are access modifiers in java.
Q13) Define a Java Class.
Answer: Whenever we think about any object then we can easily think about the properties of that object and when we wrap the data/attributes/properties/ functionality of an object in a package that package is known as class. And wrapping of the data is known as encapsulation.
Q14) What is an object in Java and how is it created?
Answer: Object is nothing but an instance of a class and we can create an object by using new keyword in java.
Example: suppose we have a class Employee
Employee employee = new Employee();
Q15) What is Object Oriented Programming?
Answer: Object oriented Programming is the concepts which is required when we design a software for the real world use case.
So OOPS concepts give us a thinking to write the code for the real world use case.
Q16) What are the main concepts of OOPs in Java?
Answer: There are four important concepts are there in OOPS.
Q17) What is the difference between a local variable and an instance variable?
Answer: Locale variable are always will be a part of method body. Instance variable will be declare in class but out of the functions. Functions can access local variable as well as instance variable but local variable to a function can to be visible outside of the functions in java.
Q18) What is final keyword in Java?
Answer: Final keyword can be used with the variable, functions and with class.
When we use finale keyword with the variable the that variable cannot be changed once that is initialized if we create a finale method then that method cannot be override and if final is used with the class then it cannot be inherited.
Q19) What is Java String Pool?
Answer: As we know string is the immutable class in java and once we create the string then it cannot be updated, java maintains the tow special memory aria where it allocate memory to the objects those are heap and constant pool which is known as string pool so any string data will be take allocation in string pool and if any other string will hold the same value then both string points the same memory location taking new memory instead.
String objects and string literals are different and string object created by using new keyword takes memory in heap area.
Q20) What is constructor chaining in JAVA?
Answer: When we perform inheritance between classes then we can use super keyword to call the parent class constructer so the advantage is when we have the long hierarchy of classes then by initializing the lowest most sub class we can call all the parent class constructor and once the super most class constructor get called this call chaining will stop and this calling contractors in calling is known as constructor chaining.