-
What is the JVM? JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment in which java bytecode can be executed.
-
Define code compilation? Code compilation is the process of running a java code to see if it can be executed
-
What is a constuctor? It is a block of code similar to a method that's called when an instance of an object is created.
-
What is the naming convention of variables in java? This is a rule to follow as you decide what to name your identifiers such as classes,constants etc.
-
What is an annotation and give an example. Annotation is a form of syntactic metadata that can be added to Java source code.Java annotations can also be embedded in and read from class files generated by the compiler.Example: An annotation always starts with the symbol @ followed by the annotation name. The symbol @ indicates to the compiler that this is an annotation.
For e.g. @Override Here @ symbol represents that this is an annotation and the Override is the name of this annotation.
-
What is the difference betwee '==' and equals() when comparing Strings?
-
What are the 8 primitive types in Java? byte short int long char float double boolean
-
What is the difference between primitives and wrapper classes and when can we use each?
Wrapper class is used to encapsulate other primitive class in Java. It , as the name suggests, its object wraps the primitive data. For example it's wraps int to Integer and double to Double and so on. The term "wrapper class" in Java refers to the classes that represent the primitive types in Object form.
- Define Encapsulation and outline its benefits. Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. In encapsulation, the variables of a class will be hidden from other classes, and can be accessed only through the methods of their current class. Therefore, it is also known as data hiding.
To achieve encapsulation in Java −
Declare the variables of a class as private.
Provide public setter and getter methods to modify and view the variables values.
It’s because encapsulation has a number of advantages that increase the reusability, flexibility and maintainability of the code.
Flexibility: It’s more flexible and easy to change the encapsulated code with new requirements. For example, if the requirement for setting the age of a person changes, we can easily update the logic in the setter method setAge().
Reusability: Encapsulated code can be reused throughout the application or across multiple applications. For example, the Person class can be reused whenever such type of object is required.
Maintainability: Application ode is encapsulated in separate units (classes, interfaces, methods, setters, getters, etc) so it’s easy to change or update a part of the application without affecting other parts, which reduces the time of maintenance.
-
Do objects get passed by reference or value in Java? Elaborate on that. Java does manipulate objects by reference, and all object variables are references. However, Java doesn't pass method arguments by reference; it passes them by value.
-
Explain the four OOP principles. a)Encapsulation Encapsulation is the idea that the attributes of an entity are enclosed in that entity. This gives context to attributes. This also allows the programmer to restrict access to those attributes so that those attributes are modified and/or used only in ways that the programmer intends to use them. b)Inheritance Inheritance is the idea that an entity can inherit attributes from another entity. It allows the programmer to create similar entities without needing to redefine similar attributes over and over. c)Polymorphism Polymorphism means “having many forms” which honestly doesn’t really help too much as a definition. I like to call it a way to have the same method, only different. There are two ways to do this: 1.Overloading: The method name stays the same, but the parameters, the return type and the number of parameters can all change.
2.Overriding: This is when a subclass method has the same name, parameters and return type as a method in a superclass but has a different implementation.
d)Abstraction Abstraction is the process of hiding all but the relevant information about a thing to make things less complex and more efficient for the user. For example, we don’t need to know how a clock works in order to use it to tell time. Abstraction lets you focus on what the thing does instead of how it does it.
- What is the difference between Abstract classes and Interfaces? An interface can contain only method declarations. An abstract class can contain both method declarations (abstract methods) and method implementations (concrete methods).
Abstract Class Interface 1 An abstract class can extend only one class or one abstract class at a time while An interface can extend any number of interfaces at a time 2 An abstract class can extend another concrete (regular) class or abstract class while An interface can only extend another interface 3 An abstract class can have both abstract and concrete methods while An interface can have only abstract methods 4 In abstract class keyword “abstract” is mandatory to declare a method as an abstract In an interface keyword “abstract” is optional to declare a method as an abstract 5 An abstract class can have protected and public abstract methods An interface can have only have public abstract methods 6 An abstract class can have static, final or static final variable with any access specifier while interface can only have public static final (constant) variable
- Is it possible to implement multiple inheritance in Java? Java has no multiple inheritance, so a class can not extend multiple classes. Although you can implement multiple interfaces. Also with Java 8 you can have default implementation in interfaces, so which makes this work-around very similar to multiple inheritance. ... But java support multiple inheritance of types.
- What is serialization? How do you implement it? To serialize an object means to convert its state to a byte stream so that the byte stream can be reverted back into a copy of the object. A Java object is serializable if its class or any of its superclasses implements either the java.io.Serializable interface or its subinterface, java.io.Externalizable.
- What are anonymous classes?
Anonymous Inner Class in Java. It is an inner class without a name and for which only a single object is created. An anonymous inner class can be useful when making an instance of an object with certain “extras” such as overloading methods of a class or interface, without having to actually subclass a class. Anonymous inner classes are useful in writing implementation classes for listener interfaces in graphics programming.
Anonymous inner class are mainly created in two ways: Class (may be abstract or concrete) Interface
-
What does it means to say that a String is immutable? String objects are immutable in Java because they provide no methods that modify the state of an existing String object. They only provide methods that create new String objects based on the content of existing ones.
-
What is the difference between method overloading and method overriding?
Overloading occurs when two or more methods in one class have the same method name but different parameters. Overriding means having two methods with the same method name and parameters (i.e., method signature). One of the methods is in the parent class and the other is in the child class.
- What are the access modifiers you know? What does each one do?
Java access modifiers are used to provide access control in Java. Default: Accessible to the classes in the same package only. ... Public. Can be accessed from anywhere. ( ... Private. Accessible only inside the same class. ... Protected. Accessible only to the classes in the same package and to the subclasses.
- Do objects get passed by reference or value in Java? Elaborate on that.
- What the difference between local, instance and class variables?
- What is Dependency Injection?
n software engineering, dependency injection is a technique whereby one object (or static method) supplies the dependencies of another object. A dependency is an object that can be used (a service). An injection is the passing of a dependency to a dependent object (a client) that would use it.
-
What does the static word mean in Java? Can a static method be overridden in Java? The static keyword in Java means that the variable or function is shared between all instances of that class as it belongs to the type, not the actual objects themselves. So if you have a variable: private static int i = 0; and you increment it ( i++ ) in one instance, the change will be reflected in all instances.Jan 6, 2009 The answer is ‘Yes’. We can have two ore more static methods with same name, but differences in input parameters.
-
When is a static block run? Java supports a special block, called static block (also called static clause) which can be used for static initializations of a class. This code inside static block is executed only once: the first time you make an object of that class or the first time you access a static member of that class (even if you never make an object of that class). For example, check output of following Java program.
-
What is reflection? In object-oriented programming languages such as Java, reflection allows inspection of classes, interfaces, fields and methods at runtime without knowing the names of the interfaces, fields, methods at compile time. It also allows instantiation of new objects and invocation of methods.
-
How does the try{} catch{} finally{}
-
What is garbage collection? How does it work? The garbage collector is a program which runs on the Java Virtual Machine which gets rid of objects which are not being used by a Java application anymore. It is a form of automatic memory management. ... This means that in every iteration, a little bit of memory is being allocated to make a String object. All objects are allocated on the heap area managed by the JVM. ... As long as an object is being referenced, the JVM considers it alive. Once an object is no longer referenced and therefore is not reachable by the application code, the garbage collector removes it and reclaims the unused memory.
-
What is memory leak and how does Java handle it?
memory leak in Java is a situation where some objects are not used by the application any more, but GC fails to recognize them as unused.
- What does the keyword synchronized mean? synchronized is a Java keyword. It means that two threads cannot execute the method at the same time and the JVM takes care of enforcing that
- Explain Generics in Java They were designed to extend Java's type system to allow “a type or method to operate on objects of various types while providing compile-time type safety”.
- What is the difference between a GET and POST request?
- What is a URI?
- Differenciate between a client and host.
- What is the difference between HTTP and HTTPS?
- Point out these components(query, host, port, protocol, path ) in the following URL https://127.0.0.1:4200/login/a=bx?c
- What is an Internet Protocol?
- What are the four main components of an Android Application? 1.Activities
They dictate the UI and handle the user interaction to the smart phone screen.
2 Services
They handle background processing associated with an application.
3 Broadcast Receivers
They handle communication between Android OS and applications.
4 Content Providers
They handle data and database management issues.
-
What is the purpose of a package name? This is of importance as it helps to uniquely identify ones app from others in google playstore.
-
What is the purpose of Android Virtual Device? This is used as a simmulator for an actual phone or device and it is for the purpose of testing.