📄 017-019.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=017-019//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="014-017.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="019-022.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading7"></A><FONT COLOR="#000077">The Ugly</FONT></H4>
<P>No language is perfect, and Java has its design flaws. Some of them are harmless, if ugly. Others, such as the fragile base class problem, could limit Java’s suitability for large software system development.
</P>
<P><FONT SIZE="+1"><B>Arrays Can Be Allocated with Two Styles</B></FONT></P>
<P>Java supports the C and Java style of array allocation. In fact, the two styles are supported within the same statement. Thus, the following are three syntactically acceptable ways of specifying a two-dimensional array of <I>ints</I>:</P>
<!-- CODE SNIP //-->
<PRE>
int [][] i = new int[3][3];
int j[][] = new int[3][3];
// and now we put the <I>Ug</I> in <I>Ug</I>ly!
int [] k [] = new int[3][3];
</PRE>
<!-- END CODE SNIP //-->
<P><FONT SIZE="+1"><B>Java Has Fragile Base Classes</B></FONT></P>
<P>Java suffers from the fragile base class and the fragile interface problem. In Java, an interface can be used to store constants and to permit class and method specifications. For example, the DiffCAD program (used as a central example in this book) has an interface called <I>Constants</I> that contains a list of commonly held constants. Here is one line in <I>Constants</I>:</P>
<!-- CODE SNIP //-->
<PRE>
final double Pi_on_2 = Math.PI/2;
</PRE>
<!-- END CODE SNIP //-->
<P>Suppose we add this line:
</P>
<!-- CODE SNIP //-->
<PRE>
final double Pi_on_4 = Math.PI/4;
</PRE>
<!-- END CODE SNIP //-->
<P>This code requires that every source code file that refers to <I>Constants</I> (in DiffCAD’s case, seven files) to be recompiled. Including the linking phase, the recompilation takes 56 seconds on the authors machine, a PowerMac 8100/100 MHz with a PowerPC 601 and 72MB RAM. Another example is the abstract base class <I>Computation</I>. When <I>Computation</I> is altered, five files require recompilation; including the linking phase, 70 seconds elapse before the program begins to run. Thus, when programs become large, the fragile base class and fragile interface can seriously hamper programmers’ productivity [Lewis].</P>
<P><FONT SIZE="+1"><B>“Appletcations” Are Confusing</B></FONT></P>
<P>The Java language has become a source of continuous confusion regarding the difference between an applet and an application. A package of classes in the core Java API is called the <I>java.applet</I> package, a very unfortunate naming convention. Within the <I>java.applet</I> package is a class called the <I>Applet</I> class. The <I>Applet</I> class is extended to create subclasses. Instances of <I>Applet</I> subclasses are called <I>Applets</I>.</P>
<DL>
<DD><B>Definition 1.1</B> An <I>applet instance</I> is an instance of a class that extends the Applet class.
<DD><B>Definition 1.2</B> An <I>application instance</I> is an instance of a class that contains a <I>main()</I>.
<DD><B>Lemma 1.1</B> To run a Java application, it is necessary and sufficient both to have a <I>main()</I> and to invoke the <I>main()</I>.
<DD><B>Corollary 1.1</B> Having a <I>main()</I> in a Java program is a necessary but not sufficient condition for running a Java application.
<DD><B>Lemma 1.2</B> To run a Java applet it is necessary and sufficient to extend the Applet class, implement the <I>init()</I>, and invoke the <I>init()</I>.
<DD><B>Corollary 1.2</B> Subclassing the <I>Applet</I> class in a Java program is a necessary but not sufficient condition for running a Java applet.
</DL>
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE: </B>Corollary 1.1 follows directly from its parent, lemma 1.1. Similarly, corollary 1.2 follows from its parent, lemma 1.2. Definitions do not follow the construction of the lemmata.<HR></FONT>
</BLOCKQUOTE>
<P>In common use, the term <I>applet</I> has come to mean “a small Java application run from within a browser.” We class such definitions as strictly incorrect. The following code is a segment of a large application, called DiffCAD, that dispatches a large number of different applets from within a Java application.</P>
<!-- CODE //-->
<PRE>
if (arg.equals(“benchmark”)) {
AppletFrame w = new
AppletFrame(“BenchmarkApplet”);
String title =”BenchmarkApplet”;
String args[] ={“”};
w.startApplet(“BenchmarkApplet”,title,args);
}
if (arg.equals(“surface”)) {
AppletFrame w = new AppletFrame(“surface”);
String title =”surface”;
String args[] ={“”};
w.startApplet(“surface”,title,args);
}
if (arg.equals(“search yahoo”)) {
AppletFrame w = new AppletFrame(“Wa hoo!”);
String title ”Search Yahoo”;
String args[] ={“”};
w.startApplet(“SearchYahoo”,title,args);
</PRE>
<!-- END CODE //-->
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="014-017.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="019-022.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 + -