JAVA Features)
JAVA Features)
What is java?
Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++
Object oriented
focus on the data (objects) and methods manipulating the data all functions are associated with objects almost all datatypes are objects (files, strings, etc.) potentially better code organization and reuse
Portable
same application runs on all platforms the sizes of the primitive data types are always the same the libraries define portable interfaces
Secure
usage in networked environments requires more security memory allocation model is a major defense access restrictions are forced (private, public)
Dynamic
java is designed to adapt to evolving environment libraries can freely add new methods and instance variables without any effect on their clients interfaces promote flexibility and reusability in code by specifying a set of methods an object can perform, but leaves open how these methods should be implemented can check the class type in runtime
Java Disadvantages
Slower than compiled language such as C
an experiment in 1999 showed that Java was 3 or 4 times slower than C or C++
title of the article: Comparing Java vs. C/C++ Efficiency Issues to Interpersonal Issues (Lutz Prechelt)
Environment Setup
Sun Solaris OS JDK 1.4 (latest: J2SE 5.0) You can use the lab at CL112. Please follow the steps:
log into the Unix environment subscribe to JDK-CURRENT when you log in for the first time (% is a prompt sign) %> subscribe JDK-CURRENT and then log out by clicking on the EXIT button on the control panel
Java is
CASE SENSITIVE!
if you see one of these errors, you have two choices: 1) specify the full path in which the javac program locates every time. For example:
C:\j2sdk1.4.2_09\bin\javac HelloWorldApp.java
Note that the command is java, not javac, and you refer to HelloWorldApp, not HelloWorldApp.java or HelloWorldApp.class
Exception in
HelloWorldApp
if you see this error, you may need to set the environment variable CLASSPATH.
Array types
Variables
dataType identifier [ = Expression]: Example variable declarations and initializations:
int x; x=5; boolean b = true; Frame win = new Frame(); String x = how are you?; int[] intArray; intArray = new int[2]; intArray[0] = 12; intArray[1] = 6; Person pArray = new Person[10];
Supplemental reading
Getting Started
http://java.sun.com/docs/books/tutorial/getStarted/index.html