Arvutiteaduse instituut
  1. Kursused
  2. 2018/19 kevad
  3. Objektorienteeritud programmeerimine (Narva Kolledž) (LTAT.NR.003)
EN
Logi sisse

Objektorienteeritud programmeerimine (Narva Kolledž) 2018/19 kevad

  • Home
  • Materials
  • Java Glossary
  • Source Example
  • Cheat sheet (S1-S6)
  • Grading
  • Links

Java Source File Example

The following example shows how to format a Java source file containing a single public class.

Pay attention to capitalization, comments and spaces.


package java.blah;

import java.blah.blahdy.BlahBlah;

/**
 * Class description goes here.
 *
 * @version 1.10 04 Oct 1996
 * @author Firstname Lastname
 */
public class ClassName extends SomeClass {
   /* A class implementation comment can go here. */

   /** classVar1 documentation comment */
   public static int classVar1;

   /*
    * classVar2 documentation comment that happens to be
    * more than one line long
    */
   private static Object classVar2;

   /** instanceVar2 documentation comment */
   protected int instanceVar2;

   /** instanceVar3 documentation comment */
   private Object[] instanceVar3;

   /**
    * ...constructor ClassName documentation comment...
    */
   public ClassName() {
       // ...implementation goes here...
   }

   /**
    * ...method doSomethingElse documentation comment...
    * @param someParam description
    */
   public void doSomethingElse(Object someParam) {
       // ...implementation goes here...

       // IF statements
       if (a == 2) {
           return TRUE;               /* special case */
       } else {
           return isprime(a);        /* works only for odd a */
       }

       // IF statements using alpha notation
       alpha = (aLongBooleanExpression) ? beta : gamma;     

       // FOR loop
       for (int i = 0; i < maxLoops; i++) {
           statements;
       }  

       // WHILE loop
       while (d++ = s++) {
           statements;
       }

       // SWITCH operator
       switch (variableName) {
       case ABC:
           statements;
           /* falls through */
       case DEF:
           statements;
           break;
       case XYZ:
           statements;
           break;
       default:
           statements;
           break;
       }

       // TRY-CATCH operators
       try {
           statements;
       } catch (ExceptionClass e) {
           statements;
       }

   }

}

Resource: Java Code Conventions

  • Arvutiteaduse instituut
  • Loodus- ja täppisteaduste valdkond
  • Tartu Ülikool
Tehniliste probleemide või küsimuste korral kirjuta:

Kursuse sisu ja korralduslike küsimustega pöörduge kursuse korraldajate poole.
Õppematerjalide varalised autoriõigused kuuluvad Tartu Ülikoolile. Õppematerjalide kasutamine on lubatud autoriõiguse seaduses ettenähtud teose vaba kasutamise eesmärkidel ja tingimustel. Õppematerjalide kasutamisel on kasutaja kohustatud viitama õppematerjalide autorile.
Õppematerjalide kasutamine muudel eesmärkidel on lubatud ainult Tartu Ülikooli eelneval kirjalikul nõusolekul.
Courses’i keskkonna kasutustingimused