Introduction To Java
Introduction To Java
1.Introduction to java
1.Who invented Java language?
A) Dennis Ritchie
B) James Gosling
C) Larry Page
D) Serge Page
Ans:B
A. Microsoft
B. Mozilla Corporation
C. Sun Microsystems
D. Amazon Inc.
Ans : C
A. Eclipse
B. OAK
C. Netbean
D. D
Ans : B
A. James Gosling
B. Larry Page
C. Bjarne Stroustrup
D. None of these
Ans a.
A. because the language was unsuccessful , so they created another version and changed its name
to java.
B. because the name was not relevant to the language they created
C. because there was another language called Oak
D. None of these
Ans : C
A. 25-05-1995
B. 27-05-1995
C. 29-05-1995
D. 28-05-1995
Ans : B
A. Object Oriented
B. Procedural
C. Event Driven
D. None of these
Ans : A
Ans : B
A. high-level
B. Middle-level
C. Low-level
D. None of the above
Ans : A
4
A. Java is Simple
B. Java is Secure
C. Java is Portable
D. All of the above
Ans : D
16.What type of Java Programs can be run inside a Java supported Web Browser?
A) Stand alone
B) Struts
C) Applets
D) AWT
Ans C
Ans.D
18. What was the reason for huge initial success of Java?
A) WWW (World Wide Web)
B) Smart TV Evolution
C) Smart Home Automation
D) None of the above
Ans. A
19.In which year, Sun Microsystems released much of its Java virtual machine?
A. 2005
B. 2006
C. 2007
D. 2008
Ans : B
5
20. What is the advantage of EXE files?
A) Run Faster
B) Efficient
C) No separate program required to run
D) All the above
Ans.D
21. Computer Viruses and Trojans are often transmitted along with which files?
A) JPG files
B) TXT files
C) EXE files
D) .ICO files
Ans.C
A. Internet development
B. Search Engine Development
C. Desktop Development
D. Operating System Development
Ans : A
A. Java 1.2
B. Java 1.0
C. Java 1.1
D. Java Premium 1.0
Ans : B
24. Basic aim of java was to solve the problem of connecting many household machines
together.
Ans : D
6
25.What is the problem with generation Executable Software (EXE files)?
A) Run only on Windows machines.
B) Linux and Unix expect a different executable format than .EXE
C) Compiler for each machine type like Linux, Unix, Windows and Processor Type needs to be
built for generating output files that can run.
D) All the above.
Ans.D
26. Sun Microsystems released the first public implementation as Java 1.0 in?
A. 1994
B. 1995
C. 1996
D. 1997
Ans : C
Ans : D
A. .Obj
B. Source Code
C. Bytecode
D. .Exe
Ans : C
7
A. Java 4.0
B. Java 8.0
C. Java 5.0
D. Java 6.0
View Answer
Ans : C
30. Which of the following is used to interpret and execute Java Applet Classes hosted by
HTML.
A. appletviewer
B. appletwatcher
C. appletshow
D. appletscreen
Ans : A
31. HTML based Java Documentary help can be accessed using ______________.
A. javahelp
B. javamanual
C. javadoc
D. None of these
Ans : C
Ans.C
A. /**
B. //
C. /*
D. None of these
Ans : B
A. javac filename.java
B. java filename.java
C. javac filename
D. java filename
Ans : A
A. javac filename.java
B. java filename.java
C. javac filename
D. java filename
Ans : D
A. True
B. False
C. Depends On Complier
D. May be true or false
Ans : A
10
43.What is true in Java?
A. For all class names the first letter should be in Upper Case.
B. All method names should start with a Lower Case letter.
C. Name of the program file should exactly match the class name.
D. All of the above
View Answer
Ans : D
Answer: b
Answer: a
1. int w = (int)888.8;
2. byte x = (byte)100L;
3. long y = (byte)100;
4. byte z = (byte)100L;
a) 1 and 2
b) 2 and 3
c) 3 and 4
d) All statements are correct
Answer: d
47. An expression involving byte, int, and literal numbers is promoted to which of these?
a) int
b) long
c) byte
d) float
Ans:A
11
48. Which of these literals can be contained in float data type variable?
a) -1.7e+308
b) -3.4e+038
c) +1.7e+308
d) -3.4e+050
Ans : B
Explanation: Range of float data type is -(3.4e38) To +(3.4e38)
49. Which data type value is returned by all transcendental math functions?
a) int
b) float
c) double
d) long
ans:c
1. class average {
2. public static void main(String args[])
3. {
4. double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};
5. double result;
6. result = 0;
7. for (int i = 0; i < 6; ++i)
8. result = result + num[i];
9. System.out.print(result/6);
10.
11. }
12. }
a)16.34
b) 16.566666644
c) 16.46666666666667
d) 16.46666666666666
ans:c
1. class output {
2. public static void main(String args[])
3. {
4. double a, b,c;
5. a = 3.0/0;
6. b = 0/4.0;
7. c=0/0.0;
8.
9. System.out.println(a);
10. System.out.println(b);
12
11. System.out.println(c);
12. }
13. }
a) Infinity
b) 0.0
c) NaN
d) all of the mentioned
ans:d
1. class increment {
2. public static void main(String args[])
3. {
4. int g = 3;
5. System.out.print(++g * 8);
6. }
7. }
a)25
b) 24
c) 32
d) 33
ans:c
1. class area {
2. public static void main(String args[])
3. {
4. double r, pi, a;
5. r = 9.8;
6. pi = 3.14;
7. a = pi * r * r;
8. System.out.println(a);
9. }
10. }
a) 301.5656
b) 301
c) 301.56
d) 301.56560000
Ans:a
13
54. What is the numerical range of a char data type in Java?
a) -128 to 127
b) 0 to 256
c) 0 to 32767
d) 0 to 65535
Ans: d
55. Which of these coding types is used for data type characters in Java?
a) ASCII
b) ISO-LATIN-1
c) UNICODE
d) None of the mentioned
Ans:c
57. Which of these occupy first 0 to 127 in Unicode character set used for characters in Java?
a) ASCII
b) ISO-LATIN-1
c) None of the mentioned
d) ASCII and ISO-LATIN1
Ans:d
Ans:b
14
1. class array_output {
2. public static void main(String args[])
3. {
4. char array_variable [] = new char[10];
5. for (int i = 0; i < 10; ++i) {
6. array_variable[i] = 'i';
7. System.out.print(array_variable[i] + "" );
8. i++;
9. }
10. }
11. }
a) i i i i i
b) 0 1 2 3 4
c) i j k l m
d) None of the mentioned
Ans:a
1. class mainclass {
2. public static void main(String args[])
3. {
4. char a = 'A';
5. a++;
6. System.out.print((int)a);
7. }
8. }
a) 66
b) 67
c) 65
d) 64
Ans:a
1. class mainclass {
2. public static void main(String args[])
3. {
15
4. boolean var1 = true;
5. boolean var2 = false;
6. if (var1)
7. System.out.println(var1);
8. else
9. System.out.println(var2);
10. }
11. }
a) 0
b) 1
c) true
d) false
Ans:c
1. class booloperators {
2. public static void main(String args[])
3. {
4. boolean var1 = true;
5. boolean var2 = false;
6. System.out.println((var1 & var2));
7. }
8. }
a) 0
b) 1
c) true
d) false
Ans:d
1. class asciicodes {
2. public static void main(String args[])
3. {
4. char var1 = 'A';
5. char var2 = 'a';
6. System.out.println((int)var1 + " " + (int)var2);
7. }
8. }
a) 162
b) 65 97
c) 67 95
d) 66 98
16
Ans:b
Ans:a
Ans:b
1. enum Season
2. {
3. WINTER, SPRING, SUMMER, FALL
4. };
5. System.out.println(Season.WINTER.ordinal());
a) 0
b) 1
c) 2
d) 3
Ans:a
68. If we try to add Enum constants to a TreeSet, what sorting order will it use?
a) Sorted in the order of declaration of Enums
b) Sorted in alphabetical order of Enums
c) Sorted based on order() method
d) Sorted in descending order of names of Enums
Ans:a
69. What will be the output of the following Java code snippet?
17
1. class A
2. {
3.
4. }
5.
6. enum Enums extends A
7. {
8. ABC, BCD, CDE, DEF;
9. }
a) Runtime Error
b) Compilation Error
c) It runs successfully
d) EnumNotDefined Exception
Ans:b
70. What will be the output of the following Java code snippet?
1. enum Levels
2. {
3. private TOP,
4.
5. public MEDIUM,
6.
7. protected BOTTOM;
8. }
a) Runtime Error
b) EnumNotDefined Exception
c) It runs successfully
d) Compilation Error
Ans:d
71. What will be the output of the following Java code snippet?
1. enum Enums
2. {
3. A, B, C;
4.
5. private Enums()
6. {
7. System.out.println(10);
8. }
9. }
10.
11. public class MainClass
12. {
13. public static void main(String[] args)
14. {
15. Enum en = Enums.B;
18
16. }
17. }
a)
10
10
10
b) Compilation Error
c)
10
10
d) Runtime Exception
Ans:a
Ans:c
Ans:a
Ans:d
74. Which of the below data type doesn’t support overloaded methods for +,-,* and /?
a) int
b) float
c) double
d) BigDecimal
Ans:d
19
75. What will be the output of the following Java code snippet?
1. double a = 0.02;
2. double b = 0.03;
3. double c = b - a;
4. System.out.println(c);
5.
6. BigDecimal _a = new BigDecimal("0.02");
7. BigDecimal _b = new BigDecimal("0.03");
8. BigDecimal _c = b.subtract(_a);
9. System.out.println(_c);
a)
0.009999999999999998
0.01
b)
0.01
0.009999999999999998
c)
0.01
0.01
d)
0.009999999999999998
0.009999999999999998
Ans:a
81. Which class is a library of functions to perform arithmetic operations of BigInteger and BigDecimal?
a) MathContext
b) MathLib
c) BigLib
d) BigContext
Ans:a
82. What will be the output of the following Java code snippet?
a) Compilation failure
b)
21
Add: 473.66
Add using MathContext: 4.7E+2
c)
Add 4.7E+2
Add using MathContext: 473.66
d) Runtime exception
Ans:b
b)
c)
d)
Ans:b
c)
d)
ANS:a
Ans:c
Ans:c
96. Which of these can not be used for a variable name in Java?
a) identifier
b) keyword
24
c) identifier & keyword
d) none of the mentioned
Ans:b
1. class evaluate
2. {
3. public static void main(String args[])
4. {
5. int a[] = {1,2,3,4,5};
6. int d[] = a;
7. int sum = 0;
8. for (int j = 0; j < 3; ++j)
9. sum += (a[j] * d[j + 1]) + (a[j + 1] * d[j]);
10. System.out.println(sum);
11. }
12. }
a) 38
b) 39
c) 40
d) 41
Ans:c
1. class array_output
2. {
3. public static void main(String args[])
4. {
5. int array_variable [] = new int[10];
6. for (int i = 0; i < 10; ++i) {
7. array_variable[i] = i/2;
8. array_variable[i]++;
9. System.out.print(array_variable[i] + " ");
10. i++;
11. }
12.
13. }
14. }
a) 0 2 4 6 8
b) 1 2 3 4 5
c) 0 1 2 3 4 5 6 7 8 9
d) 1 2 3 4 5 6 7 8 9 10
25
Ans:b
1. class variable_scope
2. {
3. public static void main(String args[])
4. {
5. int x;
6. x = 5;
7. {
8. int y = 6;
9. System.out.print(x + " " + y);
10. }
11. System.out.println(x + " " + y);
12. }
13. }
a) 5 6 5 6
b) 5 6 5
c) Runtime error
d) Compilation error
Ans:d
Ans:d
101.
26