Archive for the ‘ Java Questions ’ Category

The createNewFile() method of the File class is used to create a new empty file if a file with the given name does not already exist. It returns true if a file with the given name does not exist and is successfully created; otherwise, it returns false.

  • Share/Bookmark

class TestInstanceof {
public static void main(String[] args) {
Integer i=5;
Boolean b;
b=(i instanceof Integer);
System.out.print(b);
b=(i instanceof Number);
System.out.println(b);
}
}

  • Share/Bookmark

A: Adding objects to a collection
B: Iterating through a collection
C: Finding out if an object is in a collection
D: Retrieving an object from a collection

All answer options are correct because:

The Collections Framework in Java is a hierarchy of interfaces and classes that provides a technology for managing a group of objects. It is used to provide a central and unified theme for managing a group of objects. The Java Collections Framework is designed to meet the following goals:

  • To offer high performance in terms of efficiency.

  • Share/Bookmark

import java.util.*;
public class TestArray{
public static void main(String[] args){
TestArray test = new TestArray();
test.go();
}
public void go(){
int[] arr = new int[] {1,2,3,4,5,6};
//add code here
}
}

  • Share/Bookmark