Comp Prog Notes
Comp Prog Notes
Myprogram.java
API
Java Virtual Machine java platform
Hardware based Platform
First, start your editor. You can launch the Notepad editor
from the Start menu by selecting Programs > Accessories
Notepad. In a new document, type in the following code
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!' to standard output.
*
class Hello World App
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string,
}
}
Save the code in a file with the name Hello World App java To do this in
Notepad, first choose the File > Save As menu item. Then, in the Save
As dialog box
1.Using the Save in combo box, specify the folder (directory) where
you'll save your file. In this example, the directory is myapplication on
the C drive.
2.In the File name text field, type "Hello World App java", including the
quotation marks,
3.From the Save as type combo box, choose Text Documents (*.txt).
4.In the Encoding combo box, leave the encoding as ANSI
JAVA PACKAGES
Packages are nothing more than the way we organize files into different
directories according to their functionality, usability as well as category
they should belong to. An obvious example of packaging is the JDK
package from SUN (Java.xxx.yyy)
The reason is right now the HelloWorld class belongs to the package
world. If we want to run it, we have to tell JVM about its fully-qualified
class name (world. HelloWorld) instead of its plain class name
(HelloWorld).
C:\world>java world.HelloWorld
C:\world>HelloWorld
Note: fully-qualified class name is the name of the java class that
includes its package name Skyworth
Floating-Point Numbers
Floating-point numbers, also known as real numbers, are used when
evaluating expressions that require fractional precision. For example,
calculations such as square root, or transcendentals such as sine and
cosine, result in a value whose precision requires a floatingpoint type.
Java implements the standard (IEEE-754) set of floating-point types and
operators. There are two kinds of floating-point types, float and
double, which represent single-and double-precision numbers,
respectively. Their width and ranges are shown here:
Characters
In Java, the data type used to store characters is char. However, C/C++
programmers beware: char in Java is not the same as char in C or C++.
In C/C++, b is 8 bits wide. This is not the case in Java. Instead, Java uses
Unicode to represent characters. Unicode defines a fully international
character set that can represent all of the characters found in all human
languages. It is a unification of dozens of character sets, such as Latin,
Greek, Arabic, Cyrillic, Hebrew, Katakana, Hangul, and many more.