Google
 
Site navigation: [ Home | Theory | Java | Moodle courses | Resource wiki | About ]

High Level Language Constructs

Students should be able to:

Declare identifiers and types with appropriate scope.

Distinguish between private and public identifiers .

The term variable is often used in High Level Language programming.

Variables are areas of storage accessible by a unique name (identifier). Identifier is a general term given to names that a programmer defines.

Variables have to be of a specific type . This is so that the computer can intepret the 1's and 0's found at a given memory location since they could represent numbers , names or other kinds of data (see also 3.5.1).

The specific primitive types used in JETS are:

  Type keyword
  integer int
  long integer long
  real number double
  character char
  boolean boolean

Other types are used by the Java language but will not appear in examination questions.

Java methods can be private, protected or public in scope:

private indicates the method can only be accessed (called) from within the Class in which it is defines.

protected (not part of JETS but part of Java) indicates the method can be called from the defining Class and any Class which extends (inherits from) that Class - the sub-classes.

public indicates that the method is accessible from any Class.

Identifiers such as variables which are declared in the Class body are accessible to all methods in the class (whether those methods are public or private).

Identifiers declared within a method are private to that method - they can't be accessed outside the method body. Primitive parameters are also local to the method in which they are defined.

public class VideoTape
{
  // data members - accessible only within this class
  private String title;
  private int length;
  private boolean lent;
  // Example public method - accessible outside the class
  public void setLent( boolean lent ) { this.lent = lent; }
  // Example private (sometimes called helper) method
  private boolean checkLength(int length)
  {
    // private identifier, cannot be used outside this method
    boolean good = true;
    if (length < 0)
      good = false;
    return good;
  }
}

 

This page deals with objective 2.1.1 which is concerned with the syntax of Java programs.

Students can also learn by following the topics in the Java core link (above).


 
The site is partly financed by advertising revenue, partly by online teaching activities and partly by donations. If you or your organisation feel these resouces have been useful to you, please consider a donation, $9.95 is suggested. Please report any issues with the site, such as broken links, via the feedback page, thanks.

Questions or problems related to this web site should be addressed to Richard Jones who asserts his right to be identified as the author and owner of these materials - unless otherwise indicated. Please feel free to use the material presented here and to create links to it for non-commercial purposes; an acknowledgement of the source is required by the Creative Commons licence. Use of materials from this site is conditional upon your having read the additional terms of use on the about page and the Creative Commons Licence. View privacy policy.

Creative Commons License


This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. © 2001 - 2007 Richard Jones, PO BOX 246, Cambridge, New Zealand; This page was last modified: July 29, 200823, 2008