Common Jobs

Common Jobs Logo

Core java interview quentions and answer

Core java interview quentions and answer : The term “Core Java” describes the basic and necessary elements of the Java programming language. It includes all of the fundamental tools, frameworks, and ideas that underpin Java development. Any Java developer must comprehend Core Java since it offers the foundation for developing reliable and effective Java applications. Here are a few essential interview quentions and answerof Core Java:

Core java interview quentions and answer
1) what are static blocks and static initializers in Java ?

In Java, static fields are initialized using static blocks or static initializers. When we wish to initialize static fields in our class, we declare static blocks. Upon class load, static blocks are executed exactly once.Even before the constructors are executed, static blocks are run.

static blocks :

A static block in Java refers to a unique code block that is only performed once when the Java Virtual Machine loads the class into memory (JVM). Initializing static variables and carrying out one-time class initialization operations are the main uses of static blocks.

static initializers :

A static initializer in programming is a block of code that loads a class into memory and is only run once. It is used to carry out any one-time operations that need to be completed when a class is initially accessed, such as initializing the static members of the class.

2) How to call one constructor from the other constructor ?
  • If a class in object-oriented programming has more than one constructor and you would like one of them to call another, you can use the “this” keyword in the constructor to do so. We call this constructor chaining. Using this, the syntax for invoking an additional constructor is.
  • Using the this() function, we can call one constructor from another within the same class. This() method is called based on how many parameters we provide in.Limitations on applying this technique are

1) this must be the first statement in the constructor
2)we cannot use two this() methods in the constructor

3) What is method overriding in java ?
  • We say that a subclass method is overridden by a superclass if we have methods with the same signature (same name, same signature, and same return type) in both superclass and subclass.
  • When to utilize Java’s overriding
  • Overriding is used when we want the same method in a superclass and a subclass, but with distinct behavior.
  • The subclass method that is dubbed “hiding the superclass method” is invoked when an overridden method with a subclass reference is called.
4) What is super keyword in java ?
  • Subclasses have the ability to override superclass variables and methods. A subclass object calls its own variables and functions when it overrides. Because the overridden variables or methods conceal the super class’s methods and variables, subclasses are unable to access their contents.
  • Even in cases where a super class’s members are overwritten, Java nevertheless offers a method to access them. To access superclass variables, methods, and constructors, use super.

1) First form is for calling super class constructor.
2) Second one is to call super class variables,methods.

5) What is method overloading in java ?
  • When a class contains two or more methods with the same name but distinct arguments, we refer to those methods as overloading. Java allows for static polymorphism through the use of method overloading.
  • When we want different inputs or values to be utilized for comparable tasks, we use method overloading. Java first verifies the method name, number, and type of arguments when an overloaded method is called; the compiler then executes the method based on this information.
  • At compilation time, the compiler selects which method to invoke. In Java, static polymorphism or static binding can be accomplished using overloading.
6) What is bytecode in java ?
  • When Java source code is compiled, the Java compiler produces intermediate code known as “bytecode.” Unlike certain conventional compilers, which output machine code tailored to a particular architecture, the Java compiler generates bytecode that is agnostic of platform.
  • A.class file is produced when a class is compiled by a Java compiler. Byte code is a set of instructions included in this.class file. Machine-independent byte code is made up of a set of instructions that can only be carried out by the Java Virtual Machine (JVM). This byte code is understandable by JVM.
7) What is JIT compiler ?
  • Just in time compiler is referred to as JIT compiler. Byte code is compiled into executable code by the JIT compiler.
  • JVM includes JIT.JIT translates Java programs just as needed during execution; it is unable to turn entire Java programs into executable code.
  • Java programs can benefit from enhanced runtime performance along with platform independence when JIT compilation is used. The Java Virtual Machine (JVM) constantly adjusts to the program’s execution profile, maximizing the efficiency of the heavily utilized sections.
8) What is a class ?
  • The fundamental or base building block of object-oriented programming is the class.A class functions as an object’s blueprint or template. Variables and methods are defined in the class. What kind of objects we are constructing is specified by a class.
  • As an illustration, the Department class allows us to build objects that are departmental in nature. Any number of department objects can be created.
  • In Java, every programming construct is contained in a class. The JVM searches for the class when it first launches after compilation. There must be one main function and one class in any Java application.
  • Class keyword comes first in a class. A class definition needs to be kept in a class file with the same name as the class.
  • The last character of a file name must be.java.

public class FirstClass
{public static void main(String[] args)
{System.out.println(“My First class”);
}
}

When we compile, if we see the above class, JVM loads FirstClass and creates a.class file (FirstClass.class). The main method is called after the class has been run when the program is executed.

Core java interview quentions and answer
Core java interview quentions and answer
9) What is an object ?
  • An object is a class instance. A class specifies an object’s type.
  • Every item is a member of a class.All objects have states and behaviors.
  • Behavior is referred to as a method, and the values of characteristics determine the state. Moreover, objects are referred to as instances.
    We declare the class using the class type in order to instantiate it.

public classFirstClass {public static voidmain(String[] args)
{
FirstClass f=new FirstClass();
System.out.println(“My First class”);
}
}

To instantiate the FirstClass we use this statement
FirstClass f=new FirstClass();
f is used to refer FirstClass object

10)What is method in java ?
  • It includes the executable body that can be used with the particular class object.
  • A method consists of an executable code body, a method name, parameters or arguments, and a return type.

Syntax : type methodName(Argument List){ }

ex : public float add(int a, int b, int c)

Multiple arguments can be used with a method. When we have more than one argument, separate them with commas.

11) What is Unicode ?
  • Every letter, symbol, and script used in written languages worldwide is given a unique number (code point) under the Unicode standard character encoding system. Its goal is to represent text in all writing systems and languages, irrespective of the platform, software, or language, by serving as a universal character encoding standard.
  • As the de facto standard for character encoding, Unicode is essential to maintaining interoperability and accurate text representation in the digital age. It does away with the constraints of previous character encoding systems and enables linguists, software developers, and users to interact with a wide variety of characters and scripts.
12) What are constants and how to create constants in java?

In Java, variables that are assigned and should not have their values changed are called constants. They serve as program representations for fixed values or parameters, and their values don’t change while the program is running. Constants are declared in Java using the final keyword.

Ex : final int number =10;
final String str=”java-interview –questions”

13) Explain Java Coding standards for interfaces?
  • Uppercase letters should be used to begin interfaces.
  • Interface names ought to be descriptive
  • Example : Runnable, Serializable, Marker, Cloneable
14) Explain Java Coding standards for Methods?
  • Small letters should be used to begin method names.
  • Typically, method names are verbs
  • Every inner word in a method that has numerous words should begin with an uppercase letter.For example, toString()
  • The method name needs to be a verb-noun combination.
  • Ex : getCarName(),getCarNumber()
15) Explain Java Coding Standards for variables ?
  • Small letters should be used to begin variable names.
  • Names that change should be nouns.
  • It is advised to use brief, meaningful names.
  • Every innerword, if there are several, should begin with an uppercase letter.
  • Ex : string,value,empName,empSalary
Core java interview quentions and answer
16) Explain Java Coding Standards for Constants?
  • The static and final keywords are used in Java to construct constants.
  • Only capital letters are used in constants.
  • An underscore should be used to separate any constant names that consist of two or more words.
  • Nouns are often constant names.
  • Ex:MAX_VALUE, MIN_VALUE, MAX_PRIORITY, MIN_PRIORITY
17) What is ASCII Code?
  • ASCII, an acronym for American Standard Code for Information Interchange, is a standard character encoding used to represent text and control characters in computers and communication devices. Each character in ASCII is represented by a 7-bit binary code, for a total of 128 possible combinations of letters, numbers, punctuation, and control characters.
  • Originally created in the early 1960s, ASCII is now widely used in a wide range of applications, such as programming, data sharing, and communication protocols. It is a fundamental encoding standard for computers. Every ASCII character has a distinct numerical value, which is often expressed in either decimal or hexadecimal notation.
  • To handle more characters and more languages, extended versions of ASCII, like the 8-bit Extended ASCII, have been created over time. Even with the advent of more contemporary character encodings like Unicode, ASCII is still a widely used encoding scheme, particularly in applications and legacy systems.
18) What is ‘IS-A ‘ relationship in java?
  • The term “is a” relationship can also refer to inheritance. The extends keyword in Java allows us to implement inheritance and “is a” relationships. Reusing code instead of duplicating it is an advantage of inheritance or relationships.
  • Ex : Motor cycle is a vehicle,Car is a vehicle Both car and motorcycle extends vehicle.
19) What does null mean in java?
  • The special literal null in Java denotes the lack of an object reference or the absence of a value. A variable does not point to any memory-based objects when it is assigned the value null.
  • Example : Employee employee;
  • In the above example employee object is not instantiate so it is pointed no where
20 ) What are packages in java?
  • An interface, an enum, and related classes can be grouped together into a single module using a package.
    The declaration of a package can be made with the following syntax:
    Syntax : packageEncoding Convention: The name of the package must be stated in tiny letters.
    namespace is defined by the package declaration.
    The primary purpose of the package is:
  • 1) To settle disputes over names
    2) We can designate classes and interfaces that are inaccessible from outside the class in order to control visibility.
Share the opportunity

Leave a Comment

three × 1 =