Top 40 Jenkins Interview Questions And Answers For Freshers/Experienced
If you are looking for a career in software development, then Jenkins is definitely worth exploring. This widely used …
Core Java is a very important part of the Java programming language. So if you are appearing for a technical job interview then you need to well prepare the core java topics. To help you out, here we have provided a list of Core Java interview questions and answers from which you can prepare for your interview. Go through each question given here and prepare it well, here we have covered basic, advanced, coding-based core java interview questions for experienced and freshers.
About Core Java: It is a part of the Java programming language which is used to develop or create general-purpose online applications and mobile applications. Without Core Java, you are not able to develop any advanced java applications. Core java programming covers many important things like awt, swings, thread concept, socket, collection object, and classes.
Also, prepare for Java Collection interview questions, Networking interview questions, and other language interview questions from here.
2. Explain some features of the Java Programming language.
3. Explain Java virtual machine?
4. Tell the different types of memory areas are assigned by JVM?
7. Differentiate between Java and other platforms?
8. From where does this 'write once and run anywhere' nature in Java?
10. Is Empty .java file name a valid source file name?
11. What if I mention a static public void than a public static void?
12. Tell the default value of the local variables?
13. Explain various access specifiers in Java?
14. Tell some advantages of Packages in Java?
15. Explain the object-oriented paradigm?
18. Explain the types of constructors?
19. Does the constructor bring back any value?
20. Explain the static method?
21. Explain the restrictions applied on static methods in Java?
22. Explain the reason for being the main method static?
24. Can a program be executed without the main() method?
25. What happens when the static modifier is detached from the signature of the main method?
26. Are we able to make constructors static?
27. Can we create the abstract methods static in Java?
28. Explain this keyword in java?
29. Explain the uses of this keyword?
30. Can we allocate the reference to this variable?
31. Can this keyword be used to refer to static members?
32. Using this keyword, how constructor chaining can be done?
36. Differentiate aggregation and composition?
37. Why is the reason Java does not support pointers?
38. Explain the super keyword in java?
39. Show by coding how super keyword can be used to do constructor chaining?
40. Explain the uses of the super keyword?
41. Differentiate between this and super keyword?
42. Can we use super() & this() both in a constructor?
44. Explain method overloading?
45. Why do method overloading won’t work by changing the return type in java?
46. How can we overload the main() method?
47. Explain rules of method overriding?
48. Why are we not able to override the static method?
49. Are we able to override the private methods?
50. In subclass can we modify the scope of the overridden method?
2. Explain some features of the Java Programming language.
3. Explain Java virtual machine?
4. Tell the different types of memory areas are assigned by JVM?
7. Differentiate between Java and other platforms?
8. From where does this 'write once and run anywhere' nature in Java?
10. Is Empty .java file name a valid source file name?
Yes, Java authorizes us to save our java file by .java only, after that we need to assemble it by javac .java and operate by java class name. For example:
//save by .java only
class A{
public static void main(String args[]){
System.out.println(“Hello java”);
}
}
//compile by javac .java
//run by java A
compile it by javac .java
run it by java A
11. What if I mention a static public void than a public static void?
12. Tell the default value of the local variables?
13. Explain various access specifiers in Java?
14. Tell some advantages of Packages in Java?
15. Explain the object-oriented paradigm?
18. Explain the types of constructors?
19. Does the constructor bring back any value?
20. Explain the static method?
Follow Simple Steps to apply in these MNC’s:
21. Explain the restrictions applied on static methods in Java?
22. Explain the reason for being the main method static?
It is used to set the static data member and executed prior to the main method, at the time of classloading.
class A2{
static{System.out.println(“static block is invoked”);}
public static void main(String args[]){
System.out.println(“Hello main”);
}
}
24. Can a program be executed without the main() method?
25. What happens when the static modifier is detached from the signature of the main method?
Initially, Program compiles but at runtime, It shows an error “NoSuchMethodError.”
Know the Interview Criteria of these MNCs!!!
26. Are we able to make constructors static?
27. Can we create the abstract methods static in Java?
28. Explain this keyword in java?
29. Explain the uses of this keyword?
30. Can we allocate the reference to this variable?
No, this variable is not able to be assigned to any value as it always refers to the current class object and in Java, this is the final reference. The compiler will show an error if we try to do so. For example.
public class Test
{
public Test()
{
this = null;
System.out.println(“Test class constructor called”);
}
public static void main (String args[])
{
Test t = new Test();
}
}
Output
Test.java:5: error: cannot assign a value to final variable this
this = null;
^
1 error
31. Can this keyword be used to refer to static members?
this keyword is just a reference variable that points to the current class object. Nevertheless, it is useless to access static variables through objects, therefore, we don’t use this to refer to static members. For example:
public class Test
{
static int i = 10;
public Test ()
{
System.out.println(this.i);
}
public static void main (String args[])
{
Test t = new Test();
}
}
Output
10
32. Using this keyword, how constructor chaining can be done?
Constructor chaining allows us to call one constructor from another constructor of the class w.r.t. the current class object. this keyword can be used to perform constructor chaining in the same class. Check the below-given example:
public class Employee
{
int id,age;
String name, address;
public Employee (int age)
{
this.age = age;
}
public Employee(int id, int age)
{
this(age);
this.id = id;
}
public Employee(int id, int age, String name, String address)
{
this(id, age);
this.name = name;
this.address = address;
}
public static void main (String args[])
{
Employee emp = new Employee(105, 22, “Vikas”, “Delhi”);
System.out.println(“ID: “+emp.id+” Name:“+emp.name+” age:“+emp.age+” address: “+emp.address);
}
}
Output
ID: 105 Name:Vikas age:22 address: Delhi
33. Tell the benefit of passing this keyword into a method rather than the current class object itself?
It is a mechanism through which a single object can acquire all the behavior and properties of another object of another class. Inheritance is used for Method Overriding and Code Reusability. The idea used behind inheritance is that you can make new classes that are made upon existing classes. When you come from an existing class, you can utilize methods and fields of the parent class and also add new methods and fields in your present class. It shows the IS-A relationship that is also called the parent-child relationship.
5 types of inheritance in Java are:
Multiple inheritances are not supported in Java through the class.
36. Differentiate aggregation and composition?
37. Why is the reason Java does not support pointers?
38. Explain the super keyword in java?
It is basically a variable that always points to the immediate parent class object. When you make the subclass instance then an instance of the parent class is made implicitly which referred to the super keyword reference variable. The super() automatically becomes the class constructor by the compiler when there is no super or this keyword is used.
class Animal{
Animal(){System.out.println(“animal is created”);}
}
class Dog extends Animal{
Dog(){
System.out.println(“dog is created”);
}
}
class TestSuper4{
public static void main(String args[]){
Dog d=new Dog();
}
}
Output:
animal is created
dog is created
39. Show by coding how super keyword can be used to do constructor chaining?
class Person
{
String name,address;
int age;
public Person(int age, String name, String address)
{
this.age = age;
this.name = name;
this.address = address;
}
}
class Employee extends Person
{
float salary;
public Employee(int age, String name, String address, float salary)
{
super(age,name,address);
this.salary = salary;
}
}
public class Test
{
public static void main (String args[])
{
Employee e = new Employee(22, “Mukesh”, “Delhi”, 90000);
System.out.println(“Name: “+e.name+” Salary: “+e.salary+” Age: “+e.age+” Address: “+e.address);
}
}
Output
Name: Mukesh Salary: 90000.0 Age: 22 Address: Delhi
40. Explain the uses of the super keyword?
You may also prepare:
41. Differentiate between this and super keyword?
42. Can we use super() & this() both in a constructor?
No, because super() and this() should be the first statement in the class constructor.
Example:
public class Test{
Test()
{
super();
this();
System.out.println(“Test class object is created”);
}
public static void main(String []args){
Test t = new Test();
}
}
Output:
Test.java:5: error: call to this must be the first statement in the constructor
Object cloning is used to make a clone, an exact copy of an object. The Object class uses the clone() method to clone an object. By the object class java.lang.Cloneable interface needed to be implemented on those objects which are cloned. If the cloneable interface is not implement then, clone() method create CloneNotSupportedException.
protected Object clone() throws CloneNotSupportedException
44. Explain method overloading?
Method overloading is the polymorphism method that permits you to generate multiple methods with the same name but dissimilar signatures. Through these ways, you can achieve method overloading.
It enhances the readability of the program and it is performed to work out the program quickly.
45. Why do method overloading won’t work by changing the return type in java?
In Java programming, method overloading is not workable by changing the return type of the program because of avoiding ambiguity.
class Adder{
static int add(int a,int b){return a+b;}
static double add(int a,int b){return a+b;}
}
class TestOverloading3{
public static void main(String[] args){
System.out.println(Adder.add(11,11));//ambiguity
}}
Output:
Compile Time Error: method add(int, int) is already defined in class Adder
46. How can we overload the main() method?
47. Explain rules of method overriding?
48. Why are we not able to override the static method?
49. Are we able to override the private methods?
50. In subclass can we modify the scope of the overridden method?
If you want to prepare for more programming languages other than core java interview questions and answers for experienced and freshers then you can take help from the below-given interview questions list. If you have any concerns and queries related to core java interview questions and answers then reach us through the comment box given below.
Want to prepare for these languages:
If you are looking for a career in software development, then Jenkins is definitely worth exploring. This widely used …
In this post, we will cover a few Linux interview questions and their answers. So, let’s get started. In this …