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

Installing the JDK and Sample Files

Sun’s JDK for Solaris, Windows, and Macintosh is included as part of the CD-ROM that comes with this book. Also on the CD-ROM are all of the code examples from this book-a great help if you don’t want to type
them all in again. To install either the JDK or the sample files (or both), use one of the following procedures:

Note
If you don’t have access to a CD-ROM drive, you can also get access to these files over the World Wide Web. You can download the JDK itself from
http://java.sun.com/products/JDK/1.0.2/ and install it per the instructions on those pages. The sample files from this book are available on the Web site for
this book: http://www.lne.com/Web/JavaProf/.
If you download the JDK and source files, as opposed to getting them off the CD-ROM, make sure you read the section “Configuring the JDK” to make sure
everything is set up right.

Windows
Sun’s JDK runs on Windows 95 and Windows NT. It does not run on Windows 3.x.

To install the JDK or the sample files on Windows, run the Setup program on the CD-ROM (double-clicking the CD icon will do this automatically). By default, the package will be installed into C:\Java; you can install
it anywhere on your hard disk that you’d like. You’ll be given options to install the JDK, the sample files, and various other extra files; choose the options you want and those files will be installed.

If you’ve installed the JDK, note that in the directory JDK\lib there is a file called classes.zip. Do not unzip this file; it needs to remain in zip form for it to work correctly. The file JDK\src.zip contains the source
code for many of the JDK libraries; you can unzip this one if you like. Make sure if you do that you have a zip program that supports long filenames, or it will not work correctly!

Macintosh
Sun’s JDK for Macintosh runs on System 7 (MacOS) for 68KB or Power Mac.

To install the JDK or the sample files on the Macintosh, double-click the installation program on the CD-ROM. By default, the package will be installed into the folder Java on your hard disk; you can install it anywhere
on your disk that you’d like. You’ll be given options to install the JDK, the sample files, and various other extra files; choose the options you want and those files will be installed.

Solaris
Sun’s JDK for Solaris runs on Solaris 2.3, 2.4, and 2.5, as well as the x86 version of Solaris.

The CD-ROM for this book contains the tarred and zipped JDK in the directory jdk/solaris/jdk1.02.tgz. Using the utilities gunzip and tar, you can extract the contents of that file anywhere on the file system
you would like. For example, if you copy the .tgz file to your home directory and use the following commands to extract it, you’ll end up with a java directory that contains the full JDK:
gunzip ./jdk1.02.tgz
tar xvf ./jdk1.02.tar

Note that in the directory java\lib there is a file called classes.zip. Do not unzip this file; it needs to remain in zip form for it to work correctly. The file java\src.zip contains the source code for many of the JDK
libraries; you can unzip this one if you’re interested in the source code.

The sample files are also contained on the CD-ROM in authors/authors.tar. Create a directory where the sample files will live (for example, a directory called javasamples in your home directory), copy the
authors.tar file there, and then use the tar command to extract it

More Info

1. **Download the JDK**:
– Visit the Oracle JDK download page or the OpenJDK website.
– Choose the appropriate JDK distribution for your operating system (e.g., Windows, macOS, Linux) and architecture (32-bit or 64-bit).
– Click on the download link and follow the on-screen instructions to download the JDK installer.

2. **Install the JDK**:
– Once the download is complete, run the JDK installer.
– Follow the installation wizard instructions to install the JDK on your system.
– During the installation process, you may be prompted to choose the installation directory. Note down the installation path as you’ll need it later.

3. **Set `JAVA_HOME` Environment Variable** (for Windows):
– Right-click on “This PC” or “My Computer” and select “Properties.”
– Click on “Advanced system settings” on the left side.
– In the System Properties window, click on the “Environment Variables…” button.
– Under the “System variables” section, click “New…” and set `JAVA_HOME` as the variable name and the JDK installation directory as the variable value (e.g., `C:\Program Files\Java\jdk-11.0.12`).
– Click “OK” to save the changes.

### Creating Sample Java Files:

Now, let’s create some sample Java files to test our JDK installation:

1. **Open a Text Editor**:
– You can use any text editor of your choice. For simplicity, let’s use Notepad (Windows) or TextEdit (macOS) for this example.

2. **Write Java Code**:
– Open a new file in your text editor and type the following Java code:

“`java
public class HelloWorld {
public static void main(String[] args) {
System.out.println(“Hello, world!”);
}
}
“`

3. **Save the File**:
– Save the file with the name `HelloWorld.java`.
– Make sure to save it in a directory where you can easily access it from the command line.

### Compiling and Running the Java Program:

Now, let’s compile and run the `HelloWorld` Java program:

1. **Open Command Prompt / Terminal**:
– Open Command Prompt (Windows) or Terminal (macOS/Linux).

2. **Navigate to the Directory**:
– Use the `cd` command to navigate to the directory where you saved `HelloWorld.java`.

3. **Compile the Java Program**:
– Type the following command to compile the Java program:
“`
javac HelloWorld.java
“`

4. **Run the Java Program**:
– After successful compilation, type the following command to run the Java program:
“`
java HelloWorld
“`

5. **Verify Output**:
– You should see the output `Hello, world!` printed to the console, indicating that the program executed successfully.

That’s it! You’ve successfully installed the JDK and created a simple Java program. You can now continue exploring Java development further by writing more complex programs and exploring additional features of the language.

prime number
Scroll to Top