Learn Essays

HOME F.A.Q. REGISTER LOGIN SEARCH  
Essay Topics
Acceptance
Art
Business
Custom Written
Direct Essays
English
Example Essays
Foreign
History
Medical
Mega Essays
Miscellaneous
Movies
Music
Novels
People
Politics
Pre-Written
Religion
Science
Search
Speeches
Sports
Technology

Click here to get paid up to $147 / hour to take simple surveys


Featured Papers from RadEssays

1. In The Beginning
2. In The Beginning...
3. As it was in the Beginning
4. Java
5. Java
This is only a preview of the paper
Click here to register and get the full text.
Existing members click here to login

Beginning Some Simple Examples of Java Programs

Java programs can be a few lines short or thousands of lines long. Every Java program has a purpose – it contains seqeunces of statements that represent operation for the computer to carry out, in order to fulfill a specific task. Every program will be different – according to it’s purpose – but all Java programs must obey the Java syntax.
Here are some very simple examples:

§     Example1:

     public class Hello
     {
     /* Write a simple message on the screen. ... " +
                    "Isn’t it fun to learn Java? ... Isn’t it fun to learn Java?

As you can see, the 3 examples are similar in purpose and in structure. For simple Java programs, a common structure would be:

     public class …………………
     {
     /*………………………………………… */
      public static void main( String[] args )
      {
           ……………………………………
      }
     }

All parts represented in the figure above should be present in every Java program, regardless of it’s purpose. Java is a case-sensitive language: class should be written in lower case, and NEVER as Class or CLASS.

The name of the class is the identifier of a program and should have the same name with the file where the program is saved and the file representing the compiled Java program. ...

The comments describing the purpose of the class are optional but recommended in order to help recognising the purpose of the Java program. ...

The declarations and statements are the part where the java program actually fulfils it’s purpose.

The principal parts of the program are delimited by braces: { at the beginning and } at the end. ... Java is an object-oriented language - in a simplified description, object-oriented languages represent information as objects and every action on an object is performed through a method. ...

As seen from Examples 2 and 3, other strings of characters are: “I am your friend, the computer. ... Isn’t it fun to learn Java? ... The quotes don’t appear when the program displays the messages on the screen – they are part of the Java syntax as string of character delimiters. ...

Java is a case-sensitive language! ...
Variable and Data Types

Java and Numbers

Sometimes (or quite often) computer programs are used to perform calculations, like in the next example:

§     Example1:

public class Volume
{
/* Calculate the volume of a room of dimensions 3, 4 and 5 meters */
public static void main(String[] args)
{
System. ... Whenever an arithmetic expression is encountered in a statement, the Java program will evaluate it (calculate the value of the expression) and the pass the result (e. ...

In Java , the arithmetic operators are:

          +          addition
          -          subtraction (also used for minus)
          *          multiplication
          /          division
          %          remainder

The operands these operators work on are either integers or floating-point numbers. ... This is the reason why programs store such pieces of information in variables. ... println( " sqaure meters" );
}
}

In Java, all variables must be declared before they can be used:

int volume, area;

By declaring a variable, memory space is set aside. ... Therefore, both the integer and the floating-point data types are implemented in Java in several variants, that will be detailed below. ... Some integer numbers may be either positive or negative, others will always be positive In order to efficiently use the memory space, there are corresponding datatypes for each of these cases:

Datatype     Examples     Possible value range     Internal representation     When to use
byte     byte dailyTemp;     -128 … 127     1 byte     very small integer numbers
short     short mySavings;     -32. ... :

boolean married;      /* variable married may take
only values true or false */

Remember: true and false are both Java keywords! ... char is also a Java keyword! ...

In it’s effort to be platform-independent, Java supports Unicode. ...

All words describing Java data types – byte, short, int, long, float, double, char and boolean – are part of the language, are called keywords and should always be written exactly in the same way (in small letters).

INT height; /* illegal, INT is NOT a Java keyword */
integer height; /* illegal, integer is NOT a Java keyword */
int height; /* legal */
int good-bye;      /* illegal, sign – not allowed in variable names */
int height, width, length; /* legal */

q     Strings of characters

Strings of characters are not primitive datatypes.


Approximate Word count = 3286
Approximate Pages = 13.1
(250 words per page double spaced)
Over 101,000 Essays and Term Papers!!
Links
java technology

Beginning Some Simple Examples of Java Programs

Java

java technology

Beginning Some Simple Examples of Java Programs

Macbeth

Support
F.A.Q.
Custom Essays
Payment
Learn Essays
Forgot Password?
Activation Email
More Links
All Papers Are For Research And Reference Purposes Only! You may not turn these papers in as your own! You must cite our web site as your source!
Copyright 2003-2008 learnessays.com. All rights reserved.