JAVA CODE
JAVA PROGRAMME
Java Basics
Working with Objects
Arrays, Conditionals, and Loops
Creating Classes and Applications in Java
More About Methods
Java Applet Basics
Graphics, Fonts, and Color
Simple Animation and Threads
More Animation, Images, and Sound
Managing Simple Events and Interactivity
Creating User Interfaces with the awt
Windows, Networking, and Other Tidbits
Modifiers, Access Control, and Class Design
Packages and Interfaces
Exceptions
Multithreading
Streams and I/O
Using Native Methods and Libraries
Under the Hood
Java Programming Tools
Working with Data Structures in Java
Advanced Animation and Media
Fun with Image Filters
Client/Server Networking in Java
Emerging Technologies
appendix A :- Language Summary
appendix B :- Class Hierarchy Diagrams
appendix C The Java Class Library
appendix D Bytecodes Reference
appendix E java.applet Package Reference
appendix F java.awt Package Reference
appendix G java.awt.image Package Reference
appendix H java.awt.peer Package Reference
appendix I java.io Package Reference
appendix J java.lang Package Reference
appendix K java.net Package Reference
appendix L java.util Package Reference

Q&A

Question: I know a lot about HTML, but not much about computer programming. Can I still write Java programs?
Ans: If you have no programming experience whatsoever, you most likely will find programming Java significantly more difficult than HTML. However, Java is an excellent language to learn programming with, and if
you patiently work through the examples and the exercises in this book, you should be able to learn enough to get started with Java.
Question:
What’s the relationship between JavaScript and Java?
Ans: They have the same first four letters.A common misconception in the Web world today is that Java and JavaScript have more in common than they actually do. Java is the general-purpose programming language that you’ll learn about in this book;
you use it to create applets. JavaScript is a Netscape-invented scripting language that looks sort of like Java; with it you can do various nifty things in Web pages. They are independent languages, used for
different purposes. If you’re interested in JavaScript programming, you’ll want to pick up another book, such as Teach Yourself JavaScript in a Week or Laura Lemay’s Web Workshop: JavaScript, both also
available from Sams.net Publishing.
Question:
According to today’s lesson, Java applets are downloaded via a Java-enabled browser such as Netscape and run on the reader’s system. Isn’t that an enormous security hole? What stops
someone from writing an applet that compromises the security of my system-or worse, that damages my system?
Ans:
Sun’s Java team has thought a great deal about the security of applets within Java-enabled browsers and has implemented several checks to make sure applets cannot do nasty things:
Java applets cannot read or write to the disk on the local system.
Java applets cannot execute any programs on the local system.
Java applets cannot connect to any machines on the Web except for the server from which they are originally downloaded.

Note that some of these restrictions may be allowed in some browsers or may be turned on in the browser configuration. However, you cannot expect any of these capabilities to be available.

In addition, the Java compiler and interpreter check both the Java source code and the Java bytecodes to make sure that the Java programmer has not tried any sneaky tricks (for example, overrunning buffers or
stack frames).

These checks obviously cannot stop every potential security hole (no system can promise that!), but they can significantly reduce the potential for hostile applets. You’ll learn more about security issues for applets
on Day 8, “Java Applet Basics,” and in greater detail on Day 21, “Under the Hood.”
Question:
I followed all the directions you gave for creating a Java applet. I loaded it into HotJava, but Hello World didn’t show up. What did I do wrong?
Ans: Don’t use HotJava to view applets you’ve created in this book; get a more up-to-date browser such as Netscape or Internet Explorer. HotJava was an experimental browser and has not been updated since soon
after its original release. The steps you take to define and write an applet have changed since then, and the applets you write now will not run on HotJava.
Question:
You’ve mentioned Solaris, Windows, and Macintosh in this chapter. What about other operating systems?
Ans: If you use a flavor of UNIX other than Solaris, chances are good that the JDK has been ported to your system. Here are some examples:
SGI’s version of the JDK can be found at http://www.sgi.com/Products/cosmo/cosmo_instructions.html.
Information about Java for Linux can be found at http://www.blackdown.org/java-linux/.
IBM has ported the JDK to OS/2 and AIX. Find out more from http://www.ncc.hurley.ibm.com/javainfo/.
OSF is porting the JDK to HP/UX, Unixware, Sony NEWS, and Digital UNIX. See http://www.osf.org/mall/web/javaport.htm.

(Thanks to Elliote Rusty Harold’s Java FAQ at http://www.sunsite.unc.edu/javafaq/javafaq/html for this information.)
Question:
Why doesn’t Java run on Windows 3.1?
Ans:
Technical limitations in Windows 3.1 make porting Java to Windows 3.1 particularly difficult. Rumor has it that both IBM and Microsoft are working on ports, but no real information is forthcoming.
Question:
I’m using Notepad on Windows to edit my Java files. The program insists on adding a .txt extension to all my files, regardless of what I name them (so I always end up with files like
HelloWorld.java.txt). Short of renaming them before I compile them, what else can I do to fix this?
Ans:
Although you can rename the files just before you compile them, that can get to be a pain, particularly when you have a lot of files. The problem here is that Windows doesn’t understand the .java extension (you
may also have this problem with HTML’s .html extension as well).

To fix this, go into any Windows Explorer window and select View|Options|File Types. From that panel, select New Type. Enter Java Source Files in the Description of Type box and .java into the
Associated Extension box. Then click OK. Do the same with HTML files if you need to, and click OK again. You should now be able to use Notepad (or any other text editor) to create and save Java and
HTML files.
Question:
Where can I learn more about Java and find applets and applications to play with?
Ans:
You can read the rest of this book! Here are some other places to look for Java information and Java applets:
The Java home page at http://www.java.sun.com/ is the official source for Java information, including information about the JDK, about the upcoming 1.1 release, and about developer tools such as
the Java Workshop, as well as extensive documentation.
Gamelan, at http://www.gamelan.com/, is a repository of applets and Java information, organized into categories. If you want to play with applets or applications, this is the place to look.
For Java discussion, check out the comp.lang.java newsgroups, including comp.lang.java.programmer, comp.lang.java.tech, comp.lang.java.advocacy, and so on. (You’ll need a Usenet
newsreader to access these newsgroups.)

prime number
Scroll to Top