📄 012-014.html
字号:
<HTML>
<HEAD>
<META name=vsisbn content="1558515682"><META name=vstitle content="Java Digital Signal Processing"><META name=vsauthor content="Douglas A. Lyon"><META name=vsimprint content="M&T Books"><META name=vspublisher content="IDG Books Worldwide, Inc."><META name=vspubdate content="11/01/97"><META name=vscategory content="Web and Software Development: Programming, Scripting, and Markup Languages: Java"><TITLE>Java Digital Signal Processing:Java and Its Promise</TITLE>
<!-- HEADER --><STYLE type="text/css"> <!-- A:hover { color : Red; } --></STYLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<!--ISBN=1558515682//-->
<!--TITLE=Java Digital Signal Processing//-->
<!--AUTHOR=Douglas A. Lyon//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=1//-->
<!--PAGES=012-014//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="011-012.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="014-017.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>Java Has Exceptions</B></FONT></P>
<P>Java has a form of control structuring known as <I>exception handling</I>. Exception handling is a provision for handling abnormal circumstances that can prevent successful execution: subscript boundary violation, division by zero, overflow, I/O errors (from unavailable files or insufficient disk space), and so on. Java’s exception handling mechanism can prevent a program from terminating abnormally. Exception handling is not a new idea and has been widely available in some languages (such as Ada, COBOL, C++, Delphi (<A HREF="http://www.borland.com">http://www.borland.com</A>), PL/I, and ZetaLisp) but not in others (such as BASIC, FORTRAN, Pascal, and C) [Goodenough]. Java’s exception handling is closer to that of ZetaLisp than to that of any other language. Exceptions are subclassed in Java and so are treated in an object-oriented fashion (as opposed to their treatment in Ada, COBOL or PL/I).</P>
<P>The Java language specification identifies compile-time and run-time errors. For example, accessing an array index out of bounds is a run-time error, according to the Java specification [Gosling et al.]. In C, the effect is dependent on the operating system. For example, in Solaris (a Sun operating system), this error causes a segmentation fault and a core file is dumped. On Windows 3.x/95 or MacOS, the computer crashes. Windows NT may handle the error with a little more grace, but Java issues the following message:</P>
<!-- CODE SNIP //-->
<PRE>
java.lang.ArrayIndexOutOfBoundsException: 10
at TrivialApplet.test(TrivialApplet.java:18)
at TrivialApplet.main(TrivialApplet.java:12)
</PRE>
<!-- END CODE SNIP //-->
<P>This alternative is civilized compared with crashing the computer.
</P>
<P><FONT SIZE="+1"><B>Java Has Threading</B></FONT></P>
<P>Threading is a built-in feature of Java. A <I>thread</I> is a low-overhead context switch that enables a processor to change from one task to another very quickly. All the threads in Java could execute in parallel if the Java virtual machine existed that could take advantage of multiple processors. This is not the case, however, so only one thread can run at a given time (as of this writing). Threading is a high-level concurrent programming facility. In addition to Java, several other languages provide a high-level concurrent programming facility. Examples include Concurrent C, Concurrent C++, Concurrent Pascal, Concurrent Euclid, Modula-2, and Ada [Gehani].</P>
<P>In the past, multiple threads were programmed using support from the operating system. Java abstracts this relationship with the operating system by specifying how the virtual machine will behave when threading. There is nothing in the Java threads API that requires any operating-system involvement. In fact, the thread library of Solaris, on the Sun workstation, is unused in Java 1.0.</P>
<P><FONT SIZE="+1"><B>Java Has a Uniform Floating-Point Specification</B></FONT></P>
<P>Java uses the IEEE 754-1985 floating-point specification as a part of its language definition. Thus, round-off errors can be predicted in a platform-independent manner.
</P>
<P><FONT SIZE="+1"><B>The Compilers Are Getting Fast</B></FONT></P>
<P>Java’s compiler technology is improving. For example, just-in-time (JIT) compilers permit Java’s “compile once, run anywhere” model to be as fast as compiled native code. The just-in-time compilers take the Java byte codes and compile them to native machine language. Our benchmark indicated an 18-fold increase in speed over interpreted byte codes.
</P>
<P>This speed comes at a cost. Start-up time may be longer, although we could not verify this. Also, the JIT compiler is supposed to take more RAM, although we could not verify this, either. The overall increase in speed more than made up for any initial start-up costs on the DiffCAD program. Our benchmark was performed with a Metrowerks compiler running under MacOS. JIT compilers are not available on all platforms. If they were they would probably replace the interpreter model.</P>
<P><FONT SIZE="+1"><B>Strings Are First-Class Objects</B></FONT></P>
<P>Strings are not character arrays; rather they are instances of the <I>String</I> class. Thus, you must access them via method invocation and not as you access the array of characters in Pascal, C, or C++. This is a much cleaner way to manipulate strings and leads to better code.</P>
<P><FONT SIZE="+1"><B>Identifiers Have Unlimited Length</B></FONT></P>
<P>According to the Java language specification, identifiers may have an unlimited length. We have verified this for some very large values. For example:
</P>
<!-- CODE //-->
<PRE>
int
ThisIsAVeryLongNameInJavaWithMoreCharactersThanOneWould
TypicallyUseYouMayUseNumbers1234567890ButNoOperators=0;
int
ThisIsAVeryLongNameInJavaWithMoreCharactersThanOneWould
TypicallyUseYouMayUseNumbers1234567890ButNoOperatorsAnd
TheyAreUnique=1;
System.out.println(ThisIsAVeryLongNameInJavaWithMore
CharactersThanOneWouldTypicallyUseYouMayUseNumbers1234567890
ButNoOperators+
ThisIsAVeryLongNameInJavaWithMoreCharactersThanOneWould
TypicallyUseYouMayUseNumbers1234567890ButNoOperatorsAndThey
AreUnique
);
</PRE>
<!-- END CODE //-->
<P>The same principle should apply, in theory, to class names. Some development systems require that public classes be stored in files whose names match the class name. For these systems, it is not possible to have a public class identifier that exceeds file-name length limitations. These are implementation dependencies and not limitations imposed by the Java language specification.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="011-012.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="014-017.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright © <a href="/reference/idgbooks00001.html">IDG Books Worldwide, Inc.</a></font></div>
<!-- all of the reference materials (books) have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --></BODY></HTML><!-- END FOOTER -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -