Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Code Conventions

Code Conventions

Ratings: (0)|Views: 6|Likes:
Published by yjenith

More info:

Published by: yjenith on Apr 17, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

06/16/2009

pdf

text

original

 
JavaCode Conventions
September 12, 1997
 
ii
PleaseRecycle
Copyright Information
1997, Sun Microsystems, Inc. All rights reserved.2550 Garcia Avenue, Mountain View, California 94043-1100 U.S.A.This document is protected by copyright. No part of this document may be reproduced in any form by any meanswithout prior written authorization of Sun and its licensors, if any.The information described in this document may be protected by one or more U.S. patents, foreign patents, orpending applications.TRADEMARKSSun, Sun Microsystems, Sun Microelectronics, the Sun Logo, SunXTL, JavaSoft, JavaOS, the JavaSoft Logo, Java,HotJava Views, HotJJavaChips, picoJava, microJava, UltraJava, JDBC, the Java Cup and Steam Logo, “Write Once,Run Anywhere” and Solaris are trademarks or registered trademarks of Sun Microsystems, Inc. in the United Statesand other countries.UNIX
®
is a registered trademark in the United States and other countries, exclusively licensed through X/ OpenCompany, Ltd.Adobe
®
is a registered trademark of Adobe Systems, Inc.Netscape Navigator
is a trademark of Netscape Communications Corporation.All other product names mentioned herein are the trademarks of their respective owners.THIS DOCUMENT IS PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS ORIMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.THIS DOCUMENT COULD INCLUDE TECHNICAL INACCURACIES OR TYPOGRAPHICAL ERRORS.CHANGES ARE PERIODICALLY ADDED TO THE INFORMATION HEREIN; THESE CHANGES WILL BEINCORPORATED IN NEW EDITIONS OF THE DOCUMENT. SUN MICROSYSTEMS, INC. MAY MAKEIMPROVEMENTSAND/ ORCHANGESIN THEPRODUCT(S)AND/ ORTHEPROGRAM(S)DESCRIBED IN THISDOCUMENT AT ANY TIME.
 
June 2, 1997iii
1Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1Why Have Code Conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11.2Acknowledgments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
2File Names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2.1File Suffixes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22.2Common File Names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
3File Organization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3.1Java Source Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .23.1.1Beginning Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33.1.2Package and Import Statements. . . . . . . . . . . . . . . . . . . . . . . . . . .33.1.3Class and Interface Declarations. . . . . . . . . . . . . . . . . . . . . . . . . .3
4Indentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4.1Line Length. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44.2Wrapping Lines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4
5Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
5.1Implementation Comment Formats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65.1.1Block Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65.1.2Single-Line Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75.1.3Trailing Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75.1.4End-Of-Line Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .75.2Documentation Comments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
6Declarations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
6.1Number Per Line. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .96.2Placement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .96.3Initialization. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106.4Class and Interface Declarations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
7Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
7.1Simple Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107.2Compound Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117.3return Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117.4if, if-else, if-else-if-else Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .117.5for Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127.6while Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127.7do-while Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127.8switch Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .127.9try-catch Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
8White Space. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
8.1Blank Lines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .138.2Blank Spaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14
9Naming Conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1410Programming Practices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
10.1Providing Access to Instance and Class Variables. . . . . . . . . . . . . . . . . . .15

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->