📄 011-012.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=011-012//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="008-010.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="012-014.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P><FONT SIZE="+1"><B>Java Has Garbage Collection</B></FONT></P>
<P>Java has automatic storage operations, including a garbage collection mechanism. Garbage collection enables the Java virtual machine to reclaim storage used by discarded instances. You can explicitly invoke the garbage collector by using the <I>gc</I> method of the <I>System</I> class. The Java virtual machine will perform garbage collection without explicitly invoking <I>System.gc()</I>. The garbage collector is the only mechanism you can use to free storage in Java. To get an instance to be reclaimed by the garbage collector, you must remove all references to the object. Then either invoke <I>System.gc()</I> or wait for the garbage collector to reclaim the storage. The existence of the garbage collection mechanism in the Java virtual machine means that you will never have to worry about keeping track of storage.</P>
<P><FONT SIZE="+1"><B>Java Has Standard Class Libraries</B></FONT></P>
<P>Java has standard libraries that include an Abstract Window Toolkit (AWT). AWT enables object-oriented graphical user interface (GUI)-based programs to be portable. Previous attempts at this have not had much commercial success [Watson]. The class libraries have eight major packages, and the number is growing. An input/output package, <I>java.io</I>, enables a user to perform input and output stream manipulations. This is intended to make file and network data I/O manipulations into stream manipulations that work without direct involvement with the source of the stream. This approach provides a layer of abstraction that makes generic I/O programming much easier.</P>
<P>A network package, <I>java.net</I>, enables socket and uniform resource locator (URL) manipulations. The network package provides a standard, built-in method for turning sources and sinks of network data into streams. Once this occurs, the I/O package can be used to manipulate the streams.</P>
<P>A utilities package, <I>java.util</I>, contains several features considered standard in operating systems—features such as getting the date, time, random numbers, and so on.</P>
<P>These packages are a starting point for building portable programs. Any packages that build on these core Java packages will be portable. Also, the core Java packages are typically built into the systems that support Java. As a result, the core packages need not be downloaded every time a Java program needs something in a package. This arrangement makes the Java programs faster to download and makes the byte code files more compact.</P>
<P><FONT SIZE="+1"><B>Java Has boolean Types</B></FONT></P>
<P>Java uses a conditional statement that takes a boolean as an argument, whereas languages such as C or C++ permit an integer to be used as an argument to a conditional.
</P>
<P>For example, in C or C++ it is possible to write the following:</P>
<!-- CODE SNIP //-->
<PRE>
if (1) {fprintf(stderr, “1 is not a boolean”)};
</PRE>
<!-- END CODE SNIP //-->
<P>In Java, the argument to a conditional must be of boolean type. Using an integer as an argument can create confusion between assignments and tests for equality. For example:
</P>
<!-- CODE SNIP //-->
<PRE>
if (a = 0) {fprintf(stderr, “this will never be printed”)};
</PRE>
<!-- END CODE SNIP //-->
<P>This statement is a bug, because <I>a</I> will be assigned to the value 0. In fact, the == operator is needed:</P>
<!-- CODE SNIP //-->
<PRE>
if (a == 0) {fprintf(stderr, “this might be printed”)};
</PRE>
<!-- END CODE SNIP //-->
<P>With Java, the assignment-test confusion becomes a bug of the past.
</P>
<P><FONT SIZE="+1"><B>Java Has Security</B></FONT></P>
<P>There is a class of programs called <I>applet viewers</I> that have their own Java virtual machines. Java-enabled browsers have built-in applet viewers.</P>
<P>Secure viewers protect the system by making an instance of the security manager. The security manager can disable operations that are considered dangerous (such as file I/O, creating consoles, or running native methods). Most Java-enabled browsers make an instance of the security manager.</P>
<P>Some applet viewers permit the running of Java programs without making an instance of the security manager. Thus, applets and applications are subject to the same security procedures.</P>
<P>A Java program that makes an instance of a frame, when an instance of the security manager is in place, will display an “untrusted Java Applet” label. This message alerts the user not to type sensitive data into the applet.</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="008-010.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="012-014.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 + -