SDSU CS 596 Java Programming
Fall Semester, 1998
Using New Features
To Lecture Notes Index
© 1998, All Rights Reserved, SDSU & Roger Whitney
San Diego State University -- This page last updated 10-Oct-98

Contents of Doc 12, Using New Features


Reference

Personal experience

Listen Here!S-oct7 6mins, Q-oct8 2mins Doc 12, Using New Features Slide # 2

Using Language Features for the First Time

Rule 1

In a separate program, test the language feature using the smallest possible program. Do this before using the feature in a "real" program.

Motivation
Small programs are fast to write, easy to understand, easy to debug

Example - Packages

In file: ~masc01146/whitney/Sample.java:

package whitney;
public class Sample {
   public void print() {
      System.out.println( "In foo");
   }
}
In file: ~masc01146/Test.java

import whitney.Sample;
class Test {
   public static void main( String[] args ){
   Sample aTest = new Sample();
   aTest.print();
   }
Set classpath:
setenv CLASSPATH  '.:/home/ma/cs596/masc01146'

Doc 12, Using New Features Slide # 3
Using Language Features for the First Time

Rule 2


Actual use Rule 1. It will save you time.


Rule 3


First get something working, then try one variation at a time.


Doc 12, Using New Features Slide # 4
Using Tech Support (or Instructors, TAs)

Tech support people (& instructors, TAs) are not mind readers nor do they have any supernatural powers.

You need to provide them with your problem and the relevant information in short message

Example Message 1
"I am having problems with packages. I followed your example. It does not work for me. My classes worked before I added the packages. What am I doing wrong?


Doc 12, Using New Features Slide # 5
Example 2
I am having problems with packages. In file: ~masc01146/whitney/Sample.java I have

package whitney;
class Sample {
   public void print() {
      System.out.println( "In foo");
   }
}
In file: ~masc01146/ whitney/Test.java

import whitney.*;
class Test {
   public static void main( String[] args ){
   Sample aTest = new Sample();
   aTest.print();
   }
I set classpath by:
setenv CLASSPATH  '.'

I then compile Test using:

javac Test.java
I then get the following error message:
Can't access class whitney.Sample. Class or interface must be public, in same package, or an accessible member class.
classNotes.java line 5    Sample aTest = new Sample();

Copyright © 1998 SDSU & Roger Whitney, 5500 Campanile Drive, San Diego, CA 92182-7700 USA.
All rights reserved.

visitors since 05-Oct-98