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

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


 

Java Tutorials


 

 

Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Java: Summary - Basic Elements

 

In this section we will see how to comment your Java code.

 

We will also see the Identifiers and Keyword of Java API.

 

Properly commenting the Java code is very important. Commenting the programming code is one of the best practices of good programming. You should always comment your Java code properly.

 

Java provides three different methods of commenting the code.

 

Following table summarizes the different methods of commenting code.

a) Use // for commenting

b) Use /* .... */ for commenting

c) Use /** ..... */ for commenting in Java code

 

Java compiler ignores the text marked as comment.

 

Comments

// Everything to the end of the line is ignored. Use for most comments.
/* Everything (possibly many lines) is ignored until a */. Uncommon. Use for commenting out code.
/** Used for automatic HTML documentation generation by the javadoc program. */

Identifier Names

  • Start identifiers with an alphabetic character (a-z or A-Z), and continue with alphabetic, numeric (0-9), or '_' (underscore) characters. Do not use $.
  • Second words in a name should start with an uppercase letter.
  • Do not use keywords (see below).
  • Class and interface names should start with an uppercase letter (Graphics, ActionListener, JButton, ...)
  • Variable and method names should start with a lowercase letter (repaint(), x, ...).
  • Constants should be all uppercase with underscores between words (BoxLayout.X_AXIS, Math.PI, ...).

Keywords

The keywords are divided into three categories by expected student usage. Maybe try, catch, and assert are more common.

CategoryVery commonLess CommonUncommon
Primitive Types boolean char double int true false byte float short long
Control Flow if else while for switch case break default return assert do try catch continue finally throw synchronized
OOP class extends implements new null this enum interface super instanceof
Declarations public private import package static final void throws protected transient volatile native
Other strictfp goto const

Variables - Local, Instance, Class

Variables may be local, instance (field), or static (class) variables. Formal parameters are local variables that are assigned values when the method is called.
local instance static / class
Where declared In a method. In class, but not in a method. In class using static keyword.
Initial value Must assign a value before using. Compiler error if you don't. Zero for numbers, null for objects, false for boolean. Or initialized in constructor. Zero/null/false or initialized in static initializer.
Visibility Only in the same method. No visibility may be declared. private: Only methods in this class. Default: All methods in same package. public: Anyone can see it. protected: This class and all subclasses can see it. Same as instance.
When created When method is entered. When an instance of the class (object) is created with new. When program is loaded.
Where in memory Call stack. Heap. "Permanent" memory.
When destroyed When the method returns. When there are no more references to the object. When program terminates.

Copyright 2005 Fred Swartz
Ask programming questions?

 

 

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

 

 
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.

[an error occurred while processing this directive]