Programming Languages
A Dave Hillman Project

[Home] [Contact Me] [Site Map] [Search] [References]

Java

 

[Up]

[Language Basics]
[C Language]
[C++]
[C#]
[Java]
[JavaScript]
[Visual Basic 6.0]
[VBScript]
[VB.Net]
[.Net Technology]

 

 

 

Introduction

bulletJava was developed by Sun Microsystems.  In theory, there are 3 reasons how Java differs from other languages such as C++:
  1. Java applications can run on any hardware platform that has a Java Virtual Machine (JVM) installed.
  2. It has a number of built-in facilities for dealing with networks (i.e., the Internet).
  3. It can be used to build both standalone and embedded applications.
bulletJava uses a form of memory management called garbage collection that enables very stable, long-lasting applications to be developed and run continuously.
bulletJava syntax is very similar to C/C++ enabling a faster transition to Java development for developers in C/C++ environments.
bulletFor the record: Java and JavaScript, while they share a common syntax, are entirely different languages.

Language Fundamentals

Program Structure and Organization

bulletJava program building blocks:
bulletJava programs are organized by "classes" which are groups of features designed to accomplish specific tasks. 
bulletA class is actually a template that is used to create objects for the program.
bulletA class is defined as follows:
bulletclass  -  a keyword
bulletclassName  - the name of the class being defined, e.g., class myClass(
bulletClasses generally support inheritance:
bulletThe sending class is called the superclass.
bulletThe receiving class is called the subclass.
bulletThe "new" keyword defines the creation of an object from a class called instances:  e.g., myClass sourceclassName = new myClass()
bulletThe receiving class can extend the behavior or capabilities of the sending class.
bulletMethods are features of classes that are used to perform various actions:
bulletreturnType: the type of data returned by the method (void is used when no data is returned).
bulletmethodName: the name the method.
bulletparametersList: the input values for the method
bullete.g., returnType methodName (plist1, plist2) (
bulletMethods may be public, private, protected, and default
bulletMethods are called by the object name and specific method using dot notation: objectName.methodName();
bulletCommenting code: uses the same commenting scheme as C.
bulletLanguage/character sets: Java natively supports the ASCII character set and is capable of unicode support and other character sets.
bulletSource code management:
bulletJava classes are organized into files called packages.
bulletPackages can be imported into applications depending on their needs.
bulletProgram delivery:
bulletJava programs are compiled into bytecode which is a highly optimized code that is executed by the Java Virtual Machine or JVM.
bulletThe JVM is platform, hardware and operating system, specific.
bulletJava programs can be run as:
bulletEmbedded applications within other programs such as web browsers.
bulletSupport programs for other applications, e.g., to support a web server application.
bulletStandalone programs complete with user interfaces (command line, windows/GUI).

Data Types

Java, unlike C, offers a fixed set of data types that are independent of hardware platforms.

bulletPrimitive types:
bulletbyte - 8 bits, -128 to 127, initializes to 0
bulletshort - 16 bits, -32768 to 32767, initializes to 0
bulletint -- Integer - 32 bits, -2,147,483,648 to 2,147,483,647, initializes to 0
bulletlong - 64 bits, -9,223,372,036,854,775,808 to -9,223,372,036,854,775,807, initializes to 0
bulletFloating point:
bulletfloat -  32 bits, 1.4E-45 to 3.4E+38, initializes to 0.0d
bulletdouble - 64 bits, 4.9E-324 to 1.7E+308, initializes to 0.0d
bulletOther types:
bulletchar - 2 bytes per character (first 128 bits represent ASCII)
bulletboolean - True or False, does not convert to numbers, initializes to False
bulletVariables:
bulletDefined by a type (see above)
bulletAre assigned a name.
bulletMay be initialized with a value.
bulletLocal and global variables are supported in classes.
bulletConstant variables may be created using the static keyword.
bulletVariables my be "casted" (casting) allow one variable type to be converted to another (e.g., string to integer).
bulletArrays: Java supports arrays, including multidimensional arrays.  Arrays are 0 referent.  Brackets are used to define and manipulate array elements.

Expressions and Operators

Java shares a set of expressions and operators that are very similar to C/C++:

bulletMath operators (and precedence):
bullet* Multiplication
bullet/ Division
bullet+ Addition
bullet- Subtraction and negation
bullet% Modulus
bullet~  1s complement
bullet++ increment
bullet--   decrement
bulletAssignment operators:
bullet=
bulletRelational operators:
bullet==  equals
bullet>, >=   -- greater than, greater than/equal
bullet<, <=   --less than, less than equal
bulletLogical operators:
bullet& logical AND
bullet|, || logical OR (first is a short circuit OR, the second checks both sides of the equation)
bullet! logical negation
bullet^ XOR

Control Statements

Java uses a set of control statements that are very similar to those found in C/C++:

bulletIf-then
bulletEvaluate statements if expression is true for if condition or subsequent else conditions.
bulletIncludes if, if-then logic; complex Boolean evaluation.
bulletShort-circuit if first logical expression is found false.
bulletExamples:

if (expression) statement;

if (expression)  {
    statement;
    statement;
    ....  }

if (expression)  {
    statement;
    statement;  }
else
     statement;

if (expression)  {
    statement;
    statement;  }
else  {
    statement;
    statement;  }

if (expression)  {
    statement;
    statement;  }
else if (expression)
     statement;

bulletSwitch
bulletEvaluate expression based on truth of condition.
bulletExpression is a value to be evaluated in subsequent cases.
bulletExamples:

switch (expression) statement

switch ( command )
    case 'A': statement
    case 'B': statement

 

bulletDo/While loop
bulletEvaluate until expression evaluates to true.
bulletDo/while evaluates following the loop.
bulletWhile loops evaluate prior to the loop start.
bulletExamples:

do {
    statement;
    statement;
    ...  }
while (expression)

while (expression) {
    statement;
    statement;
    ...  }

 

bulletFor loop
bulletLoop based upon initial, goal, and modification.
bulletExample and syntax:

for (expression1; expression2; expression3)
        statement...

expression1 - initial value
expression2 - goal value
expression3 - modify value or function

 

bulletContinue
bulletOnly used in a loop; jumps over remainder of a loop to the test condition.
bulletBreak
bulletUsed in a loop to exit the loop.
bulletReturn
bulletSends a value (or void) to the calling object.
bulletException handling
bulletJava supports a Try-Throw-Catch paradigm to manage exception handling.

 

Input/Output

bulletKeyboard and direct screen output (command line interface) is possible via Java.
bulletBrowser and desktop applications may be supported by libraries offering screen objects via the java.awt library including:
bulletText boxes, areas, and labels
bulletList boxes
bulletRadio and check boxes
bulletMenus and dialog boxes.
bulletGraphics support
bulletText and fonts
bulletImages
bulletAudio clips
bulletColors
bulletFile I/O:
bulletJava file I/O is not allowed in web browser applets.
bulletJava supports a complete range of file and network I/o via the java.io and java.net libraries.
bulletDatabase: database support is available via operating system based tools and interfaces to commercial database applications.

Libraries and Support

Java, like C, is a relatively small language, with a powerful library to support application development.

Libraries are stored in directories that are accessible to the Java Virtual Machine.

Java libraries include:

bulletApplet (java.applet) - supports web browser development.
bulletjava.lang - supports objects, classes, strings, wrappers, threads, math, error handling, and runtime classes.
bulletjava.util - supports bit operator support, dates, dictionaries, hashtables, randomizers, strings, and vectors.

Resources

References

bulletGoogle Directory: http://directory.google.com/Top/Computers/Programming/Languages/Java/
bullet Java FAQ
bullet The Java Language Environment: A White Paper New to Java Programming Center

Tutorials

bulletTutorial from How Things Work: http://computer.howstuffworks.com/program.htm
bullet The Java Tutorial
bullet Introducing Java - Your First Applet
bullet Java: the new language for Internet applications
  

 

 

 

[Home] [Language Basics] [C Language] [C++] [C#] [Java] [JavaScript] [Visual Basic 6.0] [VBScript] [VB.Net] [.Net Technology]

Copyright © 2003-2005 by Dave Hillman