Java

From StudyWiki

Jump to: navigation, search


Contents

Overview

Java is an object orientated programming language by Sun Microsystems.

Java Standard Naming Conventions

  • Names can only contain letters, digits, underscores, or dollar signs.
  • Names are case sensitive.
  • First letter must be a character.


Packages

  • All package names have lower case letters.


Program Structure


Class Declarations

Class Declaration Syntax
class <classname> {
<class member declarations>
}


Class Naming Conventions
  • Names can only contain letters, digits, underscores, or dollar signs.
  • Names are case sensitive.
  • First letter must be an upper case character.
  • Where names/identifiers have multiple words, the first letter of all words after the first will be upper case (don't use underscores for spaces).



Import Statements

Import Statement Syntax
For importing a specific class:
import <packagename> . <classname> ;
For importing all classes in a package:
import <packagename> . * ;
  • Predefined classes are stored in packages.
  • Packages can be nested.
  • 2 ways of using predefined classes:
    • Using the fully qualified name to point to the class location using dot notation.
      • E.g. <packagename> . <classname>
    • Or, using an import statement, which establishes a reference to the class(es) so you only need to use the class name in the rest of the program.


Compiling and Running Java Programs

  • Java is compiled into platform-independent bytecode.
  • The Java Virtual Machine (JVM) interprets bytecode into machine code that a computer can execute.
  • The JVM is available for many different operating system.


This means that one program, compiled into bytecode, will run on any system with the JVM regardless of operating system.


Memory Model


See Also

Personal tools