Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML
 
 
Hot Web Programming Job

 

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML

[an error occurred while processing this directive]

Java: Method FAQs

Q: Do we always have to write a class name in front of static method calls?

A: Yes, but Java allows an exception. If the static method definition is in the same class as the call, you don't have to write it. You could write the following, but I've never actually seen a program use it.

Q: Does the the definition of main have to appear first?

A; No. Methods in a class may be defined in any order, unlike some languages (eg, C++).

Q: Doesn't defining this method make the program more complicated?

For this simple kilometers to miles conversion it isn't worth the effort to write a method. However, if this was a realistically large program, and if this kind of conversion had to be performed in several places in the program, it would be much better to put the conversion in a method so that there would be no errors, for example, when typing the constant 0.621. This small method is just practice.

Are parameters passed by reference or passed by value?

The phrase "pass by reference" means that a reference to the actual parameter *variable* is passed, not the value that the variable contains.

When you pass the value of a variable, even if it's a reference, it's called "pass by value", which is Java's only way of passing parameters.

C++ has both "pass by reference" and "pass by value"; Java only has pass by value (altho those values often happen to be themselves references).

The most dramatic demonstration of this is that it's impossible to define swap(a, b) in Java! For you Java programmers, this is a very useful C++ function that exchanges the values of a and b, which you have to do awkwardly in Java with

temp = a;
a = b;
b = temp;
Facing Programming Problem?
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

0 comments so far (post your own) View All Comments Latest 10 Comments:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.