Java
From StudyWiki
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
- Java programs consist of class declarations containing method and data member declarations, and comments to explain them.
- Each class is contained in a separate file.
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).
- Java programs composed of one or more classes: predefined or written by programmer
- Class members are either methods or data members.
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:
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
- only primitive values are truly stack resident
- objects/arrays are always created by calling new
- variables are copied by value
- occurs when assigning, initialising, or during parameter passing
- reference variables also copied by value
