TCS Tech JAVA Final | 2018

import java.util.*;

class hashtable{
            public static void main(String args[]){
                        Hashtable obj = new Hashtable();
                        obj.put("A",new Integer(3));
                        obj.put("B",new Integer(2));
                        obj.put("C",new Integer(8));
                        obj.remove(new String("A"));
                        System.out.print(obj);
            }
}

Ans: {C=8, B=2}

Consider the following Schema?
STUDENTS(student_code, first_name,last_name, email, phone_no, date_of_birth, honours_subject, percentage_of_marks); Which of the following query would display names and percentage of marks of all  students stored by honours subject,and then order by percentage of marks?
Ans: (a) Select first_name, lastname, hours_subject, percentage_of_marks from students order by honours_subject,percentage_of_marks.


Which of the following statements are incorrect?
Ans: Strings in java are mutable.


Which statements is true for request.getSession(true) method?
Ans:  getSession(true) method always returns a new session


In HTTP Request method Get request is secured because data is exposed in URL bar?
Ans: False



JDK stands for
Java Development Kit


import java.util.*;
public class Test{
            public static void main(String args[]){
                        System.out.println(new Test().mystery("DELIVER"));
            }
            public String mystery(String s){
                        String s1 = s.substring(0,1);
                        String s2 = s.substring(1,s.length()-1);
                        String s3=s.substring(s.length()-1);
                        if(s.length()<=3)
                                    return s3+s2+s1;
                        else return s1+mystery(s2)+s3;
            }
}

Ans: DEVILER


import java.util.*;
public class Test{
            public static int intValue;
            public static void main(String args[]){
            System.out.println(intValue);
            }
           
}
Ans: 0


FileOutputStream is meant for writing streams of_ _ _ _ _  _
Ans: raw bytes
                

What is the return type of reverse() method in StringBuffer class?
Ans: StringBuffer


Which of these is an incorrect array declaration?
Ans:  (d) int arr[] = int [5] new


_ _ _ _ is used to compare equality of two Strings
Ans: equals() method of Strong class


Which of these statements can skip processing remaining of code in this its body for a particular iteration?
Ans: continue

New drivers can be plugged-in to the JDBC API without changing the client code.
Ans: TRUE


What exception is thrown by read() method of InputStreamReader?
Ans: IOException

JAVA_HOME points to which directory?
Ans: JDK Installation directory.

In which package can we found DataInputStream class?
Ans: java.io

Is write() method in BufferedWriter Class overloaded?
Ans: TRUE

Which of the following is implemented by OutputStream class?
Ans: All of the mentioned. (closeable, flushable,autocloseable)

import java.util.*;
public class Test{
            public static void main(String args[]){
            int num=10;
            switch(num);
            }
           
}
Ans: Compiler Error

JDk7 introduced a new version of the try statement known as____
Ans: try-with-resources statement

Which of these exception is thrown in cases when the file specified for writing it not found?
Ans: FileNotFoundExcepion

public void foo(boolean a, boolean b){
                        if(a)
                        {
                                    System.out.println("A"); // line 5
                        }else if(a&&b){ //line 7
                                    System.out.println("A&&B");
                        }else{ // line 11
                                    if(!b){
                                                System.out.println("notB");
                                    }else{
                                                System.out.println("ELSE");
                                    }
                        }
            }
ANS: If a is false and b is true then the output is “ELSE”
           

class Base{
            public int varOne = 1000;
            public int varTwo = 2000;
            public int varThree;
            void display(){
                       
            }
}
class Derived extends Base{
            public int varThree = 10;
            void display(){
                        System.out.println("varOne:"+varOne);
            }
            void disp(){
                        int varThree = 100;
                        System.out.println("varTwo:"+varTwo);
                        System.out.println("varThree:"+varThree);
                        System.out.println("varThree:"+super.Three);
            }
}
class Demo{
            public static void main(String s[]){
                        Derived ob1 = new Derived();
                        ob1.display();
                        ob1.disp();
            }
}

Ans: ( b ) varone: 1000varTwo: 2000varThree:100varThree:0


Value return on reaching end of file in Writer class?
Ans: -1

Which of the following statements about array is syntactically wrong? Assume that in the options, datatype is any valid datatype in java
Ans: datatype p[5];

What command is used to remove the directory?
Ans: rmdir

TRIM function in oracle will trim off unwanted characters from both sides of string.
Ans: TRUE.


Is readFloat() of DataInputStream static?
Ans: True

class Test{
            public static void main(String[]args){
                        int x = 20;
                        String sup = (x<15)?"small":(x<22)?"tiny" : "huge";
                        System.out.println(sup);
            }
}
What is the output of above code snippet?
Ans: tiny

These methods doGet(), doPost(),doHead,doDelete(),doTrace() are used in ?
Ans: HttpServlets


What is the return type of skip() method of InputStreamReader?
Ans:  long


Compile time exception is when the compiler gives error for improper syntax in code like forgetting a semicolon.
Ans: True


What is the return type reset() methd in BufferedInputStream?
Ans: void


String s ="hello";
String t=s;
t=s+"world";
System.out.println(s);
Ans: hello


public class Test{
            public static void main(String[]args){
                        String a = "1";
                        String b = "2";
                        System.out.println((a+b).length());
            }
}
Ans: 2


How to declare that age is a variable of type integer with initial value 20 in java?
Ans: int age=20;


CREATE SEQUANCE seq_testing MINVALUE 3 START WITH 2 INCREMENT BY 5
Select the true statement based on the above code:
Ans:  On trying to create it will give error. STARTWITH cannot be less than MINVALUE


Which of the following are valid array declarations?
Ans: double []arr=new double[10];
Select the checked exception from the following options:
Ans: ParseException

public class Example{
            public static void main(String args[]){
            Object error=new Error();
            Object runtimeException = new RuntimeException();
            System.out.print((eror instnaceofException)+",");
            System.out.print(runtimeExceptioninstnaceofException);
           
            }
           
}

Ans: Prints: false,true


How many numeric data types are supported In java?
Ans: 6


public class Bank{
            public void getBankName(){
                        System.out.println("Bank");
            }
}
public class Icici extends Bank{
            public void getBank(){
                        System.out.println("ICICI");
            }
            public static void main(String args[]){
            Bank bank = new Icici();
            bank.getBankName();
            bank.getBank();
           
            }
           
}          

Ans: CompilerError


Which method is used to remove leading and trailing whitespaces in String?
Ans: trim();




Class A inherited by classes B and C. Assume we have a method in class A which both class B & C overrides. Now if Class D is extending both B & C and d wants to override the same method an ambiguity will result. This problem is called_ _
Ans: diamond problem


Which of the following is TRUE regarding Abstraction?
Ans: Abstraction exposes essential details while hiding the non-essential details


Which of the following method is used to return a Set that contains the entries in a map?
Ans: entrySet()


When a method can throw an exception then it is specified by _ _ _ keyword
Ans:  Throws


Which of these interface handle sequences?
Ans: List

                                                                                  
Java source code is case _ _ _ _ ?
Ans: sensitive


Which of these is an incorrect Statement?
Ans: It is necessary to use new operator to initialize an array


Which of the following are the five built-in functions provided by SQL?
Ans: COUNT, SUM, AVG, MAX, MIN



Which of the following is a valid declaration of an object of class Box?
ANS: Box obj = new Box();


class Demo{
            Demo(char status){
                        System.out.println("Parameterized constructor");
            }
            public static void main(String[]args){
                        Demo ob = new Demo('A');
            }
}
Ans: This code will compile as the default constructor is not used in main()


In BufferedOutputStream, the method notify is inherited from:
Ans: java.lang.Object


What is the return type of read() method in BufferedReader class?
Ans: Boolean


Generics, enumerations supported by
Ans:  java SE2


Which of the following is not true about modifying rows in a table?
Ans: You can update more than one row at a time.


_ _ _ _ in java identifies and discards the objects that are no longer needed by a program so that their resources can be reclaimed and reused.
ANS: Garbage collection

_ _ _ _ _ is also known as static variable
ANS: Class variables


FileReader is meant for reading streams of characters. For reading streams of raw bytes, use FileInputStream.
Ans: True


Which exception does close() method throw in BufferedReader class?
Ans: IO Exception


What type of exception can readLine() of DataInputStream throws?
Ans: IOException


What is the return type of write() method in BufferedWriter Class?
Ans: void()


In which Package Writer classes are defined?
Ans: java.io

When three or more AND and OR conditions are combined, it is easier to use the SQL keywords:
Ans: Both IN and NOT IN


Emp_Bonus table has the following data.
Employee bonus
A 1000
B 2000
A 500
C 700
B 1250
What is the SQL query to get the employees who received bonus more than $1,000?
Ans:  c select employee, sum(bouns) from emp_bonus group by employee having sum(bonus)>1000;


What does write(int x) of BufferedOutputStream do?
Ans: Writes the specified bytes to output stream


Which of he following is not true about the database objects?
Ans: Views give alternative names to objects.


The method forward(request,response) will
Ans: Return back to the same method from where the forward was invoked


Which method returns a string containing the unique session id?
Ans: getId()


Which of these classes is used for input operation when working with bytes?
Ans: InputStream


Which of the following is true?
Ans: all of the above
a.    Enum in java is a data type
b.    Enum can have fields, constructors and methods
c.    Enum may implement many interfaces but cannot extend any class because it internally extends Enum class



Which of the following is statements are true?
Read(byte[] b)



What is the exception thrown by write() of DataOutputStream class?
Ans: IOException


public class Sample{
            public static void main(String args[]){
            Employee[] e1=new Employee[10];
            Employee emp = new Employee(1,"A");
            System.out.println(e1[0].id);
           
            }          
}
class Employee{
            int id;
            String name;
            Employee(int i, String s)
            {
                        id=i;
                        name=s;
            }
}

Ans: Runtime Error

The expected signature of the main method is public static void main(). What happens if we make a mistake and forget to put the static void keyword? Assume that we are executing using command prompt?
Ans: The JVM fails at runtime with NoSuchMethodError


1.      Which interface does DataInputStream implements?
Ans: DataInput

3. Will this code compile?

class Demo
{
Demo(char status)
{
System.out.println("Parameterized constructor");
}
public static void main(String args[])
{
Demo ob=new Demo('A');
}
}
Ans: This code will compile as the default constructor is not used in main()

4. Which method is used to print the description of the exception?

Ans: printStackTrace()

5. The method forward(request,response) will

Ans: return back to the same method from where the forward was invoked

6. Select a query that retrieves all of the unique coursename from the student table?

Ans: SELECT DISTINCT coursename FROM studentinfo;

7. Which of the following is true?

Ans: all of the above (Enum in java is a data type, enum can have fields, constructors and methods, enum may implement many interfaces but cannot extend any class because it internally extends Enum class)

8. ON UPDATE CASCADE ensures which of the following?

Ans: Data Integrity

9. public class Test{

public static void main(String args[]){
String obj="I LIKE JAVA";
System.out.println(obj.charAt(5));
}
}
What is the output of above program?
Ans: E

10. class Equals

{
public static void main(String args[])
{
int x=100;
double y=100.1;
boolean b=(x=y); /*Line 7*/
System.out.println(b);
}
}
What is the output of above code snippet?
Ans: Compilation fails

11. Which of the following interprets html code and renders webpages to user?

Ans: browser

12. Which normal form is considered adequate for relational database design?

Ans: 3NF

13. What type of exception can readLine() of DataInputStream throws?

Ans: IOException

14. Which of these is method is used for writing bytes to an OutputStream?

Ans: write()

15. Is Java an open source software language?

Ans: Yes, Its an open source

16. Which of these are the subclasses of InputStream class?

Ans: All of the mentioned (AudioInputStream, ByteArrayInputStream, FileInputStream)

17. What is the return type of read() method in BufferedInputStream?

Ans: int

18. Every statement in java programming language ends with

Ans: Semicolon

19. All the methods in an interface are_______and________by default

Ans: Public, abstract

20. A stream that is intended for general purpose IO, not usually character, data, is called..

Ans: ByteStream

21. Parameter of______datatype is accepted by skipBytes()?

Ans: int

22. Which of these interface is not a member of java.io package?

Ans: ObjectFilter

23. Is the read function of DataInputStream class overridden?

Ans: True

24. Which of these method of class StringBuffer is used to concatenate the string representation to the end of invoking string?

Ans: append()

25. The reset method of BufferedInputStream accepts parameters

Ans: False

26. What is the output of this program?

import java.util.*;
class Array
{
public static void main(String args[])
{
int array[]=new int[5];
for(int i=5;i>0;i--)
array[5-i]=i;
Arrays.sort(array);
for(int i=0;i<5;++i)
System.out.println(array[i]);
}
}
Ans: 12345.0

27. Java platform consists of below components

Ans: Java API, JVM

28. Return type of newLine() in BufferedWriter class is Boolean

Ans: False

29. What is the return type of read function in DataInputStream class?

Ans: int

30. public class StringExam{

public static void main(String args[])
{
String s1="Arun";
String s2="Arun";
String s3=new String("Arun");
String s4=new String("Arun");
System.out.println(s1.equals(s2));
System.out.println(s1==s2);
System.out.println(s3.equals(s4));
System.out.println(s3==s4);
}
}
Ans: true true true false

31._____is a collection of objects with similar properties

Ans: class

32. Which of these keywords must be used to monitor for exceptions?

Ans: try

33. Is readShort() of DataInputStream final?

Ans: True

34. The FileReader assumes that you want to_____the bytes in the file using the default character encoding for the computer your application is running on

Ans: decode

35. The way a particular application views the data from the database that the application uses is a

Ans: Sub schema

36. InputStreamReader(InputStream) creates an InputStreamReader that uses______

Ans: default character encoding

37. An object of which is created by the web container at time of deploying the project?

Ans: ServletContext

38. How many parameters does the read() accept in DataInputStream class?

Ans: 1,3

39. Given request is an HttpServletRequest, which code snippets will create a session if one doesn't exist?

Ans: request.getSession();

40. Java programs should be compiled for each type of platform

Ans: false

41. How many parameters does the skipByte() accept in DataInputStream class?

Ans: 1

42. What is the return type of read() method in BufferedInputStream?

Ans: int

43. What command is used to remove the directory?

Ans: rmdir

44. java.util.Properties class extends________class

Ans: java.util.Hashtable

45. Which of the following describes the correct sequence of the steps involved in making a connection with a database. 

      1. Loading the driver
      2. Process the results
      3. Making the connection with the database
      4. Executing the SQL statements
Ans: 1,3,4,2

46. Writer class is for processing Character streams

Ans: True

47. How many numeric data types are supported in Java?

Ans: 6

48. java.exe can be found at which 2 places in JDK directory?

Ans: JAVA_HOME\jre\bin

49. public void write(int b) of FileOutputStream implements the write method of OutputStream

Ans: True

50. The sendRedirect() method of HttpServletResponse interface can be used to redirect response to another resource, it may be servlet, jsp or html file?

Ans: True

51. Arrays when passed to a method they are always passed by refernce. Is this true or false?

Ans: True

52. JVM is available for:

Ans: All popular Operating Systems

53. Which of these can be thrown using the throw statement?

Ans: All the above (a) Error, b) Throwable, c) Exception)

54. Which of the following is the data query statement in QUEL?

Ans: SELECT

55. How many techniques are used in Session Tracking?
Ans: 4.0

56. is write() method in BufferedWriter class overloaded?
Ans: True

57. Fork is 
Ans: The creation of a new process

58. JDK7 introduced a new version of try statement known as____
Ans: try-with-resources statement

59. How many parameter does the readBoolean() of DataInputStream accepts?
Ans: 0

60. Java is a______independent language
Ans: Platform

61. What is the return type of close() method in BufferdReader class?
Ans: void

62. What is the output of the code

public class test{

public static void main(String args[]){
int i=1,j=1;
try{
i++;
j--;
if(i/j>1)
i++;
}
catch(ArithmeticException e){
System.out.println(0);
}
catch(ArrayIndexOutOfBoundsException e){
System.out.println(1);
}
catch(Exception e){
System.out.println(2);
}
finally{
System.out.println(3);
}
System.out.println(4);
}
}
Ans: 0,3,4

63. A file containing relatively permanent data is
Ans: Master File

64. Which of the following are the five built-in functions provided by SQL?
Ans: COUNT, SUM, AVG, MAX, MIN

65. It is a good practice to put the cleanup code(like closing Connection or PrintWriter object) in______block, even when no exceptions are anticipated.
Ans: finally

66. Which life cycle method make ready the servlet for garbage collection
Ans: destroy

67. reset() have boolean return type in BufferedReader class
Ans: True

68. Subclass of Writer class is?
Ans: StringWriter

69. Development tools are
Ans: Both A and B ( a) compiler, b) java application launcher )

70. The expected signature of the main method is public static void main(). What happens if we make a mistake and forget to put the static keyword? Assume that we are executing using command prompt.
Ans: The JVM fails at runtime with NoSuchMethodError

71. Which of these class is used to read characters in a file?
Ans: FileReader

72. readLine() method have integer return types in BufferedReader class.
Ans: False

73. Java is an interpreter that interprets the byte code into machine dependent code and executes program
Ans: True

74. Which method is used access the cookies that are added to response object?
Ans: getCookies()

75. What checks the code fragments for illegal code that can violate access right to objects?
Ans: Bytecode verifier

76. What MySQL property is used to create a surrogate key in MySQL?
Ans: AUTO_INCREMENT

77. Program counter register is a type of area allocated by_____
Ans: none of these

78. What is the output of the below code?
class MyClass
{
int i;
float j;
public static void main(String[] args)
{
System.out.println("i="+i+"j="+j);
}
}
Ans: i=0 j=0.000000

79. Both Primary key and unique key allows NULL
Ans: false

80. What is the return type of read() method of InputStreamReader?
Ans: int

81. Which of the following require large computer memory?
Ans: All of the mentioned (Imaging, Graphics, Voice)

82. The tracks on a disk which can be accessed without repositioning the R/W heads is
Ans: Cylinder

83. Which will legally declare, construct and initialize an array?
Ans: int myList[]={4, 3, 7};

84.______in Java identifies and discards the objects that are no longer needed by a program so that their resources can be reclaimed and reused
Ans: Garbage Collection

85. What exception is thrown by read() method of InputStreamReader?
Ans: IOException

86. A non-correlated subquery can be defined as____
Ans: A set of one or more sequential queries in which generally the result of the inner query is used as the search value in the outer query

87. What is the fullform of WORA?

Ans: Write Once Run Anywhere

88. Is readByte() of DataInputStream final?
Ans: True

89. When three or more AND and OR conditions are combined, it is easier to use the SQL keyword(s):

Ans: Both IN and NOT IN

90. What type of exceptions can readFloat() of DataInputStream throws?
Ans: IOException

91. Arrays when passed to a method they are always passed by reference. Is this true or false?

Ans: true

92. A______file contains bytecodes
Ans: .class

93. Servlets handle multiple simultaneous requests by using threads?
Ans: True


94. In BufferedOutputStream, the method notify is inherited from:
Ans: java.lang.object

95. What will be the output of the below code:

public class Test{

public static void main(String args[])
{
String a="1";
String b="2";

System.out.println(a+b);

}
}
Ans: 12

96. A method within a class is only accessible by classes that are defined within the same package as the class of the method. Which one of the following is used to enforce such restriction?
Ans: Do not declare with any accessibility modifiers

97. close() method have integer return type in BufferedReader class
Ans: false

98. Which two statements are true regarding constraints?
Ans: A column with the UNIQUE constraint can contain NULL

99. Java is a_______level programming language
Ans: high

100. Which of these classes defined in java.io and used for file-handling are abstract: 
A) InputStream
B) PrintStream
C) Reader
D) FileInputStream
E) FileWriter
Ans: A and C

101. You want to calculate the sum of commissions earned by the employees of an organisation. If an employee doesn't receive any commission, it should be calculated as zero. Which will be the right query to achieve this?

Ans: select sum(nvl(commission,0))from employees

102. Which class does not override the equals() method, inheriting them directly from class object?
Ans: java.lang.StringBuffer

103.
public class Test{
public static void main(String args[]){
System.out.println(new Test().mystery("DELIVER"));}
public String mystery(String s){
String s1=s.substring(0,1);
String s2=s.substring(1,s.length()-1);
String s3=s.substring(s.length()-1);
if(s.length()<=3) return s3+s2+s1;
else
return s1+mystery(s2)+s3;
}}
What is the output of the above program?
Ans: (b )DEVILER

104. What data type does FileReader.readLine() return?
Ans: String
2.        
106. A part located in the central processing unit that stores data and information is known as
Ans: Core memory

107. FileInputStream class extends_____class
Ans: InputStream

108. mark() method have void return type in BufferedReader class.
Ans: True

109. _______is a special type of integrity constraint that relates two relations and maintains consistency across the relations
Ans: Referential integrity constraints

110. BufferedWriter is_______
Ans: Class

111. FileReader class inherits from the InputStreamReader class
Ans: True

112. What are all false about ENUMS?

Ans: Enums can extend any other type

113. What is the return type of readDouble() of DataInputStream class?
Ans: double

115. Given request is an HttpServletRequest, which code snippets will creates a session if one doesn't exist?

Ans: request.getSession();

116. Which of these method of FileReader class is used to read characters from a file?
Ans: read()

117. Which method is used to access the cookies that are added to response object?
Ans: getCookies()

118. _________joins two or more tables based on a specified column value not equaling a specified column value in another table
Ans: NON-EQUIJOIN

What is the return type of ready() method in BufferedReader class?
ANS: Boolean

skip() method have long returntype in Bufferedreader class.
ANS: TRUE

The type long can be used to store values in the following range:
ANS: -263 to 263-1

In BufferedOutputStream, the method clone is inherited from:
ANS: java.lang.Object

When the values in one or more attributes being used as a foreign key must exist in another set of one or more attributes in another table, we have created a(n)_ _ _ _
ANS: Referential integrity constraint

Public class Main {
   public static void main(String args[]) {
      try {
         throw 10;
      }
      catch(int ex) {
         System.out.print("Got the  Exception " + ex);
      }
  }
} What would be the output above program?
ANS: Compiler Error


Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?
ANS:  do-while
                                                                                             
What is the Return type of newline() method in BufferedWriter Class?
ANS: void

The given below program will remove the given character from the String ?
Private static String removChar(String str,char c){
If(str==null)
Return null;
Return str.replaceAll)(Character.toStrng(c),””);
}                              
ANS: True

The life cycle of a servlet is managed by
ANS: Servlet Container

What is the numerical range of char?
ANS: 0 to 65535

EMPDET is an external table containing the columns EMPNO and ENAME. Which command would work on relation to the EMPDET table?
ANS: CREATE VIEW empvu AS SELECT 8 FROM empdept;


Which three are valid array declarations?
1.      Int [] myScores[]
2.      Char [] myChars;
3.      Int [6] myScores;
4.      Dog myDogs [];
5.      :Dog myDogs[7];
ANS: 1,2,4


Buffering speeds up IO and it is not the same as writing one character at a time to the network or disk?
ANS: TRUE

Which of the following methods does BufferedInputSrream inherit from java.lang.Object?
All(equals,finilize,getClass)


Which of these data type is returned by every method of OutputStream
ANS: None of the mentioned

Public class example {
Public static void main(String args[]){
Int x = 0;
If(x >0)
X=1;
Switch(x){
Case 1: System.out.println(1);
Case 0: System.out.println(0);
Case 2: System.out.println(2);
Break;
Case 3: System.out.println(3);
Default:System.out.println(4);
Break;
 }
}
}
ANS:  0 2

class Test1{
                                public static void main(String[]args){
                                    int arr[]=new int[5];
                                    arr[1]=10;
                                    arr[3]=20;
                                    for(int i=0;i<5;i++){
                                                System.out.println(arr[i]);
                                    }
                                }
}
ANS: 0100200
Map’s subinerface, SortedMap,maintains its key-value pairs in ascending order or in an order specified by a Comparator
ANS: True

What type of exceptions are thrown by readShort() of DataInputStrea?
ANS: IOException

Select the advantages of layered architecture
All ( Simplicity-ease of design, Flexibility-Ease to modify, Incremental changes –Add new layers functions etc, )

Public class Test1{
Enum eColors{
Black(5),
BLUE(10),
GREEN(15);
Int colorCode=0;
eColors(int colorCode){
this.colorCode=colorCode;
}
};
Public static void main(String args[]){
System.out.println(eColors.values()[1].colorCode);
}
}
What will be the output?

ANS: 10

In BufferedOutStream, the method finalize is inherited from:
ANS: java.lang.Object

Subclass of Outputstreamwriter is _ _ _ -
ANS: FileWriter

LIKE operator is used for pattern matching?
Ans: true

Which of the following is FALSE Regarding String methods?
ANS:  Object equals(object another) (bcz equals returns Boolean)

If a statement tries to divide by zero which exception is thrown?
ANS: ArithmeticException

Java.io.FileOutputStream extends from which class?
ANS: java.io.OutputStream


Which of the following is not true in case of an interface?
i.                    Interface cannot be instantiated
ii.                  All methods in interface are abstract
iii.                An interface can inherit multiple interfaces are abstract
iv.                 An interface contains instance fields
ANS:  I, ii, iii are correct

public class Test1{
                                public static void main(String[]args){
                                    int i=1;
                                    do{
                                                i++;
                                    }while(i<10);
                                                System.out.println(i);
                                }
}
ANS: 10

Using mail API we cannot send mail from a servlet?
ANS:  false

Which statement will return true if atleast one condition is true?
ANS: (condition1 | | condition2)

Public static void main(String args[])
{
Int acsii[] = {65,66,67,68};
String s  = new String(ascii,1,3);
System.out.println(s);
}
}
ANS: BCD

What will be the output of the below program?
Public class Test{
Public static void main(String[] args){
String value = “abc”;
changeValue(value);
System.out.println(value);
}
Public static void changeValue(String a){
A=”xyz”;
}
}
ANS: abc

Byte Stream Classes support input/output operations on _ _ _ _ bytes:
ANS: 8 bit byte

Public static void main(String args[]){
Int I,j,k,l=0;
K=l++;
J=++k;
I=j++;
System.out.println(i);
}
}
ANS: 1

The close method of BufferedInputStream accepts parameters.
ANS: false

The relational model is based on the concept that data is organized and stored in two-dimensional tables called _ _ _
ANS: Relations

Objects are stored on stack
ANS: false

What stream type provides input from a disk file?
ANS: FileReader

Read() method of FileInputStream returns -1 when end of the file is reached
ANS: TRUE

Public class Test1{
Public static void main(String args[]){
Try{
Int answer =20/0;
}
Catch(ArithmeticException e){
//some code
}
Catch(Exception e){
//some code}
Catch(NullPointerEception e){
//some code
}
}
Select one or more true statements for above code
ANS: we will get unreachable catch block for NullPointerException, as it is already handled by the catch block for Exception

public class TestDemo{
                                public static void main(String[] args){
                                    TestDemo testObj = new TestDemo();
                                    testObj.start();
                                }
                                void start()
                                {
                                    long[] a1 = {3,4,5};
                                    long[] a2 = fix(a1);
                                    System.oit.print(a1[0]+a1[2]+"");
                                    System.out.println(a2[0]+a2[1]+a2[2]);
                                }
                                Long[] fix(long[] a3){
                                    A3[1] = 7;
                                    Return a3;
                                }
}
ANS:  15 15

What Is the main difference between the JRE and the JDK?
ANS:  The JRE includes the virtual machine


One class has an attribute which refers to another class. The relationship will be termed as _ _ _ _
ANS: Asscociation


Public class Test1{
                                Public static void main(String args[]){
                                    Try{
                                                Int answer =20/0;
                                    }
                                    /** Enter code here line 6 **/
                                    }
                                }what code can we enter at line 6? Select all that apply.
ANS: ALL the above


class Demo{
                                public static void main(String[]args){
                                    String s1=new String("hello");
                                    String s2=new String("hellow");
                                    System.out.println(s1=s2);
                                }
} What would be the output of the code mentioned above?
ANS: hellow

What is the return type of readBoolean() in DataInputstream?
ANS: Boolean

Which of the following statements are true?
ANS: Unicode characters are all 16-bits.

String Objects are mutable objects?
ANS: FALSE

_ _ _ _ _ class is called as the super class of all classes
Ans: java.lang.Object

The StreamReader can use the platform default encoding only
Ans: false                       

Is readBoolean() method of DataInputStream final?
ANS: True

What is used by executables to locate class files?
ANS: Class Path

Which of these ways used to communicate from an applet to servlet?
ANS: All mentioned above( RMI Communication, HTTP Communication, Socket Communication )

Every statement in java programming language ends wih
ANS: semicolon




public class Exam1{
                                public static void main(String[] args){
                                    int arr[] = new int[-3];
                                    for(int i=0;i<arr.length;i++){
                                                System.out.println(arr[i]);
                                    }
                                }
}
ANS: NegativeArrayException RuntimeError

Which of the following is true?
Ans: all of the above ( Enum in java a data type, Enum can have fields, constructors and methods, enum may implement many interfaces but cannot extend any class because it internally Enum class)

 On UPDATE CASCADE ensure which of the following?
ANS: Data integrity

A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer he input and to support thre mark and reset methods. True/False?
ANS: TRUE

If parent class method is public, Child class can override the method if visibility of the method is _ _ __
ANS: only public

Enum can extend other Enum
ANS: False

Which of these class is not related to input and output stream in terms of functioning?
ANS: File

Available() method throws IOException
ANS: True

public class Test{
                                public static void main(String[] args){
                                    try{
                                                throw new Exception();
                                    }catch(Exception e){
                                                System.out.println("Hello");
                                    }finally{
                                                System.out.println("No Error");
                                    }
                                   
                                }
}
ANS: Hello No Error

How many servlet context is available for an application
ANS: 1.0

Which of these classes can return more than one character to be input stream
ANS:  PushbachReader

_ _ _ _ are declare in a class, but outside method, constructor or any block.
ANS: Instance variables

What is the return type of readLine() method in Bufferedreader class?
ANS:  String

public class test{
                                public static void main(String[] args){
                                    int numValue = 5;
                                    System.out.println(++numValue);
                                    System.out.println(numValue++);
                                }
}

ANS: 6,6

Public InputSreamReader(InputStream in, String enc) throws _ _ _ _
ANS: UnsupportedEncodingException

Binary numbers need more places for counting because
ANS: Binary base is small

The parameter of the PreparedStatement object are _ _ _ _ when the user clicks on the Query button.
ANS: Initilized

Create domain YearlySalary numeric(8.2) constraint salary value test _ _ _ _; In order to ensure that an instructor’s salary domain allows only values greater than specified alue use:
ANS: check(value >= 29000.00)

Wallet has money but money doesn’t need to have Wallet necessarily. Which class relationship better explains this scenario?
ANS: Aggregation
The SELECT command, with its various clauses, allows users to query the data contained in the tables and ask many different questions or ad hoc queries.
ANS: True

JDBC is a _ _ _ _ interface, which means that it is used to invoke SQL commands directly
ANS: low-level

public class precedence{
                                public static void main(String[] args){
                                    int i = 0;
                                    i= i++;
                                    i= i++;
                                    i= i++;
                                    i= i++;
                                    System.out.println("The value of is"+i);
                                    int arr[] = new int[5];
                                    int index = 0;
                                    arr[index] = index = 3;
                                    System.out.println("The value of first element is"+arr[0]);
                                    System.out.println("The value of fourth element is"+ arr[3]);
                                }
}
ANS: all of the above
The value of i is 0
The value of first element is 3
The value of fourth element is 0

Which of the following has child class?
ANS: FilterReader

Which of these operator is used to allocate memory to array variable in java
ANS: new

What are the key elements of Problem Solving?
ANS:  ALL of these ( declarative & Imperative Knowledge, Good analytical Skills)

public class Exam1{
                                public static void main(String[] args){
                                    int a=5;
                                    int b=2;
                                    int c=a-b;
                                    if(c=3){
                                                System.out.println("Thats correct");
                                    }else{
                                                System.out.println("thats worng");
                                    }
                                }
}
ANS: Compile error

JRE stands for java _ _ _Environment
ANS: Runtime

Which statement is true?
1.      Serialization applies only to OBJECTS
2.      Static variables are NEVER saved as part of the objet state.So static variables are not Serializable.
ANS: Both statements 1&2

Issuing commit command does which of the following
ANS: Release all savepoints

Which of the following is the weakest relationship
ANS: Dependecy

Which of these contain heterogenous objects
ANS: ArrayList

How many parameter does readBoolean() of DataInputStream accepts?
Ans: 0

Which is not method of InputStreamReader
ANS: open()

For a static field, regardless of the number instances created, will hold the same data across all objects
ANS: TRUE

Single line comment starts with _ _ _ in java
ANS: //

What is the name of the stream that connects two running programs?
ANS: Pipe

Hotspot is an implementation of the JVM concept.It provides
ANS: garbage collector


Which method returns the time when the session was created?
ANS: getCreateTime()

public class precedence{
                                public static void main(String[] args){
                                int num = 10;
                                switch(num){
                                    case 8: System.out.println("The selection is 9");
                                    break;
                                    case 20: System.out.println("The selection is 20");
                                    break;
                                    case 30: System.out.println("The selection is 30");
                                    break;
                                    case 40: System.out.println("The selection is 40");
                                    break;
                                    default: System.out.println("Invalid Selection");
                                }
                                }
}
ANS: Invalid selection

To execute a stored procedure <??totalStock>?? in a database server, which of the following code snippet is used?
ANS: CallableStatement clbstmnt = con.prepareCall("{call totalStock}"); cs.executeQuery();

What class is extended by DataOutputStream class?
ANS: FilterOutputStream

Which of these class is used to read and write bytes in a file
ANS: FileInputStream

Evaluate the following command:
CREATE TABLE employees(employee_id NUMBER(2) PRIMARY KEY, last_name VARCHAR2(25) NOT NULL, department_id NUMBER(2), job_id VARCHAR2(8), salary NUMBER(10,2));

You issue the following command to create a view that displays the last names of the sales staff in the organization:
CREATE OR REPLACE VIEW sales_staff_vu AS SELECT employee_id, last_name,job_id FROM employees WHERE job_id LIKE ‘SA_%’ WITH CHECK OPTION;
Which two statements are true regarding the above view? (Choose two.)
A. It allows you to insert rows into the EMPLOYEES table .
B. It allows you to delete details of the existing sales staff from the EMPLOYEES table.
C. It allows you to update job IDs of the existing sales staff to any other job ID in the EMPLOYEES table.
D. It allows you to insert IDs, last names, and job IDs of the sales staff from the view if it is used in multitable INSERT statements.
ANS: B,D
What type of exception can all the function of DataInputStream throws?
ANS: IOException
BufferedWriter class Extends_ _ _ _
ANS: Writer

Why we use array as a parameter of main method
ANS: both of the above( for taking input to the main method, can store multiple values)

public class Exam1{
                                public static void main(String[] args){
                                for(int j=0;j<3;j++){
                                    for(int i=0;i<3;i++){
                                                if(i<2){
                                                            break;
                                                }
                                    }
                                    System.out.println("i="+i);
                                    System.out.println("j="+j);
                                }
                                }
}
ANS: Compile time error

Which of these keywords is used to refer to member of base class from a sub class?
ANS: super

Which of these method of String class is used to obtain character at specified index?
ANS: charAt()

In BufferedOutputStream, the method wait is inherited from:
ANS: java.lang.Object


Close() method closes this input stream and releases any system resources associated with the stream
ANS: YES

The _  _ _ _ method sets the query parameters of the PreparedStatement Object.
ANS: setString()

Which command deletes all information about relation from the database?
ANS: drop table

Java.io.FileInputStream extends from which class?
ANS: java.io.InputStream

Which servlet interface contain life cycle methods
ANS: Servlet

Find the SQL statement below that is equal to the following:
SELECT NAME FROM CUSTOMER WHERE STATE =’VA’;
ANSSELECT NAME FROM CUSTOMER WHERE STATE IN ('VA');
What interface is implemented by DataOutputStream class?
ANS: DataOutput

class output{
                                public static void main(String[] args){
                                String a = "hello i love java";
                                System.out.println(a.indexOf('i')+" "+a.indexOf('o')+" "+a.lastIndexOf('i')+" "+a.lastIndexOf('o'));
                                }
}
ANS: 6 4 6 9

The webserver that executes the servlet creates an _ _ _ _ and passes this to servlets service method(which inturn passes to doget and dopost)
ANS: HttpServlet


public class Sample
{
                                public static void main(String[] args){
                                int[] myArray = new int[3];
                                for(int x:myArray)
                                {
                                    System.out.print(x);
                                }
                                }
}

Ans: 000


Java platform consists of below components.
ANS: Java API, JVM


An InputStreamReader is a bridge from byte streams to ……………………streams.
ANS: Character


What can be appended to Writer class using append() ?
ANS: Character

When you create a FileOutputStream you can decide if you want to overwrite any existing file with the same name, or if you want to append to any existing file.
ANS: True

Reader class is a final class ?
ANS: False

What command is used to compile a Java program eg. Test.java
ANS: javac Test.java

Which method of Writer class is not implemented by subclass ?
ANS: read()

What value does readLine() return upon encountering end-of-file ?
ANS:  null

Can a stream act as a data source for another stream?
ANS:  Yes. Some streams can be connected together.

What is a stream that transforms data in some way called ?
ANS: Processing stream

SELECT * FROM Table1 HAVING Column1 > 10
ANS: The result will be all rows from Table 1 which have Column1 values greater than 10.

Which of the following invokes function in SQL
ANS: Callable statements

The equals method only takes Java objects as an argument , and not primitives, passing primitives will result in a compile time error.
ANS: True

Which of these keywords is not a part of Java exception handling ?
ANS: thrown

A floppy disk contains
ANS: Both circular tracks and sector


public class StringComp{
                       public static void main(String[] args){
                      
                       String s1= "rahul";
                       String s2= "rahul";
                       String s3= new String("459029");
                       String s4= new String("459029");
                       System.out.print(s1.equals(s2));
                       System.out.print((s1==s2));
                       System.out.print(s3.equals(s4));
                       System.out.print((s3==s4));
                      
                      
                       }
}
ANS: true true true false


In BufferedReader what method is used to notify the operating system that a file is no longer needed ?
ANS: close()

In Servlet Terminology what provides rentime environment for JavaEE(j2ee) applications. It performs many operations that are given below: 1. Life Cycle Management 2.Multithreaded support 3. Object Pooling 4.Security etc
ANS: Container

The DTD defines the structure of XML documents
ANS: True

Choose the incorrect one among the following choices:
ANS: List<int> I = new ArrayList<int>();

Select the equivalent answers for the code given below ?

Boolean b=true;
If(b){
x=y;
}else
{ x=z;}
                                            
ANS: x=b ? x=y : x=z;

Which one of the following will declare an array and initialize it with five numbers
ANS: int [] a={23,22,21,20,19};

Which statement about HttpSession is not true ?
ANS: A session will become invalid as soon as the user close all the browser window


What are the methods declared by the Iterators
ANS: All of the above  [ Boolean hasNext(), Object next(), void remove();

…………….. are the list of arguments that come into function.
ANS: Parameters

public class Test{
                                             public static void main(String[] args){
                                             display(null);
                                             }
                                             private static void display(String str)
                                             {
                                                if(str==null)
                                                            throw new NullPointerException();
                                                else
                                                            System.out.println("String is :"+str);   }
}
ANS: Null Pointer exception will occur if the program is run.



CREATE TABLE product
(pcode NUMBER(2),
pnameVARCHAR2(10));
INSERT INTO product VALUES(1, 'pen');
INSERT INTO product VALUES (2,'penci');
SAVEPOINT a;
UPDATE product SET pcode = 10 WHERE pcode = 1;
SAVEPOINT b;
DELETE FROM product WHERE pcode = 2;
COMMIT;
DELETE FROM product WHERE pcode=10;
ROLLBACK TO SAVEPOINT a;
ANS: Both the DELETE statements and the UPDATE statement would be rolled back




CREATE TABLE CUSTOMER(customerid NUMBER(3,2),customername VARCHAR2(10));
INSERT INTO CUSTOMER VALUES(1,’a’);
ALTER TABLE CUSTOMER ADD constraint chk_lenght_5 CHECK (length(customername)>5);
ANS: It will add the constraints to check that customername should have minimum 5 characters

The_ _ __ __ _ __ method executes a simple query and returns a single Result Set object.
ANS: executeQuery
How many constructors are there in DataInputStream class?
ANS: 1
public class precedence{
            public static void main(String[] args){
           
            StringBuffer stb = new StringBuffer("yadroh");
            // line4 //
            System.out.println(stb.toString());
            }
}
ANS: stb.replace(3,4,”li”).reverse();

You need to create a table for a banking application with the following considerations:
1.      You want a column in the table to store the duration of the credit period
2.      The data in the column should be stored in a format such that it can be easily added and substracted with
3.      Data type data without using the conversation functions
4.      The maximum period of the credit provision in the application is 30 days
5.      The interest has to be calculated for the number of days an individual has taken a credit for.
Which  data type would you use for such a column in the table?
ANS: INTERAL DAY TO SECOND


Which of these method of InputStream is used to read integer representation of next available byte input?
Ans: read()

FileWriting class ___ from the InputStreamWiter class
ANS: inherits

Which method is not present in HttpServlet class
Ans: service

JDK consists of
ANS: all of the above(tools for development, JRE, JVM)

How many copies of a JSP page can be in memory at a time?
ANS: one


If the client has disabled cookie in the browser, which session management mechanism could the web container employ?
ANS: Session Management using URL Rewriting

class Super{
            void show(){
                        System.out.println("parent");
            }
}
public class Sub extends Super{
            void show()throws IOException{
                        System.out.println("Child");
            }
            public static void main(String[]args){
                        Super s = new Sub();
                        s.show();
            }
}
ANS: compile error

StringBuffer Objects are mutable objects?
ANS: True


public class Operators1{
            public static void main(String[]args){
                        double x=6;
                        int y=5,z=2;
                        x=y++ + ++x/z;
                        System.out.println(x);
            }
}
ANS: 8.5

Automatically when the view is dropped.
E. The OR REPLACE option is used to change the definition of an existing view without dropping and recreating it.
F. The WITH CHECK OPTION constraint can be used in a view definition to restrict the columns displayed through the view.

Which of the following must be true of the object thrown by a thrown statement?
ANSIt must be assignable to the Throwable type

What will this code print?
Int arr[] = new int[5];
System.out.print(arr);
ANS: Garbage Value

What does read(char[] cbuf, int off, int len) of InputStreamreader do?
ANS: Reads characters into a portion of an array

The default initial values of the data members in Employee class for string name and int id are
ANS: null, 0

Which class handle any type of request so it is protocol-independent?
ANS: GenericServlet

Java is a_ _ __ independent language.
Ans: Platform

 What is the return type of skipByte() func in DataInputStream class?
ANS: int

Aceess modifier can beused for local variables
Ans: false


Which of the following languages is more suited to a structured program?
Ans: Pascal

What is the limit of data to be passed from HTML when doGet() method is used?
ANS: 2k

Switch(x){
Default: System.out.println(“Hello”);
}
Which two are acceptable types of for x?
1.      byte
2.      long
3.      char
4.      float
5.      Short
6.      Long
ANS: 1 and 3

For a 2 tier architecture
1.      Presentation layer in one machine and Business & Resource layer is available in different machine.
2.      Presentation & Business layer in one machine and Resource layer in another machine. Which of the below statements Is true.
ANS: Both statements are true

An Input device which can read characters directly from an ordinary piece of paper is
Ans: OCR

parseInt() and parseLong() method throws__ ___  _ _ _ ?
Ans: NumberFormatException

To explicitly throw an exception, _ _ _ _ keyword is used.
Ans: throw

How many parameters does the skipByte() accept in DataInputStream class?
Ans: 1

Is the skipByte() of DataInputStream final
Ans: false




Public class Exam1{
Private int a;
Public static void main(Strings[]arg){
/* complete the code using the options so that O is printed in console*/
}           }
ANS: System.out.println(new Exam1().a);
class AccountHolder{
            public AccountHolder(int count){
                       
            }
}
class Account{
            Account(){
                       
            }
}
class Demo{
            public static void main(String[]args){
                        AccountHolder accountholder;
                        accountholder = new AccountHolder();
                        Account accountOne = new Account();
                        Account accountTwo = new Account();
                        Account accountThree = accountTwo;
                        accountThree = accountOne;            
            }
}           while executing the above code, how many reference variable and objects will be crrated
Ans: 3 Objects and 4 references

InputStream class has one constructor.
Ans: True

Java has the characteristic
Ans: All of the above( Portable, Robust, Architecture neutral)

A deployment descriptor describes
Ans: web component settings

What data type does readLine() return?
Ans: String

Which among the following is wrong?
Ans: abstract class can have only static final(constant) variable i.e, by default

What is the result of x when the following loop exists?
Int x=0;
For(in i=0;i<10;i++){
if(i==5){
Continue; }
X++;
}
Ans: 9

String s =”kolkatta”.replace(‘k’,’a’) ?
What would the string “s” would contain after successful execution of the above statement?
Ans: aolaata

The below query returns the students whose age is between 20 to 24 including 20 and 24 also. Select * from Student where Age BETWEEN 20 AND 24
Ans: TRUE

Which life cycle method is called only once in the serbvlet life cycle
Ans: init()

No comments:

Post a Comment