Fundamental

Class are declaration template for a potential objectClasses are instantiate to become an object
Class Declaration keyword class Myclass [extends Superclass] [implements Interface]{
class variablesdeclarationsstatic initializeinstance variablesconstructorsclass methodsmethodsinstance methods}
A class signature:public abstract class MyClass extends BaseClass implements MyInterface, OtherInterface
class name Can start with any alphanumeric character including $ and _
Exam Tip class 199 {} in file 199.java will compileclass $1 {} will compileclass! {} will compile
Can contain numbers after 1st char.
Source Files source file: *.java contains class declaration.byte code file: *.class is what the compiler generates.
compiler: javacJVM: java
Only one public class or interface per file. Must be same name as file.
Exam Tip Cannot have both public class and interface in a file.
Identifiers Variables Case sensitive language
Must start with letters, $ or _
Can contain numbers after 1st char.
From the unicode character set
Comments Java comments are:// – Single line/* */ – blocked
Declarations Introduce class interface, methods, package or variables.
Declaration order:package (optional)import optional)class declarationvarmethods
package Organize and group classes together
Visibility Similar function and services are placed in a package for organization
Specify access restriction to variable and methods. Hence visibility.import other classes into current code.
No package declaration is (default package)
Package java.lang.* is imported automatically.
Only one package statement can be in file.
Makes it easier to use common names
Package reflect directory structure
classpath define root directorysubclasses begin off of classpath
package com.sun.java define a subdirectory from the classpath as:../com/sun/java
Ex.Classpath=c:mypackageSource as:package trades.quotes; for file Trade.javaplace code in c:mypackagetradesquotesTo run file the entire package name must be used:java trades.quotes.Trade
java -d The “javac -d” can compile classes and generate the directory structure from the package statement.
Exam Tip Note that the Trade.java file must be in the tradesquotes directory.As specified by package description: package trades.quotes;
Java API Packages java.appletjava.awtjava.awt.datatransferjava.awt.eventjava.awt.image

java.awt.peer

java.beans

java.io

java.lang

java.lang.reflect

java.net

java.sql

java.text

java.util

java.util.zip

Applet class, sound, browser interactionGUI componentClipboardGUI event handlersHandling Images

Platform specific component

Creates reusable software components.

IO classes and interfaces, Sockets, Files and Streams

Default standard classes and interfaces for Java programs

Dynamic discovery of class components

Communication via Internet/Intranet

SQL and database

Manipulation of numbers, dates, characters and string

Manipulation of: dates, time, random number..

JAR files

java.rmijava.rmi.dgc Remote Method Invocation (Distributed Programming)
java.security Security package
import All public classes in our classpath is accessible to our program.
To use a class in package other than the one in which it is defined, you must first import that class.
By using the import keyword we don’t have to provide the fully qualified name for each class.
We can import entire package:import java.util.*;
We can import an individual class:import java.util.Date;
java.lang.* is imported automatically.
Exam Tip import java.*;Will compile, but will try to import classes within java directory. Not the java API’s.
If import is not used, the full name of the class must be used:java.applet.AudioClip;
Keywords and Reserved Words There are 48 java keywords to be memorized. Pg 21 of Java 2 Certification book.
Exam Tip const goto are keywords not used Java yet.final, finally are keywords.null, true, false are reserved words but not keywords.(??I don’t know. Some say these are literal values, some say not??)
Applet Java programs that run in a browser. Used on the Web.
An applet must extend the java.awt.Applet class.
//Packages usually usedimport java.awt.Applet;import java.awt.Graphics;import java.awt.event.*;public class xxx extends Applet {……}
<applet code=”x.class” codebase=”.” width=232 height=232> </applet>
public void init() Called once after applet is loaded and before anything as been shown on the screen.
public void start() Called when applet is downloaded and becomes visible after been hidden.
public void paint(Graphics g) Overridden method from the java.awt.Component class. Used to render (draw) the applet.
public void stop() Called when the applet is hidden.
public void destroy() Called by JVM when applet is about to be permanently disposed.
Java Programs Run by calling main() method.Don’t have to extend any classes.
main() Main method is used in java programs.
Exam Tip Signature public static void main(String arg[]) {} or,static public void main(String arg[]) {}
arg Arguments start at index 0.
Using main()
Exam Tip java myprogram var1 var2var1 is argument 0.The myprogram is not var1.
Exam Tip public void main(String arg[]) method will compile, but will not start a java program.