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

Why Learn Java?

At the moment, probably the most compelling reason to learn Java-and probably the reason you bought this book-is that applets are written in Java. Even if that were not the case, Java as a programming language has
significant advantages over other languages and other environments that make it suitable for just about any programming task. This section describes some of those advantages.

Java Is Platform Independent

Platform independence-that is, the ability of a program to move easily from one computer system to another-is one of the most significant advantages that Java has over other programming languages, particularly if your
software needs to run on many different platforms. If you’re writing software for the World Wide Web, being able to run the same program on many different systems is crucial to that program’s success. Java is platform
independent at both the source and the binary level.

New Term
Platform independence means that a program can run on any computer system. Java programs can run on any system for which a Java virtual machine has been
installed.

At the source level, Java’s primitive data types have consistent sizes across all development platforms. Java’s foundation class libraries make it easy to write code that can be moved from platform to platform without the
need to rewrite it to work with that platform. When you write a program in Java, you don’t need to rely on features of that particular operating system to accomplish basic tasks. Platform independence at the source level
means that you can move Java source files from system to system and have them compile and run cleanly on any system.

Platform independence in Java doesn’t stop at the source level, however. Java compiled binary files are also platform independent and can run on multiple platforms (if they have a Java virtual machine available) without
the need to recompile the source.

Normally, when you compile a program written in C or in most other languages, the compiler translates your program into machine code or processor instructions. Those instructions are specific to the processor your
computer is running-so, for example, if you compile your code on an Intel-based system, the resulting program will run only on other Intel-based systems. If you want to use the same program on another system, you have
to go back to your original source code, get a compiler for that system, and recompile your code so that you have a program specific to that system. Figure 1.2 shows the result of this system: multiple executable
programs for multiple systems.

Figure 1.2 : Traditional compiled programs.

Things are different when you write code in Java. The Java development environment actually has two parts: a Java compiler and a Java interpreter. The Java compiler takes your Java program and, instead of generating
machine codes from your source files, it generates bytecodes. Bytecodes are instructions that look a lot like machine code, but are not specific to any one processor.

To execute a Java program, you run a program called a bytecode interpreter, which in turn reads the bytecodes and executes your Java program (see Figure 1.3). The Java bytecode interpreter is often also called the
Java virtual machine or the Java runtime.

Figure 1.3 : Java programs.

New Term
Java bytecodes are a special set of machine instructions that are not specific to any one processor or computer system. A platform-specific bytecode interpreter
executes the Java bytecodes. The bytecode interpreter is also called the Java virtual machine or the Java runtime interpreter.

Where do you get the bytecode interpreter? For applets, the bytecode interpreter is built into every Java-enabled browser, so you don’t have to worry about it-Java applets just automatically run. For more general Java
applications, you’ll need to have the interpreter installed on your system in order to run that Java program. Right now, you can get the Java interpreter as part of your development environment, or if you buy a Java
program, you’ll get it with that package. In the future, however, the Java bytecode interpreter will most likely come with every new operating system-buy a Windows machine, and you’ll get Java for free.

Why go through all the trouble of adding this extra layer of the bytecode interpreter? Having your Java programs in bytecode form means that instead of being specific to any one system, your programs can be run on any
platform and any operating or window system as long as the Java interpreter is available. This capability of a single binary file to be executable across platforms is crucial to what makes applets work because the World
Wide Web itself is also platform independent. Just as HTML files can be read on any platform, so can applets be executed on any platform that has a Java-enabled browser.

The disadvantage of using bytecodes is in execution speed. Because system-specific programs run directly on the hardware for which they are compiled, they run significantly faster than Java bytecodes, which must be
processed by the interpreter. For many basic Java programs, speed may not be an issue. If you write programs that require more execution speed than the Java interpreter can provide, you have several solutions available
to you, including being able to link native code into your Java program or using special tools (called just-in-time compilers) to convert your Java bytecodes into native code and speed up their execution. Note that by using
any of these solutions, you lose the portability that Java bytecodes provide. You’ll learn about each of these mechanisms on Day 20, “Using Native Methods and Libraries.”

 
prime number
Scroll to Top