مثال

public static void main( String[] args ) {
System.out.println( "Hello" ); //$NON-NLS-1$
System.out.println( "Bye" ); //$NON-NLS-1$
System.out.println( "Hello" ); //$NON-NLS-1$
}

الحل
تعريف الثابت
  1. تعريف الثابت باسم ذو معنى لتمثيل مجموعة الحروف حرفيا.
  2. استبدال كل التكرارات لمجموعة الحروف ذات المراجع لتعريف الثابت.

public static void main( String[] args ) {
System.out.println( HELLO );
System.out.println( BYE );
System.out.println( HELLO );
}

private static final String HELLO = "Hello"; //$NON-NLS-1$
private static final String BYE = "Bye"; //$NON-NLS-1$