Monday 19 September 2011

Global edge conducting walk-in for freshers.

Location: Bangalore
Eligibility:
B.E/B. Tech only (CSE/ECE/IS/Telecommunication/ IT only)
Year of Passing – 2010 & 2011
Cut Off - Minimum 65 % in academics (10th/PUC/Engineering)
How to apply:
Registration for the drive will be done on 22nd & 23rd September 2011 at 10 AM to 5 PM at
Global Edge Software Limited,
218, JP Royale, Sampige Road,
Malleswaram
Details of the venue and time will be intimated during registrationprocess:
Please carry updated profile and a passport size photograph for registration process
Test Details
1st Round :
General Aptitude/ Computer Fundamentals/E&C Fundamentals
2nd Round :
C& OS Descriptive/C& OS Objective/C Programming

Note: All selected candidates would be required to sign an agreement with us for 3 years. Initial training of 6 months would be given. Confirmation of their services would be subject to the performance of the candidate during the training period

100 Keyboard shortcuts (Windows)

Getting familiar with keyboard shortcuts not only help you get the work done faster, but also more efficient. If your daily  job  rely heavily on using Windows, here are some 100+ Windows Keyboard Shortcuts you might want to check out. If there’s any nifty shortcuts we have missed, appreciate a heads up.
The General Shortcuts
  • CTRL+C (Copy)
  • CTRL+X (Cut)
  • CTRL+V (Paste)
  • CTRL+Z (Undo)
  • Delete(Delete)
  • Shift+Delete (Delete the selected item permanently without placing the item in the Recycle Bin)
  • CTRLwhile dragging an item (Copy the selected item)
  • CTRL+Shift while dragging an item (Create a shortcut to the selected item)
  • F2key (Rename the selected item)
  • CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word)
  • CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word)
  • CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph)
  • CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph)
  • CTRL+Shift with any of the arrow keys (Highlight a block of text)
  • Shiftwith any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document)
  • CTRL+A (Select all)
  • F3key (Search for a file or a folder)
  • Alt+Enter (View the properties for the selected item)
  • Alt+F4 (Close the active item, or quit the active program)
  • Alt+Enter (Display the properties of the selected object)
  • Alt+Spacebar (Open the shortcut menu for the active window)
  • CTRL+F4 (Close the active document in programs that enable you to have multiple documents open simultaneously)
  • Alt+Tab (Switch between the open items)
  • Alt+ESC (Cycle through items in the order that they had been opened)
  • F6key (Cycle through the screen elements in a window or on the desktop)
  • F4key (Display the Address bar list in My Computer or Windows Explorer)
  • Shift+F10 (Display the shortcut menu for the selected item)
  • Alt+Spacebar (Display the System menu for the active window)
  • CTRL+ESC (Display the Start menu)
  • Alt+Underlined letter in a menu name (Display the corresponding menu)
  • Underlined letter in a command name on an open menu (Perform the corresponding command)
  • F10key (Activate the menu bar in the active program)
  • RIGHT ARROW(Open the next menu to the right, or open a submenu)
  • LEFT ARROW(Open the next menu to the left, or close a submenu)
  • F5key (Update the active window)
  • Backspace(View the folder one level up in My Computer or Windows Explorer)
  • ESC (Cancel the current task)
  • Shiftwhen you insert a CD-ROM into the CD-ROM drive (Prevent the CD-ROM from automatically playing)
Dialog Box Keyboard Shortcuts
  • CTRL+Tab (Move forward through the tabs)
  • CTRL+Shift+Tab (Move backward through the tabs)
  • Tab(Move forward through the options)
  • Shift+Tab (Move backward through the options)
  • Alt+Underlined letter (Perform the corresponding command or select the corresponding option)
  • Enter(Perform the command for the active option or button)
  • Spacebar(Select or clear the check box if the active option is a check box)
  • Arrow keys (Select a button if the active option is a group of option buttons)
  • F1key (Display Help)
  • F4key (Display the items in the active list)
  • Backspace(Open a folder one level up if a folder is selected in the Save As or Open dialog box)
Microsoft Natural Keyboard Shortcuts
  • Win(Display or hide the Start menu)
  • Win+BREAK (Display the System Properties dialog box)
  • Win+D (Display the desktop)
  • Win+M (Minimize all of the windows)
  • Win+Shift+M (Restore the minimized windows)
  • Win+E (Open My Computer)
  • Win+F (Search for a file or a folder)
  • CTRL+Win+F (Search for computers)
  • Win+F1 (Display Windows Help)
  • Win+ L (Lock the keyboard)
  • Win+R (Open the Run dialog box)
  • Win+U (Open Utility Manager)
Accessibility Keyboard Shortcuts
  • Right Shift for eight seconds (Switch FilterKeys either on or off)
  • Left Alt+left Shift+PRINT SCREEN (Switch High Contrast either on or off)
  • Left Alt+left Shift+NUM LOCK (Switch the MouseKeys either on or off)
  • Shiftfive times (Switch the StickyKeys either on or off)
  • NUM LOCKfor five seconds (Switch the ToggleKeys either on or off)
  • Win+U (Open Utility Manager)
Windows Explorer Keyboard Shortcuts
  • END(Display the bottom of the active window)
  • HOME(Display the top of the active window)
  • NUM LOCK+* (Display all of the subfolders that are under the selected folder)
  • NUM LOCK++ (Display the contents of the selected folder)
  • NUM LOCK+- (Collapse the selected folder)
  • LEFT ARROW(Collapse the current selection if it is expanded, or select the parent folder)
  • RIGHT ARROW(Display the current selection if it is collapsed, or select the first subfolder)
Shortcut Keys for Character Map
  • After you double-click a character on the grid of characters, you can move through the grid by using the keyboard shortcuts:
  • RIGHT ARROW(Move to the right or to the beginning of the next line)
  • LEFT ARROW(Move to the left or to the end of the previous line)
  • UP ARROW(Move up one row)
  • DOWN ARROW(Move down one row)
  • PAGE UP(Move up one screen at a time)
  • PAGE DOWN(Move down one screen at a time)
  • HOME(Move to the beginning of the line)
  • END(Move to the end of the line)
  • CTRL+HOME (Move to the first character)
  • CTRL+END (Move to the last character)
  • Spacebar(Switch between Enlarged and Nor mal mode when a character is selected)
Microsoft Management Console (MMC) Main Window Keyboard Shortcuts
  • CTRL+O (Open a saved console)
  • CTRL+N (Open a new console)
  • CTRL+S (Save the open console)
  • CTRL+M (Add or remove a console item)
  • CTRL+W (Open a new window)
  • F5key (Update the content of all console windows)
  • Alt+Spacebar (Display the MMC window menu)
  • Alt+F4 (Close the console)
  • Alt+A (Display the Action menu)
  • Alt+V (Display the View menu)
  • Alt+F (Display the File menu)
  • Alt+O (Display the Favorites menu)
MMC Console Window Keyboard Shortcuts
  • CTRL+P (Print the current page or active pane)
  • Alt+- (Display the window menu for the active console window)
  • Shift+F10 (Display the Action shortcut menu for the selected item)
  • F1key (Open the Help topic, if any, for the selected item)
  • F5key (Update the content of all console windows)
  • CTRL+F10 (Maximize the active console window)
  • CTRL+F5 (Restore the active console window)
  • Alt+Enter (Display the Properties dialog box, if any, for the selected item)
  • F2key (Rename the selected item)
  • CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console)
Remote Desktop Connection Navigation
  • CTRL+Alt+END (Open the m*cro$oft Windows NT Security dialog box)
  • Alt+PAGE UP (Switch between programs from left to right)
  • Alt+PAGE DOWN (Switch between programs from right to left)
  • Alt+INSERT (Cycle through the programs in most recently used order)
  • Alt+HOME (Display the Start menu)
  • CTRL+Alt+BREAK (Switch the client computer between a window and a full screen)
  • Alt+Delete (Display the Windows menu)
  • CTRL+Alt+- (Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.)
  • CTRL+Alt++ (Place a snapshot of the entire client window area on the Terminal server clipboard and provide the same functionality as pressing Alt+PRINT SCREEN on a local computer.)
Internet Explorer navigation
  • CTRL+B (Open the Organize Favorites dialog box)
  • CTRL+E (Open the Search bar)
  • CTRL+F (Start the Find utility)
  • CTRL+H (Open the History bar)
  • CTRL+I (Open the Favorites bar)
  • CTRL+L (Open the Open dialog box)
  • CTRL+N (Start another instance of the browser with the same Web address)
  • CTRL+O (Open the Open dialog box, the same as CTRL+L)
  • CTRL+P (Open the Print dialog box)
  • CTRL+R (Update the current Web page)
CTRL+W (Close the current window)

Upload your CV to Tata Consultancy Services.


To apply for a job, please upload your resume highlighting your qualifications. Please make sure that you provide a valid email address in your resume. TCS would notify you via email when an opportunity arises that matches your profile.

To know more about the work life at TCS, please click here.

To Apply online:

https://grs.tcs.com/DTOnline/CareersDesign/Jsps/EntryLevel.jsp
All the Best.

Number of ways to create java object

1)Ex1 obj1j=new Ex1;(using new operator)

2)Class c = Class.forName("java.lang.String"); (using Class.forName also called reflection)

3)MyObject obj=(MyObject) obj.clone();(using cloning)

4)we will create the objects using factory design pattern (but internally we are using new operator).

5)with the help of deserialization we will get the object(in serialization we are creating object to file and in deserialization we are getting the object from file).


Some in put from google
1. Using new keyword
This is the most common way to create an object in java. I read somewhere that almost 99 of objects are created in this way.
MyObject object = new MyObject();
2. Using Class.forName()
If we know the name of the class & if it has a public default constructor we can create an object in this way.
MyObject object= (MyObject) Class.forName( subin.rnd.MyObject ).newInstance();
3. Using clone()The clone() can be used to create a copy of an existing object.
MyObject anotherObject = new MyObject();
MyObject object = anotherObject.clone();
4. Using object deserialization
Object deserialization is nothing but creating an object from its serialized form.
ObjectInputStream inStream = new ObjectInputStream(anInputStream );
MyObject object = (MyObject) inStream.readObject();
5. Using class loaderone more is through creation of object using classloader
like

this.getClass().getClassLoader().loadClass( com.amar.myobject ).newInstance();

Wednesday 14 September 2011

SCWCD Questions 01-10


Question: 1
To take advantage of the capabilities of modern browsers that use web standards, such as
XHTML and CSS, your web application is being converted from simple JSP pages to JSP
Document format. However, one of your JSPs, /scripts/screenFunctions.jsp, generates a
JavaScript file. This file is included in several web forms to create screen-specific validation
functions and are included in these pages with the following statement:
10. <head>
11. <script src='/scripts/screenFunctions.jsp'
12. language='javascript'
13. type='application/javascript'> </script>
14. </head>
15. <!-- body of the web form -->
Which JSP code snippet declares that this JSP Document is a JavaScript file?
A. <%@ page contentType='application/javascript' %>
B. <jsp:page contentType='application/javascript' />
C. <jsp:document contentType='application/javascript' />
D. <jsp:directive.page contentType='application/javascript' />
E. No declaration is needed because the web form XHTML page already declares the MIME
type of the /scripts/screenFunctions.jsp file in the <script> tag.
Answer: D


Question: 2
Given the JSP code:
10. <html>
11. <body>
12. <jsp:useBean id='customer' class='com.example.Customer' />
13. Hello, ${customer.title} ${customer.lastName}, welcome
14. to Squeaky Beans, Inc.
15. </body>
16. </html>
Which three types of JSP code are used? (Choose three.)
A. Java code
B. Template text
C. Scripting code
D. Standard action
E. Expression language
Answer: B, D, E


Question: 3
You have built a collection of custom tags for your web application. The TLD file is located in the
file: /WEB-INF/myTags.xml. You refer to these tags in your JSPs using the symbolic name:
myTags. Which deployment descriptor element must you use to make this link between the
symbolic name and the TLD file name?
A. <taglib>
<name>myTags</name>
<location>/WEB-INF/myTags.xml</location>

</taglib>
B. <tags>
<name>myTags</name>
<location>/WEB-INF/myTags.xml</location>
</tags>
C. <tags>
<tags-uri>myTags</taglib-uri>
<tags-location>/WEB-INF/myTags.xml</tags-location>
</tags>
D. <taglib>
<taglib-uri>myTags</taglib-uri>
<taglib-location>/WEB-INF/myTags.xml</taglib-location>
</taglib>
Answer: D


Question: 4
Which implicit object is used in a JSP page to retrieve values associated with <context-param>
entries in the deployment descriptor?
A. Config
B. Request
C. Session
D. Application
Answer: D


Question: 5
Click the Task button.
Place the events in the order they occur.

Answer:

Question: 6
Click the Task button.
Place the code snippets in the proper order to construct the JSP code to import static content into
Explanation:



QUESTION NO: 7



You have created a JSP that includes instance variables and a great deal of scriptlet code.
Unfortunately, after extensive load testing, you have discovered several race conditions in your
JSP scriptlet code. To fix these problems would require significant recoding, but you are already
behind schedule. Which JSP code snippet can you use to resolve these concurrency problems?
A. <%@ page isThreadSafe='false' %>
B. <%@ implements SingleThreadModel %>
C. <%! implements SingleThreadModel %>
D. <%@ page useSingleThreadModel='true' %>
E. <%@ page implements='SingleThreadModel' %>

Answer: A


QUESTION NO: 8
Click the Exhibit button.
The attribute "name" has a value of "Foo,"
What is the result if this tag handler's tag is invoked?

A. Foo
B. done
C. Foodone
D. An exception is thrown at runtime.
E. No output is produced from this code.
F. Compilation fails because of an error in this code.

Answer: A

QUESTION NO: 9

You are building a web application that will be used throughout the European Union; therefore, it
has significant internationalization requirements. You have been tasked to create a custom tag
that generates a message using the java.text.MessageFormat class. The tag will take the
resourceKey attribute and a variable number of argument attributes with the format, arg<N>. Here
is an example use of this tag and its output:
<t:message resourceKey='diskFileMsg' arg0='MyDisk' arg1='1247' />
generates:
The disk "MyDisk" contains 1247 file(s).
Which Simple tag class definition accomplishes this goal of handling a variable number of tag
attributes?
A. public class MessageTag extends SimpleTagSupport
implements VariableAttributes {
private Map attributes = new HashMap();
public void setVariableAttribute(String uri,
String name, Object value) {
this.attributes.put(name, value);
}
// more tag handler methods
}
B. The Simple tag model does NOT support a variable number of attributes.
C. public class MessageTag extends SimpleTagSupport
implements DynamicAttributes {
private Map attributes = new HashMap();
public void putAttribute(String name, Object value) {
this.attributes.put(name, value);
}

// more tag handler methods
}
D. public class MessageTag extends SimpleTagSupport
implements VariableAttributes {
private Map attributes = new HashMap();
public void putAttribute(String name, Object value) {
this.attributes.put(name, value);
}
// more tag handler methods
}
E. public class MessageTag extends SimpleTagSupport
implements DynamicAttributes {
private Map attributes = new HashMap();
public void setDynamicAttribute(String uri, String name,
Object value) {
this.attributes.put(name, value);
}
// more tag handler methods
}

Answer: E

QUESTION NO: 10

Given the JSP code:
<% request.setAttribute("foo", "bar"); %>
and the Classic tag handler code:
5. public int doStartTag() throws JspException {
6. // insert code here
7. // return int
8. }
Assume there are no other "foo" attributes in the web application.
Which invocation on the pageContext object, inserted at line 6, assigns "bar" to the variable x?
A. String x = (String) pageContext.getAttribute("foo");
B. String x = (String) pageContext.getRequestScope("foo");




C. It is NOT possible to access the pageContext object from within doStartTag.
D. String x = (String)
pageContext.getRequest().getAttribute("foo");
E. String x = (String) pageContext.getAttribute("foo",
PageContext.ANY_SCOPE);

Answer: D

Wednesday 7 September 2011

Tuesday 6 September 2011

SCJP Questions 211-224


                                                        PREVIOUS 

Question 211
Given:
11. class Snoochy {
12. Boochybooch;
13. public Snoochy() { booch = new Boochy(this); }
14. }
15.
16. class Boochy {
17. Snoochy snooch;
18. public Boochy(Snoochy s) { snooch = s; }
19. }
And the statements:
21. public static void main(String[] args) {
22. Snoochy snoog = new Snoochy();
23. snoog = null;
24. // more code here
25. }
Which statement is true about the objects referenced by snoog,
snooch, and booch immediately after line 23 executes?
A. None of these objects are eligible for garbage collection.
B. Only the object referenced by booch is eligible for garbage
collection.
C. Only the object referenced by snoog is eligible for garbage
collection.
D. Only the object referenced by snooch is eligible for garbage
collection.
E. The objects referenced by snooch and booch are eligible for garbage
collection.
Answer: E

Question 212
Given:
1. public class GC {
2. private Object o;
3. private void doSomethingElse(Object obj) { o = obj; }
4. public void doSomething() {
5. Object o = new Object();
6. doSomethingElse(o);
7. o = new Object();
8. doSomethingElse(null);
9.o=null;
10. }
11. }
When the doSomething method is called, after which line does the
Object created in line 5 become available for garbage collection?
A. Line 5
B. Line 6
C. Line 7
D. Line 8
E. Line 9
F. Line 10
Answer: D

Question 213
Which two are true? (Choose two.)
A. A finalizer may NOT be invoked explicitly.
B. The finalize method declared in class Object takes no action.
C. super.finalize() is called implicitly by any overriding finalize method.
D. The finalize method for a given object will be called no more than
once by the garbage collector.
E. The order in which finalize will be called on two objects is based on
the order in which the two objects became finalizable.
Answer: BD

Question 214
A class games.cards.Poker is correctly defined in the jar file Poker.jar.
A user wants to execute the main method of Poker on a UNIX system
using the command:
java games.cards.Poker
What allows the user to do this?
A. put Poker.jar in directory /stuff/java, and set the CLASSPATH to
include /stuff/java
B. put Poker.jar in directory /stuff/java, and set the CLASSPATH to
include /stuff/java/*.jar
C. Put Poker.jar in directory /stuff/java, and set the CLASSPATH to
include /stuff/java/Poker.jar
D. put Poker.jar in directory /stuff/java/games/cards, and set the
CLASSPATH to include /stuff/java
E. put Poker.jar in directory /stuff/java/games/cards, and set the
CLASSPATH to include /stuffijava/*.jar
F. put Poker.jar in directory /stuff/java/games/cards, and set the
CLASSPATH to include /stuff/java/Poker.jar
Answer: C

Question 215
Click the Exhibit button.
Given the fully-qualified class names:
com.foo.bar.Dog
com.foo.bar.blatz.Book
com.bar.Car
com.bar.blatz.Sun
Which graph represents the correct directory structure for a JAR file
from which those classes can be used by the compiler and JYM?
A. Jar A
B. Jar B
C. Jar C
D. Jar D
E. Jar E
Answer: A

Question 216
A developer is creating a class Book that needs to access class Paper.
The Paper class is deployed in a JAR named myLib.jar. Which three,
taken independently, will allow the developer to use the Paper class
while compiling the Book class? (Choose three.)
A. The JAR file is located at $JAVA_HOME/jre/classes/myLib.jar.
B. The JAR file is located at $JAVA_HOME/jre/lib/ext/myLib.jar.
C. The JAR file is located at /foo/myLib.jar and a classpath
environment variable is set that includes /foo/myLib.jar/Paper.class.
D. The JAR file is located at /foo/myLib.jar and a classpath
environment variable is set that includes /foo/myLib.jar.
E. The JAR file is located at /foo/myLib.jar and the Book class is
compiled using javac -cp /foo/myLib.jar/Paper Book.java.
F. The JAR file is located at /foo/myLib.jar and the Book class is
compiled using javac -d /foo/myLib.jar Book.java.
G. The JAR file is located at /foo/myLib.jar and the Book class is
compiled using javac -classpath /foo/myLib.jar Book.java.
Answer: BDG

Question 217
Given:
1. package com.company.application;
2.
3. public class MainClass {
4. public static void main(String[] args) { }
5. }
And MainClass exists in the /apps/com/company/application directory.
Assume the CLASSPATH environment variable is set to “.“ (current
directory). Which two java commands entered at the command line
will run MainClass? (Choose two.)
A. java MainClass if run from the /apps directory
B. java com.company.application.MainClass if run from the /apps
directory
C. java -classpath /apps com.company.application.MainClass if run
from any directory
D. java -classpath . MainClass if run from the
/apps/com/company/application directory
E. java -classpath /apps/com/company/application:. MainClass if run
from the /apps directory
F. java com.company.application.MainClass if run from the
/apps/com/company/application directory
Answer: BC

Question 218
A UNIX user named Bob wants to replace his chess program with a
new one, but he is hot sure where the old one is installed. Bob is
currently able to run a Java chess program starting from his home
directory /home/bob using the command:
java -classpath /test:/home/bob/downloads/* .jar games.Chess
Bob’s CLASSPATH is set (at login time) to:
/usr/lib:/home/bob/classes:/opt/java/lib:/opt/java/lib/* .jar
What is a possible location for the Chess.class file?
A. /test/Chess.class
B. /home/bob/Chess.class
C. /test/games/Chess.class
D. /usr/lib/games/Chess.class
E. /home/bob/games/Chess.class
F. inside jarfile /opt/java/lib/Games.jar (with a correct manifest)
G. inside jarfile /home/bob/downloads/Games.jar (with a correct
manifest)
Answer: C

Question 219
Given:
11. public static void test(String str) {
12. if(str == null | str.lellgth() == 0) {
13. System.out.println(”String is empty”);
14. } else {
15. System.out.println(”String is not empty”);
16. }
17. }
And the invocation:
31. test(llull);
What is the result?
A. Au exception is thrown at runtime.
B. “String is empty” is printed to output.
C. Compilation fails because of au error in line 12.
D. “String is not empty” is printed to output.
Answer: A

Question 220
Given:
11. public static void test(String str) {
12. int check = 4;
13. if (check = str.length()) {
14. System.out.print(str.charAt(check -= 1) +“, “);
15. } else {
16. System.out.print(str.charAt(0) + “, “);
17. }
18. }
and the invocation:
21. test(”four”);
22. test(”tee”);
23. test(”to”);
What is the result?
A. r, t, t,
B. r, e, o,
C. Compilation fails.
D. An exception is thrown at runtime.
Answer: C

Question 221
Given:
10. public class MyClass {
11.
12. public Integer startingI;
13. public void methodA() {
14. Integer i = new Integer(25);
15. startingI = i;
16. methodB(i);
17. }
18. private void methodB(Integer i2) {
19. i2 = i2.intValue();
20.
21. }
22. }
If methodA is invoked, which two are true at line 20? (Choose two.)
A. i2 == startingI returns true.
B. i2 == startingI returns false.
C. i2.equals(startingI) returns true.
D. i2.equals(startingI) returns false.
Answer: BC

Question 222
222. Given:
11. class Cup { }
12. class PoisonCup extends Cup { }
21. public void takeCup(Cup c) {
22. if(c instanceof PoisonCup) {
23. System.out.println(”Inconceivable!”);
24. } else if(c instanceof Cup) {
25. System.out.println(”Dizzying intellect!”);
26. } else {
27. System.exit(0);
28. }
29. }
And the execution of the statements:
Cup cup = new PoisonCup();
takeCup(cup);
What is the output?
A. Inconceivable!
B. Dizzying intellect!
C. The code runs with no output.
D. An exception is thrown at runtime.
E. Compilation fails because of an error in line 22.
Answer: A

Question 223
Given:
11. String[] elements = { “for”, “tea”, “too” };
12. String first = (elements.length > 0)? elements[0] null;
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime.
C. The variable first is set to null.
D. The variable first is set to elements[0].
Answer: D

Question 224
Given:
42. public class ClassA {
43. public int getValue() {
44.int value=0;
45. boolean setting = true;
46. String title=”Hello”;
47. if (value || (setting && title == “Hello”)) { return 1; }
48. if (value == 1 & title.equals(”Hello”)) { return 2; }
49. }
50. }
And:
70. ClassA a = new ClassA();
71. a.getValue();
What is the result?
A. 1
B. 2
C. Compilation fails.
D. The code runs with no output.
E. An exception is thrown at runtime.
Answer: C


                                                     PREVIOUS    

SCJP Questions 201-210

                                      PREVIOUS                       NEXT

Question 200
Given the command line java Pass2 and:
15. public class Pass2 {
16. public void main(String [] args) {
17.int x=6;
18. Pass2 p = new Pass2();
19. p.doStuff(x);
20. System.out.print(” main x = “+ x);
21. }
22.
23. void doStuff(int x) {
24. System.out.print(” doStuffx = “+ x++);
25. }
26. }
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime.
C. doStuffx = 6 main x = 6
D. doStuffx = 6 main x = 7
E. doStuffx = 7 main x = 6
F. doStuffx = 7 main x = 7
Answer: B

Question 201
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 1234
What is the result?
A. No output is produced.
123
B. No output is produced.
234
C. No output is produced.
1234
D. An exception is thrown at runtime.
123
E. An exception is thrown at runtime.
234
F. An exception is thrown at rijntime.
1234
Answer: B

Question 202
Given:
12. public class Yippee2 {
13.
14. static public void main(String [] yahoo) {
15. for(int x= 1; x<yahoo.length; x++) {
16. System.out.print(yahoo[x] + “ “);
17. }
18. }
19. }
and the command line invocation:
java Yippee2 a b c
What is the result?
A.a b
B.b c
C.a b c
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: B

Question 203
Given:
11. public class Commander {
12. public static void main(String[] args) {
13. String myProp = /* insert code here */
14. System.out.println(myProp);
15. }
16. }
and the command line:
java -Dprop.custom=gobstopper Commander
Which two, placed on line 13, will produce the output gobstopper?
(Choose two.)
A. System.load(”prop.custom”);
B. System.getenv(”prop.custom”);
C. System.property(”prop.custom”);
D. System.getProperty(”prop.custom”);
E. System.getProperties().getProperty(”prop.custom”);
Answer: DE

Question 204
Click the Exhibit button.
11. class Payload {
12. private int weight;
13. public Payload(int wt) { weight = wt; }
13. public void setWeight(mt w) { weight = w; }
15. public String toString { return Integer.toString(weight); }
16. }
17.
18. public class TestPayload {
19. static void changePayload(Payload p) {
20. /* insert code here */
21. }
22.
23. public static void main(String[] args) {
24. Payload p = new Payload();
25. p.setWeight(1024);
26. changePayload(p);
27. System.out.println(”The value of p is “+ p);
28. }
29. }
Which statement, placed at line 20, causes the code to print “The
value of p is 420.”?
A. p.setWeight(420);
B. p.changePayload(420);
C. p = new Payload(420);
D. Payload.setWeight(420);
E. p = Payload.setWeight(420);
F. p = new Payload();
p.setWeight(420);
Answer: A

Question 205
Click the Exhibit button.
1. public class Item {
2. private String desc;
3. public String getDescription() { return desc; }
4. public void setDescription(String d) { desc = d; }
5.
6. public static void modifyDesc(Item item, String desc) {
7. item = new Item();
8. item.setDescription(desc);
9. }
10. public static void main(String[] args) {
11. Item it = new Item();
12. it.setDescription(”Gobstopper”);
13. Item it2 = new Item();
14. it2.setDescription(”Fizzylifting”);
15. modifyDesc(it, “Scrumdiddlyumptious”);
16. System.out.println(it.getDescription());
17. System.out.println(it2.getDescription());
18. }
19. }
What is the outcome of the code?
A. Compilation fails.
B. Gobstopper
Fizzylifting
C. Gobstopper
Scrumdiddlyumptious
D. Scrumdiddlyumptious
Fizzylifltng
E. Scrumdiddlyumptious
Scrumdiddlyumptious
Answer: B

Question 206
Given:
11. public class ItemTest {
12. private final mt id;
13. public ItemTest(int id) { this.id = id; }
14. public void updateId(int newId) { id = newId; }
15.
16. public static void main(String[] args) {
17. ItemTest fa = new ItemTest(42);
18. fa.updateId(69);
19. System.out.println(fa.id);
20. }
21. }
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime.
C. The attribute id in the Item object remains unchanged.
D. The attribute id in the Item object is modified to the new value.
E. A new Item object is created with the preferred value in the id
attribute.
Answer: A

Question 207
Click the Exhibit button.
10. class Inner {
11. private int x;
12. public void setX( int x) { this.x = x; }
13. public int getX() { return x; }
14. }
15.
16. class Outer {
17. private Inner y;
18. public void setY( Inner y) { this.y = y; }
19. public Inner getY() { return y; }
20. }
21.
22. public class Gamma {
23. public static void main( String[] args) {
24. Outer o = new Outer();
25. Inner i = new Inner();
26.int n=10;
27. i.setX(n);
28. o.setY(i);
29. // insert code here
30. System.out.println( o.getY().getX());
31. }
32. }
Which three code fragments, added individually at line 29, produce the
output 100? (Choose three.)
A. n = 100;
B. i.setX( 100);
C. o.getY().setX( 100);
D. i = new Inner(); i.setX( 100);
E. o.setY( i); i = new Inner(); i.setX( 100);
F. i = new Inner(); i.setX( 100); o.setY( i);
Answer: BCF

Question 208
Click the Exhibit button.
10. class Foo {
11. private int x;
12.publicFoo(intx) {this.x=x; }
13. public void setX( int x) { this.x = x; }
14. public int getX() { return x; }
15. }
16.
17. public class Gamma {
18.
19. static Foo fooBar( Foo foo) {
20. foo = new Foo( 100);
21. return foo;
22. }
23.
24. public static void main( String[] args) {
25. Foo foo = new Foo( 300);
26. System.out.print( foo.getX() + “-“);
27.
28. Foo fooFoo = fooBar( foo);
29. System.out.print( foo.getX() + “-“);
30. System.out.print( fooFoo.getX() + “-“);
31.
32. foo = fooBar( fooFoo);
33. System.out.print( foo.getX() + “-“);
34. System.out.prmt( fooFoo.getX());
35. }
36. }
What is the output of this program?
A. 300-100-100-100-100
B. 300-300-100-100-100
C. 300-300-300-100-100
D. 300-300-300-300-100
Answer: B

Question 209
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.
Answer: D

Question 210
Given:
11. rbo = new ReallyBigObject();
12. // more code here
13. rbo = null;
14. /* insert code here */
Which statement should be placed at line 14 to suggest that the virtual
machine expend effort toward recycling the memory used by the
object rbo?
A. System.gc();
B. Runtime.gc();
C. System.freeMemory();
D. Runtime.getRuntime().growHeap();
E. Runtime.getRuntime().freeMemory();
Answer: A

                                      PREVIOUS                       NEXT

SCJP Questions 191-200


                                    PREVIOUS                       NEXT

Question 191
Given classes defined in two different files:
1. package util;
2. public class BitUtils {
3. public static void process(byte[]) { /* more code here */ }
4. }
1. package app;
2. public class SomeApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
What is required at line 5 in class SomeApp to use the process method
of BitUtils?
A. process(bytes);
B. BitUtils.process(bytes);
C. util.BitUtils.process(bytes);
D. SomeApp cannot use methods in BitUtils.
E. import util.BitUtils.*; process(bytes);
Answer: C

Question : 192
Given classes defined in two different files:
1. package util;
2. public class BitUtils {
3. private static void process(byte[] b) { }
4. }
1. package app;
2. public class SomeApp {
3. public static void main(String[] args) {
4. byte[] bytes = new byte[256];
5. // insert code here
6. }
7. }
What is required at line 5 in class SomeApp to use the process method
of BitUtils?
A. process(bytes);
B. BitUtils.process(bytes);
C. app.BitUtils.process(bytes);
D. util.BitUtils.process(bytes);
E. import util.BitUtils. *; process(bytes);
F. SomeApp cannot use the process method in BitUtils.
Answer: F

Question 193
Given classes defined in two different files:
1. package packageA;
2. public class Message {
3. String getText() { return “text”; }
4. }
and:
1. package packageB;
2. public class XMLMessage extends packageA.Message {
3. String getText() { return “<msg>text</msg>”; }
4. public static void main(String[] args) {
5. System.out.println(new XMLMessage().getText());
6. }
7. }
What is the result of executing XMLMessage.main?
A. text
B. <msg>text</msg>
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 2 of XMLMessage.
E. Compilation fails because of an error in line 3 of XMLMessage.
Answer: E

Question 194
Given a file GrizzlyBear.java:
1. package animals.mammals;
2.
3. public class GrizzlyBear extends Bear {
4. void hunt() {
5. Salmon s = findSalmon();
6. s.consume();
7. }
8. }
and another file, Salmon.java:
1. package animals.fish;
2.
3. public class Salmon extends Fish {
4. void consume() { /* do stuff */ }
5. }
Assume both classes are defined in the correct directories for theft
packages, and that the Mammal class correctly defines the
findSalmon() method. Which two changes allow this code to compile
correctly? (Choose two.)
A. add public to the start of line 4 in Salmon.java
B. add public to the start of line 4 in GrizzlyBear.java
C. add import animals.mammals.*; at line 2 in Salmon.java
D. add import animals.fish.*; at line 2 in GrizzlyBear.java
E. add import animals.fish.Salmon.*; at line 2 in GrizzlyBear.java
F. add import animals.mammals.GrizzlyBear.*;at line 2 in Salmon.java
Answer: AD

Question 195
Given a class Repetition:
1. package utils;
2.
3. public class Repetition {
4. public static String twice(String s) { return s + s; }
5. }
and given another class Demo:
1. // insert code here
2.
3. public class Demo {
4. public static void main(String[] args) {
5. System.out.println(twice(”pizza”));
6. }
7. }
Which code should be inserted at line 1 of Demo.java to compile and
run Demo to print “pizzapizza”?
A. import utils.*;
B. static import utils.*;
C. import utils.Repetition.*;
D. static import utils.Repetition. *;
E. import utils.Repetition.twice();
F. import static utils.Repetition.twice;
G. static import utils.Repetition.twice;
Answer: F

Question 196
Given:
11. interface DeclareStuff{
12. public static final int EASY = 3;
13. void doStuff(int t); }
14. public class TestDeclare implements DeclareStuff {
15. public static void main(String [] args) {
16. int x=5;
17. new TestDeclare().doStuff(++x);
18. }
19. void doStuff(int s) {
20. s += EASY + ++s;
21. System.out.println(”s “ + s);
22. }
23. }
What is the result?
A. s 14
B. s 16
C. s 10
D. Compilation fails.
E. An exception is thrown at runtime.
Answer: D

Question 197
Given:
1. interface DoStuff2 {
2. float getRange(int low, int high); }
3.
4. interface DoMore {
5. float getAvg(int a, int b, int c); }
6.
7. abstract class DoAbstract implements DoStuff2, DoMore { }
8.
9. class DoStuff implements DoStuff2 {
10. public float getRange(int x, int y) { return 3.14f; } }
11.
12. interface DoAll extends DoMore {
13. float getAvg(int a, int b, int c, int d); }
What is the result?
A. The file will compile without error.
B. Compilation fails. Only line 7 contains an error.
C. Compilation fails. Only line 12 contains an error.
D. Compilation fails. Only line 13 contains an error.
E. Compilation fails. Only lines 7 and 12 contain errors.
F. Compilation fails. Only lines 7 and 13 contain errors.
G. Compilation fails. Lines 7, 12, and 13 contain errors.
Answer: A

Question 198
Given:
11. public class Counter {
12. public static void main(String[] args) {
13. int numArgs = /* insert code here */;
14. }
15. }
and the command line:
java Counter one fred 42
Which code, inserted at line 13, captures the number of arguments
passed into the program?
A. args.count
B. args.length
C. args.count()
D. args.length()
E. args.getLength()
Answer: B

Question 199
Given a correctly compiled class whose source code is:
1. package com.sun.sjcp;
2. public class Commander {
3. public static void main(String[] args) {
4. // more code here
5. }
6. }
Assume that the class file is located in /foo/com/sun/sjcp/, the current
directory is /foo/, and that the classpath contains “.“ (current
directory).
Which command line correctly runs Commander?
A. java Commander
B. java com. sim. sjcp.Commander
C. java com/sun/sjcp/Commander
D. java -cp com.sun.sjcp Commander
E. java -cp com/sun/sjcp Commander
Answer: B

Question 200
Given the command line java Pass2 and:
15. public class Pass2 {
16. public void main(String [] args) {
17.int x=6;
18. Pass2 p = new Pass2();
19. p.doStuff(x);
20. System.out.print(” main x = “+ x);
21. }
22.
23. void doStuff(int x) {
24. System.out.print(” doStuffx = “+ x++);
25. }
26. }
What is the result?
A. Compilation fails.
B. An exception is thrown at runtime.
C. doStuffx = 6 main x = 6
D. doStuffx = 6 main x = 7
E. doStuffx = 7 main x = 6
F. doStuffx = 7 main x = 7
Answer: B

                                          PREVIOUS                       NEXT
Related Posts Plugin for WordPress, Blogger...