📄 019-022.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=019-022//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="017-019.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="022-024.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>In fact, the applet is just a kind of <I>frame</I>. It runs in its own thread and has its own <I>applet context</I>. The point is that a large program can run many applets. A Java <I>application</I> is typically a program that contains a <I>main</I>. For example, the following is an application:</P>
<!-- CODE SNIP //-->
<PRE>
public class TrivialApplication {
public static void main(String args[]) {
System.out.println( “Hello World!” );
}
}
</PRE>
<!-- END CODE SNIP //-->
<P>An <I>applet</I> is an instance of an <I>Applet</I> subclass. For example:</P>
<!-- CODE //-->
<PRE>
import java.awt.*;
import java.applet.Applet;
public class TrivialApplet extends Applet {
public void init() {
repaint();
}
public void paint( Graphics g ) {
g.drawString( “I am an Applet”, 30, 30 );
}
}
</PRE>
<!-- END CODE //-->
<P>One popular Java reference states that a <I>class</I> becomes an applet by subclassing the <I>Applet</I> class and that an applet is an “embeddable window” [Chan and Lee]. No wonder even seasoned Java programmers misuse the term <I>applet</I>.</P>
<P>To top off the example, we present an appletcation that is an extension of the <I>Applet</I> class and contains a <I>main</I>:</P>
<!-- CODE //-->
<PRE>
import java.awt.*;
import java.applet.Applet;
public class TrivialApplet extends Applet{
public void init() {
repaint();
}
public static void main(String args[]) {
System.out.println(“An Appletcation”);
}
public void paint( Graphics g ) {
g.drawString( “Hello World!”, 30, 30 );
}
}
</PRE>
<!-- END CODE //-->
<P>The preceding code may be called as an applet or as an application. When it is called as an applet, the <TT>init()</TT> method will be invoked and “Hello World” will be drawn. When it is called as an application, the <I>TrivialApplet</I> class is loaded, the <I>main</I> will be invoked, and the following will be displayed:</P>
<!-- CODE SNIP //-->
<PRE>
An Appletcation
</PRE>
<!-- END CODE SNIP //-->
<P><I>TrivialApplet</I> is a subclass of an <I>Applet</I> class but may be used as an applet or an application, depending on context. This permits the formulation of lemma 1.3 and corollaries 1.3a and 1.3b.</P>
<DL>
<DD><B>Lemma 1.3</B> Applets are run by invoking <I>init()</I>, and applications are run by invoking <I>main()</I>.
<DD><B>Corollary 1.3a</B> The difference between an applet and an application is the invocation and not necessarily the content.
<DD><B>Corollary 1.3b</B> Applets do not automatically run their <I>main</I>s. Applications do not automatically run their <I>init</I>s.
</DL>
<P><FONT SIZE="+1"><B>The Requirements to Match File Names and Class Names</B></FONT></P>
<P>Some compilers—such as JDK, J++, and the Symantec products—require that the file name of the Java source code match that of the public class name contained in the file. This requirement is not a part of the language specification [Gosling et al.]. It is a restriction imposed by the compiler implementation. This restriction is not uniformly imposed. For example, the Metrowerks CodeWarrior IDE for MacOS and Windows 95/NT do not impose this conformance between file names and class names.
</P>
<P>This lack of uniformity makes it time-consuming to port source code from one compiler to another. We hope that Sun will correct this bug in its own compiler soon.</P>
<P>It is much easier to distribute one file with several small classes. The alternative is to make several small source files.</P>
<P><FONT SIZE="+1"><B>No Validation System</B></FONT></P>
<P>At present, no validation system exists for a Java compiler or supporting Java technology. This is a critical need, because many products appear to violate the compile-time and run-time specifications laid out by Sun.
</P>
<P>A validation system would include series of test programs that would generate known compiler errors and known run-time errors. Such programs should elicit specific kinds of behavior from the Java class libraries.</P>
<H3><A NAME="Heading8"></A><FONT COLOR="#000077">The HTML Model vs. the Java Model</FONT></H3>
<P>The HTML model permits a document to make references to files in other formats. A browser reads the references to the HTML files and dispatches them to a decoding program. For example, if the file is compressed, the browser may start a decompression program automatically.
</P>
<P>The fatal flaw in this model is that browsers (and thei number of supporting applications, known as <I>helper apps</I>) can grow without bound. The Netscape browser, for example, recommends 16MB of RAM. As the applications become bloated, they tend to slow down even for simple tasks.</P>
<P>In this section we compare the HTML model with the Java model. In the Java model, code is compiled into class files and then downloaded, over the network, into an applet viewer. The applet viewer decodes the data stream that follows. The theory is that Java will become the language for decoding a wide range of data and that a browser need only support an applet viewer. For this model to work, the data must point to Java decoders that can be downloaded on demand.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="017-019.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="022-024.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 + -