A: The most basic question asked in a java interview is that what is thread? Well the simple answer to this is that a thread is basically a program in execution which is performing some specific task. There may be multiple threads running altogether. A single thread is independent in nature and does one specific task. The other thread is also independent and does their specific task. Both the threads run parallel and this is called multi-threading.
A: Well converting string to int in java is very easy. one can use Integer.pardeInt() to convert a string to int.
A: We can set the path in java by using the following two ways
A: By following below three steps one can declare array in java- First, one must declare a variable of the desired type which will hold the array. Second, allocate the memory which will hold the array, create a new array and assign it to the array variable. Now you can store things in that array.
A: When an instance of object is created, a special type of method is used to initialize the class. These are called constructors.
A: When we convert the state of an object into a byte stream then this mechanism is called serialization. Deserialization is just the opposite of this. i.e. when we use the byte stream to recreate the actual java object in memory then this mechanism is called deserialization.
A: The dictionary meaning of synchronization is the operation or activity of two or more things at the same time or rate. Similarly accessing and controlling multiple threads from any shared resources in java is called synchronization in java.
A: From the word garbage, it is pretty much clear that it is related to something which is now a waste and not in use. The garbage collector in java virtual machine helps in getting rid of the objects which are not being used by Java anymore.
A: An applet is a small internet based programming language for the web written in java and can be downloaded by any computer. It runs in a web browser and usually embedded in an HTML page on the website.
By following the below steps one can easily create an immutable class in java:
A: A Platform is defined as the software or hardware environment where a program is run. There are hardware-based platforms and software-based platforms, and JAVA gives a software-based platform.
A: JAVA provides software-based platform, but is itself platform independent. This means that JAVA programs can be run in any operating system irrespective of where it is written.
A: JVM stands for JAVA Virtual Machine and provides the environment where JAVA codes are executed. Different JVMs exist for different platforms. JRE or Java Runtime Environment is the implementation of Java Virtual Machine. JDK or JAVA Development Kit is the actual software to create and run JAVA programs containing JRE and development tools.
A: The Just in Time Compiler or JIT Compiler is used by JAVA to improve execution performance by compiling parts of the program with similar functionality together.
A: Classloader is a JVM subsystem that loads classes and interfaces.
A: A class in JAVA is the blueprint for the creation of individual objects. It may contain methods and fields that define the object behaviour.
A: A JAVA program entity with a state and behaviour is called an Object. It is the instance or result of a class. The state of an object is saved in fields, and its behaviour is expressed through methods.
A: Variables that are defined within methods, constructors, or blocks are Local Variables. They are declared and initialized in the method and exist as long as the method is not completed.
A: Variables declared in a class but outside a method are called Instance Variables.
A: Class variables or Static Variables are also declared in a class and outside a method, but they are declared with the keyword static.
A: Constructor, like method, initializes the state of an object. They are invoked upon creation of a new object. Each class must have a constructor, and the compiler creates one if it is not defined by the programmer.
A: Access modifiers are parts of the code that specify the level of access for classes, methods, variables, and constructors. If access modifiers are not specified, the member has a default or package access.
A: The default constructor, created by the compiler in absence of any defined constructor supplies default values to objects.
A: Keeping reference to a class in another class is called composition.
A: Exceptions are any problems that may arise when a program is being executed.
A: Runtime exception is an exception that occurs due to a programmer’s error and could have been avoided, typing mistakes in the code, for example. These exceptions are ignored during compilation.
A: Checked exception occurs due to a problem beyond the programmer’s control. For example, a file which needs to be opened could not be found. Such exceptions are not ignored during compilation.
A: Multiple methods in the same class nut with differing arguments is called overloading.
A: Overriding is an inheritance concept where two methods are defined with the same signature in both parent and child classes.
A: Packaging is the method of organizing classes in JAVA by grouping them according to modules or specific logic of functionality.
A: The keyword ‘finally’ is applied to create a code block to follow a try block. The ‘finally’ code block executes always, with or without an exception occurring.
A: When a method overrides another of its superclass, the method overridden can be called using ‘super’. It may also indicate a hidden field.
A: Polymorphism is defined as the ability of objects to exist in multiple forms as required. It is an integral property of Object Oriented Programming.
A: Abstract Classes are classes without an instance and are implemented either partially or not at all. They contain methods declared without a body, called abstract methods.
A: An Interface is a simple group of abstract methods. When an interface is implemented by a class, the abstract methods are inherited by it.
A: We all know that a Hashmap is a hash table based implementation of the map interface. A Hashmap produces an integer by performing a “hashing” calculation on the keys. It then uses that produced integer to find a bucket to get the value. It also determines the mapping of the bucket with the key/value pair by using the key’s hashcode.
A: A hashcode is a number generated from the java object. This is the work of hashcode to allow objects to be stored or retrieved quickly in a Hashtable. The Hashcode is a 32-bit signed integer which is generally used for comparing objects and are not necessarily unique. Two same type of objects is said to be equal if they have the same type of hashcode.