Core Java Interview Questions and Answers
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
Ques 1. What is Constructor in Java?
Constructor is a block of code which is executed at the time of Object creation. It is entirely different than methods. It has same name of class name and it cannot have any return type.
Ques 2. What is java.util package in Core Java?
Java.util package contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes.
- java.util.List
- java.util.Set
- java.util.Date
Ques 3. What is difference between String and StringTokenizer?
A StringTokenizer is utility class used to break up string. Example:
StringTokenizer st = new StringTokenizer("Hello World");
while (st.hasMoreTokens()) {
System.out.println(st.nextToken());
}
Output:Hello
World
Ques 4. What is the argument type of a program's main() method?
A program's main() method takes an argument of the String[] type.
public static void main(String args[])
{
System.out.println("WithoutBook");
}
Ques 5. What is this() keyword in core java and when should we use this() in core java?
public class Foo {
private String name;
// ...
public void setName(String name) {
// This makes it clear that you are assigning
// the value of the parameter "name" to the
// instance variable "name".
this.name = name;
}
// ...
}
class Foo{
void callMethod(){
Toy toy = new Toy();
toy.insertValue(this); //Here this means Foo current object
}
}
class Foo {
public Foo() {
this("Some default value for bar");
// Additional code here will be executed
// after the other constructor is done.
}
public Foo(String bar) {
// Do something with bar
}
// ...
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
Most helpful rated by users:
- How could Java classes direct program messages to the system console, but error messages, say to a file?
- What are the differences between an interface and an abstract class?
- Why would you use a synchronized block vs. synchronized method?
- How can you force garbage collection?
- What are the differences between the methods sleep() and wait()?