Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

Friday, December 30, 2016

Use predefined class as identifiers in JAVA

E. In java application, we are able to use all predefined class names & interface names as identifiers.

EX: 1
int Exception= 10;
System.out.println(Exception);

Status: No compilation error
Output: 10

Note: Here Exception is an int variable.
---------------

EX: 2
String String = "String";
System.out.println(String);

Status: No compilation Error.
Output: String

Note: Here First String is as String class, 2nd String as a variable, 3rd String as value of variable.
--------------

EX: 3
int System = 10;
System.out.println(System);

Status: Compilation Error.
Reason: In java application , if we declare "System" as an integer variable then in the remaining program, we must use that System as integer variable only, we must not use that System as original class name, if we use "System" as original class name then compiler will rise an error.

In the above context if wi want to use System as class name, then we have to use its "fully qualified name" providing class name along their package name is called as "Fully qualified name".

EX:
class Test
{
public static void main(String[] args)
{
int System = 10;
java.lang.System.out.println(System);
System=System + 10;
java.lang.System.out.println(System);
}
}

Status: No compilation error
Output:
10
20
---------------------------

Along with the above rules & regulations, JAVA has provided the following suggestiong to use identifiers in JAVA application:

1. It is suggestible to provide identifier with a particular meaning.
EX:
String aa = "abc123"; ---------> Not Suggestible
String accNo = "abc123"; ------> Suggestible

2. In Java Application, there is no length restriction for the identifiers, but, it is suggestible to manage length of the identifier around 10 symbols.
EX: 
String temporaryemployeeaddress = "Hyd"; -------> Not Suggestible
String tempEmpAddr = "Hyd"; --------------------> Suggestible

3. If we have multiple words with in a single identifier then it is suggestible to separate multiple words with special notation like '-' symbol.
EX:
String tempEmpAddr = "Hyd"; -----> Not Suggestible
String temp_Emp_Addr = "Hyd"; ---> Suggestible

You May Also Like --> Classes Vs Interference 

Thursday, December 29, 2016

Naming Rules: in oracle dbms

Naming Rules:

-----------------------------------------------

1. Each name should begun with alphabetic character.

2. Void character set is a-z, A-Z, 0-9, @, #, $, _ used but first name should be a letter.

3. Names are not case sensitive.

4. Spaces not allowed within the name.

5. Duplicate names are not allowed.

6. Reserved words not allowed as names.

7. Maximum length of a name is 30 character length.

EX:

 Valid   | Invalid
emp_dtls   | emp-dtls
emp123   | 123emp
pdod#info | prod.detls
table123   |      table
--------------------------

Wednesday, December 28, 2016

Tokens in language fundamentals in oracle dbms

1. Tokens: 

Any logical unit in java programming is called as Lexeme.

The collection of Lexeme come under a particular group called as "Tokens".
Lexeme and tokens



Q. Find the no of lexemes & tokens in following expression?
int a = b + c *d;

Ans: int,a,=,b,=,+,*,d,; --------> 9 lexeme
int ----------------> data type
a,b,c,d ------------> Variables
=,+,* --------------> operator
; ------------------> special symbol/ terminator

Tokens ---------------> 4 types of token.
------------------------------------------------------------------------------------------

To prepare java application, java has provided the following tokens:
1. Identifiers
2. Literals
3. Keywords/reserved words
4. operators

1. Identifiers:

-------------------
Identifier is a name provided to the programming elements like variables, methods, classes, interfaces.....

To provide identifiers in java program, java has provided the following rules & regulations.

A. Identifiers must not be started with a number, Identifiers may start with an alphabet, _ symbol, $          symbol but subsequent symbols may be a number, an alphabet, _ symbol, $ symbol.

EX: String 9eid = "err";----------------> invalid
String eid = "err-1";---------------> valid
String emp9Id = "err891";---------------> valid
float $esal =   6932145f;---------------> valid
String _eaddr = "Hyd";---------------> valid
String emp_Name = "bali";---------------> valid
--------------

B. Identifiers are not allowing all operators & all special symbol except _ and $ symbol.
EX: String emp.Name = "bali" ----------> invalid
String emp-Name = "bali" ----------> invalid
String emp_Name = "bali" ----------> valid
String emp$Name = "bali" ----------> valid
String emp+Name = "bali" ----------> invalid
String emp@Name = "bali" ----------> invalid
String _$_emp_$_$_Name = "bali" ----------> valid
---------------------------

C. Identifiers are not allowing spaces in the middle.
EX: forName(--); ---------> Valid
for Name(--); ---------> invalid
getInputStream(-); ----> valid
get Input Stream (-); ------> Invalid
---------------------

D. Identifiers must not be duplicated within the same scope, identifiers may be duplicated in two             different scopes.
EX:
class A
{
int i = 10;
short i = 20;-------->error
boolean f = true;
void m1()
{
float f = 23.4f -----> no error
double f = 2850; -----> error
long i = 20; ---------> no error
System.out.println(i); ------> print local variable
System.out.println(this.i); -----> print class level variable
}
}

Monday, December 26, 2016

How to install java part-4

6. Execute JAVA program:

------------------------------------------------------------------------------------------------------------
To execute java program, we have to use the following command or command prompt at the location where main class .class file is existed.
Java Main_Class_Name

EX: D:\java10>java FirstApp

If we provide the above command on command prompt then operating system will identify “java” command at “C:\java\jdk1.7.0_79\bin”, through path environment variable, JVM will execute “java” command, with this, JVM Software will be activated and JVM will perform the following actions:

A. JVM will take main class name from command prompt.
B. JVM will search for main class .class file at 3 locations:
i. current location,
ii. at java predefined library and
iii. at the location referred by “class path” environment variable.
C. If the required main class .class file is not identified at all the above locations then JVM will provide the following:

JAVA6: java.lang.NoClassDefFoundError: FirstApp
JAVA7: Error: Could not find or local main class: FirstApp

Note: if the required main class .class file is available at another location then to make available that .class file to JVM, we have to set “class path” environment variable.
D:\java10>set classpath = E:\abc;

D. If the required main class .class file is available at either of the above locations them JVM will load main class byte code to the memory.
E. After loading main class byte code to the memory, JVM will search for main() method at main class.
F. If the required main () method is not available then JVM will provide the following Exceptions.

JAVA6: java.lang.NoSuchMethodError: main
JAVA7: Error: Main method not found in class FirstApp, please defined the main method as:
            public static void main(String[] args)

G. If the required main() method is existed in main class the JVM will execute main() method by creating a thread called as “main thread”.

H. When Main thread reached to the ending point of main() method, Main thread will come Dead State, with this, JVM will terminate all of its internal processes and JVM will go to shutdown mode.

Friday, December 23, 2016

JAVA Interview Question

Q. 41
11. class Alpha {
12. public void foo() { System.out.print(“Afoo”); }
13. }
14. public class Beta extends Alpha {
15. public void foo() { System.out.print(“Bfoo”); }
16. public static void main(String[] args) {
17. Alpha a = new Beta();
18. Beta b = (Beta)a;
19. a.foo();  20. b.foo();
21. }
22. }
What is the result?
A. Afoo Afoo
B. Afoo Bfoo
C. Bfoo Afoo
D. Bfoo Bfoo
E. Compilation fails.
F. An exception is thrown at runtime.

Q. 42 Given:
7. void waitForSignal() {
8. Object obj = new Object();
9. synchronized(Thread.currentThreat()) {
10. obj.wait();
11. obj.notify();
12. }
13. }
Which statement is true?
A. This code may throw an interruptedException.
B. This code may throw an illegalstateException.
C. This code may throw a TimeoutException after ten minutes.
D. This code will not compile unless “obj.wait()” is replaced with “((Thread) obj).wait()”.
E. Reversing the order of obj.wait() and obj.notify() may cause this method to complete normally.
F. A call to notify() or notifyAll() from another thread may cause this method to complete normally.

Q, 43 Given:
1. public class TestSeven extends Thread {
2. private static int x;
3. public synchronized void doThings() {
4. int current = x;
5. current++;
6. x = current;
7. }
8. public void run() {
9. doThings();
10. }
11. }
Which statement is true?
A. Compilation fails.
B. An exception is thrown at runtime.
C. Synchronizing the run() method would make the class thread-safe.
D. The data in variable “x” are protected from concurrent access problems.
E. Declaring the doThings() method as static would make the class thread-safe.
F. Wrapping the statements within doThings() in a synchronized (new Object()) { } block would make the class thread-safe.

Q. 44 Given:
11. public void testIfA() {
12. if (testlfB(“True”)) {
13. System.out.println(“True”);
14. } else {
15. System.out.println(“Not True”);
16. }
17. }
18. public Boolean testlfB(String str) {
19. return Boolean.valueof(str);
20. }
What is the result when method testlfA is invoked?
A. True
B. Not True
C. An exception is thrown at runtime.
D. Compilation fails because of an error at line 12
E. Compilation fails because of an error at line 13.

Q.45 when comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in only one of the two?
A. closing the stream.
B. flushing the stream
C. writing to the Stream
D. marking a location in the stream
E. writing a line separator to the stream

46. The calendar for the year 2007 will be the same for the year.
A. 2014 B. 2016 c. 2017                  D. 2018

47. A man standing at a point P is watching the top of a tower, which makes an angle of elevation of 30 degree with the man’s eye. The man walks some distance towards the tower to watch its top and the angle of the elevation becomes 60 degree. What is the distance between the base of the tower and the point P?
A. 43 units           B. 8 units             C. 12 units           D. Data inadequate.

48. Two ships are sailing in the sea on the two sides of a lighthouse. The angle of elevation of the top of the lighthouse is observed from the ships are 30 degree and 45 degree respectively. If the lighthouse is 100 m high, the distance between the two ships is:
A. 173 m               B. 200 m               C. 273 m               D. 300 m

49. A and B take part in 100 m race. A runs at 5 kmph. A gives B a start of 8 m and still beats him by 8 seconds. The speed of B is:
A. 5.15 kmph      B. 4.14 kmph      C. 4.25 kmph      D. 4.4 kmph

50. In 100 m race, A covers the distance in 36 seconds and B in 45 seconds. In this race A beats B by:

A. 20 m                 B. 25m                  C. 22.5m               D. 9 m

Thursday, December 22, 2016

JAVA Interview Question 31-40

Q: 31 Given:
15. public class Yippee {
16. public static void main(String[] args) {
17. for (int x = 1; x < args.length; x++) {
18. System.out.print(args[x] + “ “);
19. }
20. }
21. }
and two separate command line invocations:
java Yippee
java Yippee 1 2 3 4

What is the result?
A. No output is produced.
1 2 3
B. No output is produced.
2 3 4
C. No output is produced.
1 2 3 4
D. An exception is thrown at runtime.
1 2 3
E. An exception is thrown at runtime.
2 3 4
F. An exception is thrown at runtime.
1 2 3 4

Q. 32 Given:

10. class Nav{
11. public enum Direction {NORTH, SOUTH, EAST, WEST}
12. }
13. public class Sprite {
14. // insert code here
15. }

Which code, inserted at line 14, allows the Sprite class to compile?
A. Direction d = NORTH;
B. Nav. Direction d = NORTH;
C. Direction d = Direction.NORTH;
D. Nav.Direction d = Nav.Direction.NORTH;

Q: 33 Given:
11. public class Ball{
12. public enum Color {RED, GREEN, BLUE};
13. public void fool(){
14. // insert code here
15. { System.out.println(c);}
16. }
17. }
Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?
A. for(Color c : Color.values() }
B. for(Color c = RED; c <= BLUE; c++)
C. for(Color c; c.hasNext(); c.next() )
D. for(Color c = Color[0]; c <= Color[2]; c++)
E. for(Color C = Color.RED; c <= Color.BLUE; c++)

Q. 34 Given:
3. public class Spock{
4. public static void main(String[] args){
5. Long tail = 2000L
6. Long distance = 1999L
7. Long story = 1000L
8. if((tail > distance) ^ ((story * 2) == tail))
9. System.out.print(“1”);
10. if((distance + 1 != tail) ^ ((story * 2) == distance))
11. System.out.print(“2”) ;
12. }
13. }
What is the result?
A. 1
B. 2
C. 12
D. Compilation fails.
E. No output is produced.
F. An exception is thrown at runtime.

Q. 35 Given:
25. int x = 12;
26. while (x<10) {
27. x--;
28. }
29. System.out.print(x);
What is the result?
A. 0
B. 10
C. 12
D. Line 29 will never be reached.

Q. 36 Given:
11. static void test() throws Error {
12. if (true) throw new AssertionError ();
13. System.out.print(“test”);
14. }
15. public static void main(String[] args) {
16. try(test); }
17. catch (Exception ex} {System.out.print(“exception”); }
18. System.out.print(“end”);
19. }
What is the result?
A. end
B. Compilation fails.
C. exception end.
D. exception test end
E. A Throwable is thrown by main.
F. An Exception is thrown by main.

Q. 37 Given:
33. try {
34. // some cade here
35. } catch (NullPointerException e1) {
36. System.out.print(“a”);
37. } catch (RuntimeException e2) {
38. System.out.print(“b”);
39. } finally {
40. System.out.print(“c”);
41. }
What is the result if a NullPointerException occurs on line 34?
A. c
B. a
C. ab
D. ac
E. bc
F. abc

Q. 38
Click the Exhibit Button.
1. public class Test {
2.
3. public static void main( String[] args) {
4. Boolean assert = true;
5. if(assert) {
6. System.out.println(“assert is true”);
7. }
8. }
9.
10. }
Given:
Javac –source 1.3 Test.java

What is the result?
A. Compilation fails.
B. Compilatin Succeeds with errors.
C. Compilation succeeds with warnings.
D. Compilation succeeds without warnings or errors.

Q. 39 Given:
11. public void genNumbers() {
12. ArrayList numbers = new ArrayList();
13. for (int i=0; I<10; i++) {
14. int value = i * ((int) Math.random());
15. integer intObj = new Integer(Value);
16. numbers.add(intObj);
17. }
18. System.out.println(numbers);
19. }

Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbage collection?
A. Line 16
B. Line 17
C. Line 18
D. Line 19
E. The object is NOT a candidate for garbage collection.

Q. 40 Given:
1. class SuperClass {
2. public A getA(){
3. return new A();
4. }
5. }
6. class SubClass extends SuperClass {
7. public B getA() {
8. return new B();
9. }
10. }
Which statement is true?
A. Compilation will succeed if A extends B.
B. Compilation will succeed if B extends A.
C. Compilation will always fail because of an error in line 7
D. Compilation will always fail because of an error in line 8


How to Install JAVA Part-1

Step Prepare First JAVA Application:

--------------------------------------------------------------------
1. Install JAVA Software
2. Select JAVA Editor
3. Write JAVA Program
4. Save JAVA File
5. Compile JAVA File
6. Execute JAVA Problem

1. Install JAVA Software:

--------------------------------------
i. Download jdk file from Oracle or Click Here.
   (Accept the terms and click on the link according to your OS).
ii. Double click on jdk-8u111.exe file.
iii. Click on “Yes” Button.
iv. Click on “Next” Button.
v. Change jdk Installation location from “C:\Program file(x86)\Java\jdk1.8.0_111” to
      “C:\Java\jdk1.8.0_111” by clicking on change button and OK button.
vi. Click on “Next” Button.
vii. Change jre installation location from “C:\Program file(x86)\Java\jre8” to
       “C:\Java\jre8” by clicking change Button and OK button.
viii. Click on “Next” Button.
ix. Click on “Close” Button.

After Installation of JAVA Software, we have to set “path” environment variable to the location where JAVA commands like javac, java, javap, javadoc,… are existed, that is  “C:\Java\jdk1.8.0_111\bin”.

In command prompt:

set path= C:\Java\jdk\1.8.0_111\bin;

Note: the main intention to set “path” environment variable to give location information of all JAVA commands like javac, java, … to the operating system in order to execute.

The above “path” setup is temporary setup, it is valid up to the present command prompt only. If we want to set “path” environment permanently then we have to use the following steps:
a) Right Click on “This PC” on desktop.
b) Select “Properties”.
c) Click on “Advanced System Setting”.
d) Select “Advanced Tab” (By Default Selected).
e) Click on “Environmental Variable” Button.
f) Goto user variables section and click on “New” Button.
g) Provide the following details:
variable name: path
variable value: C:\Java\jdk1.7.0_79\bin;
h) Click on “Ok” Button.
i) Click on “Ok” Button.
j) Click on “Ok” Button.
----------------------------------------------------------------------------------------

2. Select JAVA Editor:

Editor is a Software, it will provide very good environment to write java programs & to save JAVA program into our system.
EX: Notepad, Notepad++, EditPlus…

Note: In real time application development, it is not suggestible to use editors, always it is suggestible to use IDEs[Integrated Development Environments]
EX: Eclipse, MyEclipse, Netbeans, Intellij,…..

---------------------------------------------------

 

Monday, December 19, 2016

Interview Question 21 - 30

Interview Question 21 - 30

21. A bank offers 5% compound interest calculated on half-yearly basis. A customer deposits Rs. 1600 each on 1st January and 1st July of a year. At the end of the year, the amount he would have gained by way of interest is:
A. Rs. 120             B. Rs. 121             C. Rs. 122             D. Rs. 123

22. The difference between simple and compound interests compounded annually on a certain sum of money for 2 years at 4% per annum is Re 1. The sum (in Rs.) is –
A. 625                    B. 630                    C. 640                    D. 650

23. A motorboat, whose speed in 15km/hr In still water goes 30 km downstream and comes back in a total of 4 hours 30 minutes. The speed of the stream (in km/hr) is:
 A. 4                       B. 5                         C. 6                         D. 10

24. A man can row three-quarters of a kilometre against the stream in 11 minutes and down the stream in 7 minutes. The speed (in km/hr) of the man in still water is:
A. 2                        B. 3                         C. 4                         D. 5

25. The least perfect square, which is divisible by each of 21, 36 and 66 is:
A.21344                B. 214344             C. 214434             D. 231444

26. A shop keeper sells milk which contains 5% water. What quantity of pure milk should be added to 2 litres milk (containing 5% water) so that proportion of water becomes 4%?
A. 100 ml              B. 250 ml              C. 400 ml              D. 350 ml              E. None of these

27. A and B started a  business in partnership investing Rs 20,000 and Rs 15,000 respectively. After six months C joined them with Rs 20,000. What will be B’s share in the total profit of Rs 25,000 earned at the end of two years from the starting of the business?
A.  Rs 9,000         B. Rs 10,000        C. Rs 7,500           D. Rs 9,500          E. None of these

28. What approximate value should come in place of the question mark (?)  in the following equation?
158.25 x 4.6 + 21% of 847 + ? = 950.93
A. 35                      B. 40                      C. 25                      D. 50                      E. 45

29. The average of the first and the second of three numbers is 15 more than the average of the second and the third of these numbers. What is the difference between the first and the third of these three numbers?
A. 15                      B. 45                      C. 60                      D. Data inadequate         E. None of These

30. A man starts going for morning walk every day. The distance walked by him on the first day was 2 km. Every day he walks half the distance walked on the previous day. What can be the maximum total distance walked by him in his lifetime?
A. 4 km                 B. 20 km               C. 8 km                 D. Data inadequate         E. None of these

JAVA Programming Format

JAVA Programming Format:

--------------------------------------------------------------------------------------------------------------------------

To design JAVA application, we have to use the following structure:

First java program
JAVA Programming Format


1. Comment Section
2. Package Section
3. Import Section
4. Classes/interface Section
5. Main class Section

The Detailed description will be in the following posts. Bookmark or Subscribe to get updated. 

Sunday, December 18, 2016

JAVA Interview Question 10 - 20

JAVA Interview Question  10 - 20

Q. 11
11. class Alpha {
12. public void foo() { System.out.print(“Afoo”); }
13. }
14. public class Beta extends Alpha {
15. public void foo() { System.out.print(“Bfoo”); }
16. public static void main(String[] args) {
17. Alpha a = new Beta();
18. Beta b = (Beta)a;
19. a.foo();  20. b.foo();
21. }
22. }
What is the result?
A. Afoo Afoo
B. Afoo Bfoo
C. Bfoo Afoo
D. Bfoo Bfoo
E. Compilation fails.
F. An exception is thrown at runtime.

Q. 12 Given:
7. void waitForSignal() {
8. Object obj = new Object();
9. synchronized(Thread.currentThreat()) {
10. obj.wait();
11. obj.notify();
12. }
13. }
Which statement is true?
A. This code may throw an interruptedException.
B. This code may throw an illegalstateException.
C. This code may throw a TimeoutException after ten minutes.
D. This code will not compile unless “obj.wait()” is replaced with “((Thread) obj).wait()”.
E. Reversing the order of obj.wait() and obj.notify() may cause this method to complete normally.
F. A call to notify() or notifyAll() from another thread may cause this method to complete normally.

Q, 13 Given:
1. public class TestSeven extends Thread {
2. private static int x;
3. public synchronized void doThings() {
4. int current = x;
5. current++;
6. x = current;
7. }
8. public void run() {
9. doThings();
10. }
11. }
Which statement is true?
A. Compilation fails.
B. An exception is thrown at runtime.
C. Synchronizing the run() method would make the class thread-safe.
D. The data in variable “x” are protected from concurrent access problems.
E. Declaring the doThings() method as static would make the class thread-safe.
F. Wrapping the statements within doThings() in a synchronized (new Object()) { } block would make the class thread-safe.

Q. 14 Given:
11. public void testIfA() {
12. if (testlfB(“True”)) {
13. System.out.println(“True”);
14. } else {
15. System.out.println(“Not True”);
16. }
17. }
18. public Boolean testlfB(String str) {
19. return Boolean.valueof(str);
20. }
What is the result when method testlfA is invoked?
A. True
B. Not True
C. An exception is thrown at runtime.
D. Compilation fails because of an error at line 12
E. Compilation fails because of an error at line 13.

Q. 15 when comparing java.io.BufferedWriter to java.io.FileWriter, which capability exists as a method in only one of the two?
A. closing the stream.
B. flushing the stream
C. writing to the Stream
D. marking a location in the stream
E. writing a line separator to the stream
     
16. The calendar for the year 2007 will be the same for the year.
A. 2014                 B. 2016                       c. 2017                  D. 2018

17. A man standing at a point P is watching the top of a tower, which makes an angle of elevation of 30 degree with the man’s eye. The man walks some distance towards the tower to watch its top and the angle of the elevation becomes 60 degree. What is the distance between the base of the tower and the point P?
A. 43 units           B. 8 units              C. 12 units           D. Data inadequate.

18. Two ships are sailing in the sea on the two sides of a lighthouse. The angle of elevation of the top of the lighthouse is observed from the ships are 30 degree and 45 degree respectively. If the lighthouse is 100 m high, the distance between the two ships is:
A. 173 m               B. 200 m               C. 273 m               D. 300 m

19. A and B take part in 100 m race. A runs at 5 kmph. A gives B a start of 8 m and still beats him by 8 seconds. The speed of B is:
A. 5.15 kmph      B. 4.14 kmph      C. 4.25 kmph      D. 4.4 kmph

20. In 100 m race, A covers the distance in 36 seconds and B in 45 seconds. In this race A beats B by:
A. 20 m                 B. 25m                  C. 22.5m               D. 9 m

Saturday, December 17, 2016

JAVA Naming Conventions

JAVA Naming Conventions:

--------------------------------------------------------------------------------------------------------------------------

JAVA is strictly a case sensitive programming language, where in JAVA application, there is a separate recognition for lower case letter and upper case letters.

In JAVA application to use lower case letters and upper case letters separately, JAVA has provided the following conventions-

1. All JAVA class names, abstract class names, interface names and enum names must be started with upper case letters and the subsequent symbols must also be upper case letters.

EX:
------
String (1 word)
StringBuffer (2 word)
InputStreamReader(3 word)

2. All JAVA variable name must be started with lower case letters but the subsequent symbols must be upper case letters.
EX:
-------
in, out, err             (1 word)
faceContext, bodyContent (2 words)

3. All JAVA method names must be started with lower case letters but the subsquent symbols must be upper case letters.
EX:
------
concat(-)
forName(--)
getInputStream(---)

4. All JAVA constant variables must be provided in upper case letters.
EX:
-------
MIN_PRIORITY
NORM_PRIORITY
MAX_PRIORITY

5. All JAVA package names must be provided in lower case letters.
EX:
------
java.io
java.awt.event
java.servelet.jsp.tagext



Note: All the above conventions are mandatory for predefined library, which are optional for used defined library, but suggestible.

JAVA Interview Question 0-10

JAVA Interview Question 0-10

Q: 01 Given:
15. public class Yippee {
16. public static void main(String[] args) {
17. for (int x = 1; x < args.length; x++) {
18. System.out.print(args[x] + “ “);
19. }
20. }
21. }
and two separate command line invocations:
java Yippee
java Yippee 1 2 3 4

What is the result?
A. No output is produced.
1 2 3
B. No output is produced.
2 3 4
C. No output is produced.
1 2 3 4
D. An exception is thrown at runtime.
1 2 3
E. An exception is thrown at runtime.
2 3 4
F. An exception is thrown at runtime.
1 2 3 4

Q. 02 Given:

10. class Nav{
11. public enum Direction {NORTH, SOUTH, EAST, WEST}
12. }
13. public class Sprite {
14. // insert code here
15. }

Which code, inserted at line 14, allows the Sprite class to compile?
A. Direction d = NORTH;
B. Nav. Direction d = NORTH;
C. Direction d = Direction.NORTH;
D. Nav.Direction d = Nav.Direction.NORTH;

Q: 3 Given:
11. public class Ball{
12. public enum Color {RED, GREEN, BLUE};
13. public void fool(){
14. // insert code here
15. { System.out.println(c);}
16. }
17. }
Which code inserted at line 14 causes the foo method to print RED, GREEN, and BLUE?
A. for(Color c : Color.values() }
B. for(Color c = RED; c <= BLUE; c++)
C. for(Color c; c.hasNext(); c.next() )
D. for(Color c = Color[0]; c <= Color[2]; c++)
E. for(Color C = Color.RED; c <= Color.BLUE; c++)

Q. 4 Given:
3. public class Spock{
4. public static void main(String[] args){
5. Long tail = 2000L
6. Long distance = 1999L
7. Long story = 1000L
8. if((tail > distance) ^ ((story * 2) == tail))
9. System.out.print(“1”);
10. if((distance + 1 != tail) ^ ((story * 2) == distance))
11. System.out.print(“2”) ;
12. }
13. }
What is the result?
A. 1
B. 2
C. 12
D. Compilation fails.
E. No output is produced.
F. An exception is thrown at runtime.

Q. 5 Given:
25. int x = 12;
26. while (x<10) {
27. x--;
28. }
29. System.out.print(x);
What is the result?
A. 0
B. 10
C. 12
D. Line 29 will never be reached.

Q. 6 Given:
11. static void test() throws Error {
12. if (true) throw new AssertionError ();
13. System.out.print(“test”);
14. }
15. public static void main(String[] args) {
16. try(test); }
17. catch (Exception ex} {System.out.print(“exception”); }
18. System.out.print(“end”);
19. }
What is the result?
A. end
B. Compilation fails.
C. exception end.
D. exception test end
E. A Throwable is thrown by main.
F. An Exception is thrown by main.

Q. 7 Given:
33. try {
34. // some cade here
35. } catch (NullPointerException e1) {
36. System.out.print(“a”);
37. } catch (RuntimeException e2) {
38. System.out.print(“b”);
39. } finally {
40. System.out.print(“c”);
41. }
What is the result if a NullPointerException occurs on line 34?
A. c
B. a
C. ab
D. ac
E. bc
F. abc

Q. 8
Click the Exhibit Button.
1. public class Test {
2.
3. public static void main( String[] args) {
4. Boolean assert = true;
5. if(assert) {
6. System.out.println(“assert is true”);
7. }
8. }
9.
10. }
Given:
Javac –source 1.3 Test.java

What is the result?
A. Compilation fails.
B. Compilatin Succeeds with errors.
C. Compilation succeeds with warnings.
D. Compilation succeeds without warnings or errors.

Q. 9 Given:
11. public void genNumbers() {
12. ArrayList numbers = new ArrayList();
13. for (int i=0; I<10; i++) {
14. int value = i * ((int) Math.random());
15. integer intObj = new Integer(Value);
16. numbers.add(intObj);
17. }
18. System.out.println(numbers);
19. }

Which line of code marks the earliest point that an object referenced by intObj becomes a candidate for garbage collection?
A. Line 16
B. Line 17
C. Line 18
D. Line 19
E. The object is NOT a candidate for garbage collection.

Q. 10 Given:
1. class SuperClass {
2. public A getA(){
3. return new A();
4. }
5. }
6. class SubClass extends SuperClass {
7. public B getA() {
8. return new B();
9. }
10. }
Which statement is true?
A. Compilation will succeed if A extends B.
B. Compilation will succeed if B extends A.
C. Compilation will always fail because of an error in line 7
D. Compilation will always fail because of an error in line 8

Write the Answers in Comments. i will  post correct answer with the name of person. Help me to get Answer.


JAVA Features

JAVA Features:

To show the nature of JAVA, It provided the following features:

1. Simple
2. Object Oriented
3. Platform Independent
4. Architecture Neutral
5. Portable
6. Robust
7. Dynamic
8. Secure
9. Distributed
10. Multi Threaded
11. Interpretive
12. High Performance
-----------------------------------------------------------------------------------------------------

1. Simple:
--------------
JAVA is a Simple Language because-

i.   JAVA take less memory and less execution time.
ii.  JAVA language already removed confusing features like pointers, multi inheritance....
iii. JAVA is using simplifies syntax from C and C++.


2. Object Oriented:
--------------------------
JAVA is an object oriented programming language because JAVA allows its application to store data in the form of Objects.

3. Platform Independent:
------------------------
JAVA is platform Independent programming language because JAVA allows its application to compile in one operating system  and to execute in another operating system.

4. Architecture Neutral:
----------------------------------
JAVA is Arch Neutral language because it allows its application to compile on one hardware Arch and to execute on another Hardware Arch.

5. Portable:
-----------
JAVA is more portable programming language because it able to run its application in all the operating system & in all the
Hardware Arch.

6. Robust:
-----------------
JAVA is Robust programming language because-

i. JAVA is having very good memory management system in the form of Heap memory management system. It allocates and deallocates memory for the objects at the run time.
ii. JAVA is having very good exception handling mechanism, because JAVA has provided very good predefined library to represent & handle almost all the exception which are generating frequently in JAVA application.

7. Security:
------------------
JAVA is very good secure programming language  because-

i. JAVA has provided an implicit component inside JVM as a form of security manager in order to provide implicit security.
ii. JAVA has provided a separate middle ware service in the form of  JAAS(JAVA authorization and Authentication Service) in order to implement web security.
iii. JAVA has provided predefined implementation for almost all of the well known web security algorithm in order to provide network security.

8. Dynamic:
-----------------
JAVA is dynamic programming language because JAVA allows memory allocatio for premitive data type at run-time.

9. Distributed:
---------------------
By using JAVA, we are able to prepare the following type of application-

i. Standalone Application
ii. Distributed Application

i. Standalone Application

If we design any JAVA application without using client server architecture then that JAVA application called standalone application.

ii. Distributed Application

If we design any JAVA application with using client server architecture then that JAVA application called Distributed Application.

To prepare Distributed application, JAVA has provided separate module in the form of J2EE/JAVA EE, so that, JAVA is distributed programming language.

10. Multi Threaded:
-----------------------------
Thread is a flow of execution to perform a particular task, to execute application, there are two module:

i. Single Threaded Module
ii. Multi Threaded Module

i. Single Threaded Module

It allows only one thread to execute application, it follows sequential  execution. it will increase execution time and reduce application  performance.

ii. Multi Threaded Module

JAVA allows more than one thread to execute application . it follows parallel execution. it will reduce application execution time and it improves application performance.

JAVA is following multi threaded application to execute application. JAVA is able to provide very good environment to create and execute more than  one thread at a time.

11. Interpretive:
-----------------------
JAVA is both interpretive and compilation language because-

i. to check developer mistake in JAVA program and to translate JAVA code from high legel representation to low level representation, we need compilation to execute JAVA program . we need an interpreter inside JVM.

12. High Performance:
-------------------------------
JAVA is high performance programming language due to its rich set of features like platform independent, arch neutral, portable, dynamic, robust, multi threaded.