Java: Introduction


HOME]  Consulting  Design  Maintenance  Project  Testing  Training  Turnkey  Java  C++  SQL  HTML  JavaScript  C# 
© 2002  2016 All Rights Reserved Total Application Works
Tell a friend about this site (copy and paste the following HTML page into a file (e.g., using Notepad).) 

<html> <head> <title>C#: Table of Contents </title> </head> <body> <a href="http://sumtotalz.com/TotalAppsWorks/Java/JAV_Introduction.html"> Java: Introduction </a> </table> </body> </html> 
Source code 
The JAV_INTRO.zip file contains the following files:
This tutorial assumes that you have some prior programming experience. This tutorial is intended to be an introductory discussion on Java and programming. Java as a programming language is widespread and can be found on nearly all computers. This tutorial will prepare you to step through a set of tutorials on Java.
Java is a generalpurpose computer programming language that is concurrent, classbased, objectoriented, and specifically designed to have as few implementation dependencies as possible. It is intended to let application developers "write once, run anywhere" (WORA),[ Java was originally developed by James Gosling at Sun Microsystems (which has since been acquired by Oracle Corporation) and released in 1995 as a core component of Sun Microsystems' Java platform. As we ease into Java 3GL programming, you'll learn
We will discuss what makes up a program in the next section.
A program is a set of instructions used to solve a task. More specifically, these instructions tell a computer what to do. These set of instructions are like a recipe used to make a cake; a set of computer instructions are used to make a program. To make/create a program, we do the following:
++  text editor  Step 1: Open an Text Editor +++  V ++  source code  Step 2: Enter raw source into Text Editor +++  V +++  compiler  Step 3: compiler processes file created +++ by Text Editor that contains  source code V +++  Link Editor  Step 4: Object code created by compiler +++ is processed by Link Editor  V +++  executable program  Step 5: Result of link editor ++ 
Figure 1: Steps taken to create an executable program 

Application software consists of those programs written to perform particular tasks that are required by the users. For example, the following partial list shows programs that solve a specific task.
What is a navigation program? A navigation Program is an easytouse software application that provides stepbystep directions showing the user how to get from point A to point B. If you consider that the human brain is similar to a computer, then these
instructions are commands to the user providing instructions on what steps to perform next.
A Java program is a collection of commands, that tell the computer what steps to perform
next. This collection of commands, written in a programming language, is usually called Java source code,
source code or just code. As previously stated, human brains are similar to computers. As humans, we run programs all the time. Our daily routines could be considered human programs.
For example, look at the following routine/program.
Wake up; Go to the bathroom; Wash up; Exercise; Eat breakfast; Shower; Get dressed; Go to work; Do work/job; Return home; Watch TV; Log on to the Internet; Read/send email; Go to bed; 
Figure 2: A human daily routine/program 

Commands are either "functions" or "keywords". Keywords are predefined reserved identifiers that have specified meanings/functions. Since they are predefined, they cannot be used as identifiers (variable names or function/method names) in your program.
The set of rules of a language, Java in this case, that dictate how the various parts (keywords and/or commands) of sentences go together to provide instructions for a computer is called syntax.
For example, the "int a;" statement tells the compiler that variable "a" is of data type int.
Some of the Java commands/keywords are listed in the following table.
abstract 
continue 
for 
new 
switch 
assert ^{***} 
default 
goto ^{*} 
package 
synchronized 
boolean 
do 
if 
private 
this 
break 
double 
implements 
protected 
throw 
byte 
else 
import 
public 
throws 
case 
enum ^{****} 
instanceof 
return 
transient 
catch 
extends 
int 
short 
try 
char 
final 
interface 
static 
void 
class 
finally 
long 
strictfp ^{**} 
volatile 
const ^{*} 
float 
native 
super 
while 
Figure 3: Java keywords 

Name  Description  

static double abs(double a)  This method returns the absolute value of a double value.  
static float abs(float a)  This method returns the absolute value of a float value.  
static int abs(int a)  This method returns the absolute value of an int value.  
static long abs(long a)  This method returns the absolute value of a long value.  
static double acos(double a)  This method returns the arc cosine of a value; the returned angle is in the range 0.0 through pi.  
static double asin(double a)  This method returns the arc sine of a value; the returned angle is in the range pi/2 through pi/2.  
static double atan(double a)  This method returns the arc tangent of a value; the returned angle is in the range pi/2 through pi/2.  
static double atan2(double y, double x)  This method returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).  
static double cbrt(double a)  This method returns the cube root of a double value.  
static double ceil(double a)  This method returns the smallest (closest to negative infinity) double value that is greater than or equal to the argument and is equal to a mathematical integer.  
static double copySign(double magnitude, double sign)  This method returns the first floatingpoint argument with the sign of the second floatingpoint argument.  
static float copySign(float magnitude, float sign)  This method returns the first floatingpoint argument with the sign of the second floatingpoint argument.  
static double cos(double a)  This method returns the trigonometric cosine of an angle.  
static double cosh(double x)  This method returns the hyperbolic cosine of a double value.  
static double exp(double a)  This method returns Euler's number e raised to the power of a double value.  
>static double expm1(double x)  This method returns e^{x} 1.  
>static double floor(double a)  This method returns the largest (closest to positive infinity) double value that is less than or equal to the argument and is equal to a mathematical integer.  
static int getExponent(double d)  This method returns the unbiased exponent used in the representation of a double.  
static int getExponent(float f)  This method returns the unbiased exponent used in the representation of a float.  
static double hypot(double x, double y)  This method returns sqrt(x^{2} +y^{2}) without intermediate overflow or underflow.  
static double IEEEremainder(double f1, double f2)  This method computes the remainder operation on two arguments as prescribed by the IEEE 754 standard.  
static double log(double a)  This method returns the natural logarithm (base e) of a double value.  
static double log10(double a)  This method returns the base 10 logarithm of a double value.  
static double log1p(double x)  This method returns the natural logarithm of the sum of the argument and 1.  
static double max(double a, double b)  This method returns the greater of two double values.  
static float max(float a, float b)  This method returns the greater of two float values.  
static int max(int a, int b)  This method returns the greater of two int values.  
static long max(long a, long b)  This method returns the greater of two long values.  
static double min(double a, double b)  This method returns the smaller of two double values.  
static float min(float a, float b)  This method returns the smaller of two float values.  
static int min(int a, int b)  This method returns the smaller of two int values.  
static long min(long a, long b)  This method returns the smaller of two long values.  
static double nextAfter(double start, double direction)  This method returns the floatingpoint number adjacent to the first argument in the direction of the second argument.  
static float nextAfter(float start, double direction)  This method returns the floatingpoint number adjacent to the first argument in the direction of the second argument.  
static double nextUp(double d)  This method returns the floatingpoint value adjacent to d in the direction of positive infinity.  
static float nextUp(float f)  This method returns the floatingpoint value adjacent to f in the direction of positive infinity.  
static double pow(double a, double b)  This method returns the value of the first argument raised to the power of the second argument.  
static double random()  This method returns a double value with a positive sign, greater than or equal to 0.0 and less than 1.0.  
static double rint(double a)  This method returns the double value that is closest in value to the argument and is equal to a mathematical integer.  
static long round(double a)  This method returns the closest long to the argument.  
static int round(float a)  This method returns the closest int to the argument.  
static double scalb(double d, int scaleFactor)  This method returns d × 2^{scaleFactor} rounded as if performed by a single correctly rounded floatingpoint multiply to a member of the double value set.  
static float scalb(float f, int scaleFactor)  This method return f × 2^{scaleFactor} rounded as if performed by a single correctly rounded floatingpoint multiply to a member of the float value set.  
static double signum(double d)  This method returns the signum function of the argument; zero if the argument is zero, 1.0 if the argument is greater than zero, 1.0 if the argument is less than zero.  
static float signum(float f)  This method returns the signum function of the argument; zero if the argument is zero, 1.0f if the argument is greater than zero, 1.0f if the argument is less than zero.  
static double sin(double a)  This method returns the hyperbolic sine of a double value.  
static double sinh(double x)  This method Returns the hyperbolic sine of a double value.  
static double sqrt(double a)  This method returns the correctly rounded positive square root of a double value.  
static double tan(double a)  This method returns the trigonometric tangent of an angle.r  
static double tanh(double x)  This method returns the hyperbolic tangent of a double value.  
static double toDegrees(double angrad)  This method converts an angle measured in radians to an approximately equivalent angle measured in degrees.  
static double toRadians(double angdeg)  This method converts an angle measured in degrees to an approximately equivalent angle measured in radians.  
static double ulp(double d)  This method returns the size of an ulp of the argument.  
static double ulp(float f)  This method returns the size of an ulp of the argument.  
Figure 4: Java Math builtin functions 
A function is a selfcontained block of code that has a name and it has a property that it is reusable/reentrant i.e. it can be executed from as many different points in a Java program or many Java programs as required.
A function allows a number of program statements to be grouped into a unit with an addressable name. This unit can be called/invoked from other parts of a program.
A function is usually created to perform a task that will be needed many times in a program or needed by many program e.g., SQRT(). An outline of a function is depicted in the following figure.
function_name( data_type parameter ) { needed_variables ; int a ; int b ; code line 1 ; code line 2 ; a = 9 ; b = sqrt( a ) ; ... code line n ; } /** ************************************** * The main() function is the entry point * that is called Java runtime. *****************************************/ public static void main( String args[] ) { lines_of_code } 
Figure 5: Outline of a Function 

You may be wondering how does your program actually start? Every Java program has one entry point/function, which is called main. This function is the entry point that is called when your program first loaded into memory. From the main function, you can also call other functions whether they you wrote them or, as previously mentioned, they are provided by the compiler.
#import Java.Lang.Math; import javax.swing.JOptionPane ; import java.io.*; class MyApp { String name ; // name of user /** MyApp1 constructor */ public MyApp() { String mess = " ", title = " " , ret = " " ; /** read in the name of the user as a string */ name = JOptionPane.showInputDialog( "Please enter your name." ); System.out.println( "Hello " + name ) ; System.out.println( "This is a message from\n" ); System.out.println( "Ronald S. Holland\n" ); System.out.println( " @\n" ); System.out.println( "Sumtotalz.com\n\n\n" ); System.out.println( " Hello...\n" ); ret = JOptionPane.showInputDialog( null , mess , title , JOptionPane.PLAIN_MESSAGE ) ; } /***************************************************** * The main() function is the entry point that is called * when the program is loaded into memory. ****************************************************/ public static void main( String args[] ) { MyApp app = new MyApp() ; /** creates an instance of MyApp */ System.exit( 0 ); /** end the program */ } } 
Figure 6: Outline of a Function 

ret = JOptionPane.showInputDialog( null , mess , title , JOptionPane.PLAIN_MESSAGE ) ;
Holland's OOP Programming Design Model
++  Data <+ +++  ^  >+ V ^ +++   Topdown    Structured <+  programming    on Classes   (stepwise)  and methods   (refinement) ++  (as needed or as the)   (application ages) ++
HOME]  Consulting  Design  Maintenance  Project  Testing  Training  Turnkey  Java  C++  SQL  HTML  JavaScript  C# 
© 2002  2016 All Rights Reserved Total Application Works