GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Placement Papers  >  Manhattan Associates  >  Java
Next Question 
 Java  |  Question 1 of 17    Print  
Which of the following 2 methods executes faster ?

class Trial {

String _member;

void method1() {
for(int i=0;i<2048;i++) {
_member += "test";
}
}

void method2() {

String temp;

for(int i=0;i<2048;i++) {
temp += "test";
}
_member = temp;
}

}


(a) method1()
(b) method2()
(c) Both method1() and method2() takes same time for execution

(b)

Accessing method variables requires less overhead than accessing class variables.




  
Total Answers and Comments: 2 Last Update: June 19, 2005   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
April 27, 2005 05:31:46   #1  
Amit        

RE: Which of the following 2 methods executes faster ?class Trial { String _member; void method1() { ...
a
 
Is this answer useful? Yes | No
June 19, 2005 00:49:31   #2  
chandra        

RE: Which of the following 2 methods executes faster ?class Trial { String _member; void method1() { ...

 
Time taken for method1() is 1375 
Time taken for method2()is 1406 
 
public static void main(String arg[]) 

Class_Method_Variable cmv=new Class_Method_Variable(); 
Date d=new Date(); 
long t1=d.getTime(); 
cmv.method1(); 
Date d1=new Date(); 
long t2=d1.getTime(); 
long time=t2-t1; 
 
System.out.println("Time taken for method1() is "+time); 
Date d3=new Date(); 
t1=d3.getTime(); 
cmv.method2(); 
Date d4=new Date(); 
t2=d4.getTime(); 
time=t2-t1; 
System.out.println("Time taken for method2()is "+time); 
 
}

 
Is this answer useful? Yes | No

 Related Questions

Which of the following 2 methods executes faster ?class Trial { String _member; void method1() { for(int i=0;i<2048;i++) { _member += "test"; } } void method2() { String temp; for(int i=0;i<2048;i++) { temp += "test"; } _member = temp; } } (a) method1() (b) method2() (c) Both method1() and method2() takes same time for execution
(b)Accessing method variables requires less overhead than accessing class variables. 

(a) 
Latest Answer : an exception of NumberFormat will be thrown ...

By default, Strings to functions are passed using the method(a) Call by Value (b) Call by Reference (c) Strings cannot be passed to function
(b)String is a class defined in java.lang and in java all classes are passed by reference. 

What is the output of following program ?class Test { public static void main(String args[]) { for(int i=0;i<2;i++) { System.out.println(i); } } }(a) Goes into infinite loop (b) 0,1 (c) 0,1,2 (d) None
(a) 

How many String objects are created by the following statements ?String str = " a+b=10 "; trim(str) str.replace(+,-);(a) 1 (b) 2 (c) 3 (d) 4
(c)Strings are immutable. So, for each String operation, one new object is generated. 

Latest Answer : Interface is design on which class is built.Interface is a java defined type. ...

Latest Answer : yes answer is final  it wou't give chance to other to modify. it prevant to other to chace the class. ...

What is the better way of writing the Constructor with 2 parameters in the following code:class Test { int x,y; Test(int a) { //Code for very complex operations will be written //in this place x=a; } Test(int a, int b) { //Code for very complex operations will be written //in this place (same code as in above constructor) x=a; y=b; } }


 Sponsored Links

 
Related Articles

Service Oriented Java Business Integration Review

Service Oriented Java Business Integration Review Introduction If you ve read through the texts which give you an introduction to SOA or Web Services you will often find them to be quite frustrating and the reason for this is because they spend too much time referencing business processes which are
 

Microsoft AJAX Library - JavaScript Execution Context

JavaScript Execution Context In this section we ll take a peek under the hood of the JavaScript closures and the mechanisms that allow us to create classes objects and object members in JavaScript For most cases understanding these mechanisms isn t absolutely necessary for writing JavaScript code&am
 

C++ Void Pointer and Null Pointer

C Void Pointer and Null Pointer In this C tutorial you will learn about two interesting types of pointers; void pointers and Null Pointer These pointers will be discussed in conjunction with syntax usage and example mosgoogle center Pointer to Void General Syntax void pointer variable; Void is use
 

C++ Pure Virtual Function and Base Class

C Pure Virtual Function and Virtual Base Class In this C tutorial you will learn about pure virtual function declaration of pure virtual function and virtual base class virtual base class and how to implement a virtual base class explained with examples mosgoogle center What is Pure Virtual Function
 

C++ String Representation and Handling

C String Representation and Handling In this C tutorial you will learn about string representation and handling how is string represented end string notation initializing char array character representation string literals example programe to understand the character array concept and the accessing
 

Java and Client Server Models

Java and Client Server Models The Role of Client Servers on the Web Client server models provide the essential mechanisms for working with the Internet In fact most of the World Wide Web is built according to this paradigm In client server models the web browsers run by millions of users are the cli
 

How to Access C++ Class Members

How to Access C Class Members In this C tutorial you will learn how to access Class members dot operator or class member access operator difference between struct and class and&nbsp; scope resolution operator mosgoogle center It is possible to access the class members after a class is defined an
 

JavaScript String Object

JavaScript String Object In this JavaScript tutorial you will learn about String Object purpose of string object in JavaScript purpose of string object indexof method lastIndexOf method and substring method along with syntax and example mosgoogle center Purpose of String Object in JavaScript The mai
 

Convert a String into an Integer

How to convert a string into an integer in C program? This is done by using the function named as atoi(). This function atoi() is present in the header file named as &lt;stdlib.h&gt;. When programmers use this function they must include the header file by the statement #include &lt;stdl
 

String handling functions

What is the string handling functions present in header file &lt;string.h&gt;? There are number of string handling functions present in string.h. In other words if a programmer uses any of the function present in string.h then they must include the header file as #include &lt;string.h&am
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape