SDSU CS 580 Client-Server Programming
Fall Semester, 2000
Assignment 2 Comments
Previous    Lecture Notes Index    Next    
© 2000, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 20-Nov-00

Contents of Doc 22, Assignment 2 Comments


References

Student papers

Doc 22, Assignment 2 Comments Slide # 2

Assignment 2 Comments

Names


Use Java Standard name

ClassName
methodName

this_is_not_java_standard

Some Bad habits

file1
file2
flag = getFile( blah)
if (flag) then
   more blah
else
   even more blah

Doc 22, Assignment 2 Comments Slide # 3

Line Wrap


Just say no to line wrap in source code

If you have problem with line wrap in hard copy:

Place the following comment in a file:

//234567890123456789012345678901234567890etc
Make the comment long enough to insure line wrap

Print the file using the commands/printer you use to print your assignments

Determine how many columns you have before you get line wrap

Use a few columns less than that

In your source code files you can place a comment of the max length for a guide

Test out your tabs

Doc 22, Assignment 2 Comments Slide # 4

Threads


This does not start a thread:

Thread test = new Thread();
Test.run()

This does start a thread:

Thread test = new Thread();
Test.start()

But in a server this will do more harm than good:


Java threads perform differently on different platforms

Unless you are careful with threads, Java programs do not port well

Doc 22, Assignment 2 Comments Slide # 5

Positional Data


public void main(String[] args ) {
   String port = args[1];
   String file = args[2];
   etc.
Say no to positional data



For command line arguments use flags:

java Server -p 5555 -f myFile

SDSU Java library makes it easy to do this

Most languages/systems have library code to parse command line arguments!

Learn it and use it!

Doc 22, Assignment 2 Comments Slide # 6

Very Bad Coupling!



File cs325 = new File("cs325");
File cs419 = new File("cs419");
blah
if (value.equals( "Exam1") ) 
   blah
else if (value.equals( "Project 2" ))
   blahs

If the instructor adds a new assignment the program has to be rewritten

The program must be rewritten for every course that uses it

Before the program could be used in a course, the instructor must know the name of every assignment, quiz, project and test


Doc 22, Assignment 2 Comments Slide # 7

Testing


Manual verses Automatic Tests

Manual

Automated

In most cases automated unit tests are preferred over manual unit tests

JUnit test with no asserts are really manual tests

Most people know the mechanics of JUnit

Need to work on test coverage & better tests


Doc 22, Assignment 2 Comments Slide # 8

Logging


Recall that servers

Must log

try
   {
   blah
   }
catch (FileException readProblem)
   {
   // no code here
   }
What happens when the exception occurs?


Doc 22, Assignment 2 Comments Slide # 9
Logging & Debug Statements

try
   {
   blah
   Logger.log("a message");
   System.out.println( "aMessage");
   Blah
   System.out.println( "I made it here");
   }
catch (FileException readProblem)
   {
   System.out.println( "file exception occured");
   }

Sort of works in development, but what happens when you deploy?


Doc 22, Assignment 2 Comments Slide # 10
Use the Logging Debug Statements

When debugging:
SelectiveLogger activeLog = (SelectiveLogger ) ScreenLogger.register();
activeLog.debugOn();

In production:
SelectiveLogger activeLog =
   (SelectiveLogger ) FileLogger.register("fileName");
activeLog.debugOff();

Server Code:
try
   {
   blah
   Logger.log("a message");
   Blah
   Logger.debug( "I made it here");
   }
catch (FileException readProblem)
   {
   Logger.log( "file exception occured");
   }


Copyright ©, All rights reserved.
2000 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
OpenContent license defines the copyright on this document.

Previous    visitors since 20-Nov-00    Next