Jets Java Subset For IB Computer Science
Jets Java Subset For IB Computer Science
Introduction
The object-oriented programming (OOP) option of the IB computer science syllabus allows students to learn to program in Java, and this is a choice that most teachers would reasonably be expected to makealthough the IB does not insist that this is so. It would be unreasonable to expect students to learn all of Javawith the many libraries and classes and the constantly changing nature of the language that would be impractical. The intention is not for students to become Java experts. The intention is to provide an unambiguous representation of essential OOP concepts for the examination. Teachers should note that sample algorithms can be found in the teacher support material for this course. Only the commands, symbols and constructs specified in JETS will be used in examination questions relating to the OOP option. Students will not be required to read or write answers involving other libraries. Students may have learned some other languages, constructs and classes, and may choose to use these in their examination answers. However, students are not permitted to use library classes and methods from any language, including Java, that would perform automated tasks, such as sorting and searching arrays and other collections. JETS also specifies a naming convention and style for examination questions. Teachers should familiarize their students with JETS, including the naming and style conventions. These conventions are intended to make examination questions clear and easily readable. Students are not required to follow these conventions in their answers. However, they should write answers in a clear, consistent and readable style, and must not use non-standard libraries that trivialize the solution. Students will not be expected to write perfect syntax in their answers (for example, a mistake in capitalization or a missing semi-colon would not normally be penalized) but errors that substantially change the meaning of the algorithm will be penalized (for example, forgetting an exclamation point is a real error). Students and examiners alike are expected to use the clearest, most readable style in their answers. Students should be especially careful to avoid careless writing and syntax that is difficult to read, such as double minus signs (--) or compound assignment operators like (-=). For example:
Style conventions
The style conventions for JETS to be used in all examination papers will be as follows.
Operators
Arithmetic: + , - , * , / , % (students must understand the polymorphic behaviour of the division operator, for example int / int ==> int) Relational: == , > , < , >= , <= , != Boolean: ! , && , || (bitwise Boolean operators & , | are not required)
Operator precedence
The standards for operator precedence in Java are assumed knowledge. Examination questions may use extra parentheses for clarity and candidates should be encouraged to do the same in their solutions.
Parameter passing
Parameter passing follows the standard specification in Java, for example, primitive types are automatically passed by value, and structured types (arrays and objects) have their references passed by value (usually equivalent to pass by reference of other languages).
Symbols
/* multi-line comments */ // single line // comments
( ) round brackets for parameters [ ] square brackets for subscripts in arrays . dot notation for dereferencing object methods and data members { } for blocks of code { 1 , 2 , 3 } for initializing an array < class > to permit the use of structured classes with the LinkedList class The assumed set of IBIO commands is listed below.
String input(String prompt) String input() // does not print a prompt before inputting String inputString(String prompt) char inputChar(String prompt) boolean inputBoolean(String prompt) byte inputByte(String prompt) int inputInt(String prompt)
Files
Standard level/higher level
BufferedReader(FileReader)will be used to open a sequential file for input .ready .read .readLine .close PrintWriter(FileWriter)will be used to open a sequential file for output .print .println .close // Serialization is not required.
Standard methods
Math class
.equals(String) .substring(startPos, endPos) .length() .indexOf(String) .compareTo(String) .toUpperCase() .toLowerCase() LinkedList class
.add(E e) .add(int index, E element) .addFirst(E e) .addLast(E e) .clear() .element() .get(int index) .getFirst() .getLast() .remove() .remove(int index) .removeFirst() .removeLast() .size() .isEmpty()
Arrays
--------.length
Cast
-------(int) (double) (byte) (char) (numeric + "") // to convert a numeric value to a String
Integer.parseInt(String)
converts a valid String representation of an integer to an int primitive. The IBIO input/output methods are also static. Understanding the new construct is required. Students must be aware that new causes an object to be instantiated, and that this is somewhat different from declaring a primitive data type. They should thoroughly understand the rules for scope and lifetime of identifier references, and that instances may be automatically destroyed and garbage collected when they go out of scope. For example, students must understand that a value stored in a methods local variables will be lost when the method returns, and that this value cannot be retrieved by subsequent calls to the method. Static is a required concept, but will not be directly tested in code (it may appear, but the meaning in the code will not be directly examined).
public void printNumbers() { int x = 0; while ( x < 10 ) { output( x ); } // brackets lined up horizontally } // brackets for method body lined up vertically
Class scope
public, private // implements and abstract are not included // interface is not included
Error handling
try{ ... commands ... } catch(Exception e){ ... handle the error ... };
Error handling in examinations will be limited to simply outputting an error message, setting a flag or returning from the method. Complex handling of specific Exception types will not be expected. Only the generic Exception and IOException errors must be trapped.
methodName() throws IOException // Students must understand the idea of throwing an exception, rather than trapping it with try..catch..
Example algorithms
Algorithms to exemplify JETS, the IBIO console class and additional Java-related material may be added to CSopedia.