Web Developer's Virtual Library: Encyclopedia of Web Design Tutorials, Articles and Discussions


WDVL Newsletter

Active Server Pages
JSP/Java Servlets
Microsoft SQL Server
Daily Backup
Dedicated Servers
Streaming Audio/Video
24-hour Support    

jobs.webdeveloper.com

Hiermenus


e-commerce
Partner With Us















Developer Channel
FlashKit.com
JavaScript.com
JavaScriptSource
Developer Jobs
ScriptSearch
StreamingMediaWorld
Web Developer's Journal
Web Developer's Virtual Library
WebDeveloper.com
Webreference
Web Hosts
XMLfiles.com

internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Comments

Fundamental Programming Standards

  • Just as we saw in Perl, Java uses the standard syntax for defining the parts of a program. For example, all commands are ended with a semicolon(;)
    	int i = 5;
    
  • Similarly, all blocks of code are defined by curly braces such as in the following example:
    if (i <10)
      {
      System.out.println("i is less than 5);
      }
    
  • This type of programming should be very familiar for you from yesterday.

Comments

  • Just as you could use the number sign (#) to let the Perl interpreter know that a line in the code was a comment, you can specify comments in Java.

  • Actually, there are several ways to denote comments in Java.

  • For single line comments, you can use the "//" notation. For example, consider the following code:

    		// Initialize variables...
    int age = 28;	// Declare and initialize age
    

  • Single line comments can be defined on the same line as your code or on their own line

  • To specify multiline comments, however, you will use the "/*" and "*/" combination such as in the following example:

    /*
    This is a sample class which is used to demonstrate
    the use of multi-line comments.  it was written by
    Selena Sol for the Web Programming Tutorial
    */
    
    	// Define an Example class with a single
            // main() method which will print out
            // "Hello Cyberspace!" to standard output.
    
    public class Example
      {
      public static void main(String[] args)
        {
        System.out.println("Hello Cyberspace!");
        }
      }
    
    

  • As you can see, if you use the "//" notation and your comment spans multiple lines, you must begin each new line with a "//" combination.

  • Finally, if you are writing comments which should be included as part of a javadoc document, you should use the "/**" "*/" combination such as in the following example:

    /*
    This is a sample class which is used to demonstrate
    the use of multi-line comments.  it was written by
    Selena Sol for the Web Programming Tutorial.  This comment
    does not appear in the java documentation
    */
    
    	/** 
            Define an Example class with a single
            main() method which will print out
            "Hello Cyberspace!" to standard output.
            This comment appears in the javadoc.
            */
    
    public class Example
      {
      public static void main(String[] args)
        {
        System.out.println("Hello Cyberspace!");
        }
      }
    

Additional Resources:

Setting Your Development Environment
Table of Contents
Printing to Standard Output


Up to => Home / Authoring / Scripting / Tutorial




Jupiter Online Media: internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and Jupiter Online Media

Jupitermedia Corporate Info


Legal Notices, Licensing, & Permissions, Privacy Policy.

Web Hosting | Newsletters | Tech Jobs | Shopping | E-mail Offers