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 Notes

Methods - Declaring

Declaration syntax

Notation: Everything between square brackets, "[" and "]", is optional.

[access] [static] [type] name( [parameters] ) { body }

access If no scope is given, a method has package scope. Other comon values for scope are public (everyone can see it) and private (can only be seen from within this class). For small programs don't worry about scope. However, for applets you need to declare init() and paintComponent() methods to be public so that the browser and Java GUI code can see them. If you are writing an application, you must declare main(...) to be public so the operating system can call it.
static The static keyword is used to declare class methods -- methods that don't refer to a specific object. The only method that you will probably declare this way is main.
type Any Java type, including arrays, can be written here to tell what data type value the method returns. Use void if the method doesn't return a value.
Note: There are also other, less frequent, modifiers that we won't discuss here (protected, synchronized, final, abstract, native)

Parameters

Formal parameters are the parameters that are written in the method definition. These are the names that you use in your method. Formal parameters are like local variables that get an initial value at the time the method is called.

Actual parameters or arguments are the values that are written in the method call. The actual parameter values are copied into the formal parameters, which are then like initilialized local variables.

Local Variables

Variables that you declare in a method are called local variables. They are created on a call stack when the method is entered, and they are destroyed when the method returns. Because objects (eg Strings and arrays) are allocated in the heap, they are never in the call stack and can be returned from the method.

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.

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:
  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.