Group presentations will take place on
November 26th, and 27th, 2008.
Be prepared.
_____________________________________________
Parts Of Program
/*********************************************************
Name: PartsOfProgram.java
Output: Prints out results of adding two numbers.
Demonstrates different parts of a program.
Author: Mr.P
Date: November 17th, 2008
*********************************************************/
public class PartsOfProgram //Key words (public, class)
{
public static void main (String [] args)
{
int a,b.result; //Programmer defined variables (a,b,result)
a = 10;
b = 20;
result = a + b; //Operators (+, =)
System.out.println ("The result is: " +result);
}
}
______________________________________________
Name: PartsOfProgram.java
Output: Prints out results of adding two numbers.
Demonstrates different parts of a program.
Author: Mr.P
Date: November 17th, 2008
*********************************************************/
public class PartsOfProgram //Key words (public, class)
{
public static void main (String [] args)
{
int a,b.result; //Programmer defined variables (a,b,result)
a = 10;
b = 20;
result = a + b; //Operators (+, =)
System.out.println ("The result is: " +result);
}
}
______________________________________________
Homework Assignment
Homework is due on Monday, November 17th, 2008.
1.Open an Gmail account from http://www.google.com/,
2. Using the google account's username and password sign up for blog @ http://www.blogger.com/,
3. Create your new blog for our java class,
4. Send your blog address to Mr.P,
5. Post 5 examples of each primitive data types:
int, double, char, boolean.
6. Post a message to the World embedded in a java program.
____________________________________________________
1.Open an Gmail account from http://www.google.com/,
2. Using the google account's username and password sign up for blog @ http://www.blogger.com/,
3. Create your new blog for our java class,
4. Send your blog address to Mr.P,
5. Post 5 examples of each primitive data types:
int, double, char, boolean.
6. Post a message to the World embedded in a java program.
____________________________________________________
Variables in Java
In Java, you must explicitly declare all variables before using them. This rule is in contrast to some languages — most notably Basic and Visual Basic — which let you use variables that haven’t been automatically declared.
Allowing you to use variables that you haven’t explicitly declared might seem like a good idea at first glance. But it’s a common source of bugs that result from misspelled variable names. Java requires that you explicitly declare variables so that if you misspell a variable name, the compiler can detect your mistake and display a compiler error.
The basic form of a variable declaration is this:
type name;
Here are some examples:
int x;
String lastName;
double radius;
In these examples, variables named x, lastName, and radius, are declared. The x variable holds integer values, the lastName variable holds String values, and the radius variable holds double values. int variables can hold whole numbers (like 5, 1,340, and -34), double variables can hold numbers with fractional parts (like 0.5, 99.97, or 3.1415), and String variables can hold text values (like “Hello, World!” or “Jason P. Finch”).
Notice that variable declarations end with a semicolon. That’s because the variable declaration is itself a type of statement.
In short, a variable name can be any combination of letters and numerals, but must start with a letter. Most programmers prefer to start variable names with lowercase letters, and capitalize the first letter of individual words within the name. For example, firstName and salesTaxRate are typical variable names.
Initializing Variables
In Java, local variables are not given initial default values. The compiler checks to make sure that you have assigned a value before you use a local variable.
Examples of Code
/*******************************************************
Name: HelloWorld.java
Output: Prints out "Hello, world!" to the console
Date: May 3, 2006
*******************************************************/
public class HelloWorld
{
public static void main(String [] args)
{
System.out.println("Hello, World!");
}
}
/*******************************************************
Name: PartsOfProgram.java
Output: Prints out result of adding two numbers.
Demonstrates different parts of a program.
Date: May 8, 2006
*******************************************************/
public class PartsOfProgram //Key words(public, class)
{
public static void main (String [] args)
{
int a,b,result; //Programmer-defined variables(a,b,result)
a = 10;
b = 5;
result = a + b; //Operators (+,=)
System.out.println("The result is : "+result); //Punctuation (;)
}
}
__________________________________________
Allowing you to use variables that you haven’t explicitly declared might seem like a good idea at first glance. But it’s a common source of bugs that result from misspelled variable names. Java requires that you explicitly declare variables so that if you misspell a variable name, the compiler can detect your mistake and display a compiler error.
The basic form of a variable declaration is this:
type name;
Here are some examples:
int x;
String lastName;
double radius;
In these examples, variables named x, lastName, and radius, are declared. The x variable holds integer values, the lastName variable holds String values, and the radius variable holds double values. int variables can hold whole numbers (like 5, 1,340, and -34), double variables can hold numbers with fractional parts (like 0.5, 99.97, or 3.1415), and String variables can hold text values (like “Hello, World!” or “Jason P. Finch”).
Notice that variable declarations end with a semicolon. That’s because the variable declaration is itself a type of statement.
In short, a variable name can be any combination of letters and numerals, but must start with a letter. Most programmers prefer to start variable names with lowercase letters, and capitalize the first letter of individual words within the name. For example, firstName and salesTaxRate are typical variable names.
Initializing Variables
In Java, local variables are not given initial default values. The compiler checks to make sure that you have assigned a value before you use a local variable.
Examples of Code
/*******************************************************
Name: HelloWorld.java
Output: Prints out "Hello, world!" to the console
Date: May 3, 2006
*******************************************************/
public class HelloWorld
{
public static void main(String [] args)
{
System.out.println("Hello, World!");
}
}
/*******************************************************
Name: PartsOfProgram.java
Output: Prints out result of adding two numbers.
Demonstrates different parts of a program.
Date: May 8, 2006
*******************************************************/
public class PartsOfProgram //Key words(public, class)
{
public static void main (String [] args)
{
int a,b,result; //Programmer-defined variables(a,b,result)
a = 10;
b = 5;
result = a + b; //Operators (+,=)
System.out.println("The result is : "+result); //Punctuation (;)
}
}
__________________________________________
Primitive Data Types in Java
Integer Types
The integer types in Java are byte, short, int, and long. All integral types represent signed numbers;
Example of Primitive int
Code fragment defining, using int variables:
int secondsPerMinute = 60;
int minutesPerHour = 60;
int hoursPerDay =24;
int daysPerWeek =7;
int secondsPerWeek = secondsPerMinute *
minutesPerHour * hoursPerDay * daysPerWeek;
JOptionPane.showMessageDialog(null,
"There are " + secondsPerWeek +
" seconds per week");
int Operation Examples
int i = 5;
int j = 7;
int sumij = i + j; // 12
int diffij = i - j; // -2
int prodij = i * j; // 35
int divij = i / j; // 0
int remij = i % j; // 5
int divji = j / i; // 1
int remji = j % i; // 2
Double Types
Example of Primitive double
Code fragment:
double lbsPerKg = 2.205;
double mPerInch = 0.0254;
double height = 70.5;
double weight = 183.;
double heightMetres = height * mPerInch ;
double bmi = (weight / lbsPerKg) /
(heightMetres * heightMetres); // body mass index
System.out.println("Your body mass index is " + bmi);
double Operation Examples
double x = 5.e20; // 5.e20 = 5 * 1020
double y = 7.0e20;
double sumxy = x + y; // 1.2e21
double diffxy = x - y; // -2.0e20
double prodxy = x * y; // 3.5e41
double divxy = x / y; // .7142857142857143
double remxy = x % y; // 5.0e20
double divxy = y / x; // 1.4
double remxy = y % x; // 2.0e20
The Boolean Type
The Boolean type represents truth values. This type has only two possible values, representing the two Boolean states: on or off, yes or no, true or false. Java reserves the words true and false to represent these two Boolean values.
Example of Primitive boolean
boolean canBeCaught = true;
boolean canBeThrown = false;
What am I?
boolean goesAroundTheWorld = true;
boolean staysInACorner = true;
What am I?
The char Type
The char type represents Unicode characters.
Example of char type
char c = 'A';
________________________________________
The integer types in Java are byte, short, int, and long. All integral types represent signed numbers;
Example of Primitive int
Code fragment defining, using int variables:
int secondsPerMinute = 60;
int minutesPerHour = 60;
int hoursPerDay =24;
int daysPerWeek =7;
int secondsPerWeek = secondsPerMinute *
minutesPerHour * hoursPerDay * daysPerWeek;
JOptionPane.showMessageDialog(null,
"There are " + secondsPerWeek +
" seconds per week");
int Operation Examples
int i = 5;
int j = 7;
int sumij = i + j; // 12
int diffij = i - j; // -2
int prodij = i * j; // 35
int divij = i / j; // 0
int remij = i % j; // 5
int divji = j / i; // 1
int remji = j % i; // 2
Double Types
Example of Primitive double
Code fragment:
double lbsPerKg = 2.205;
double mPerInch = 0.0254;
double height = 70.5;
double weight = 183.;
double heightMetres = height * mPerInch ;
double bmi = (weight / lbsPerKg) /
(heightMetres * heightMetres); // body mass index
System.out.println("Your body mass index is " + bmi);
double Operation Examples
double x = 5.e20; // 5.e20 = 5 * 1020
double y = 7.0e20;
double sumxy = x + y; // 1.2e21
double diffxy = x - y; // -2.0e20
double prodxy = x * y; // 3.5e41
double divxy = x / y; // .7142857142857143
double remxy = x % y; // 5.0e20
double divxy = y / x; // 1.4
double remxy = y % x; // 2.0e20
The Boolean Type
The Boolean type represents truth values. This type has only two possible values, representing the two Boolean states: on or off, yes or no, true or false. Java reserves the words true and false to represent these two Boolean values.
Example of Primitive boolean
boolean canBeCaught = true;
boolean canBeThrown = false;
What am I?
boolean goesAroundTheWorld = true;
boolean staysInACorner = true;
What am I?
The char Type
The char type represents Unicode characters.
Example of char type
char c = 'A';
________________________________________
Java
Introduction
Java is an object-oriented programming (OOP) language.
The Java programming language is the language in which Java applications, applets, servlets, and components are written. When a Java program is compiled, it is converted to byte codes that are the portable machine language of a CPU architecture known as the Java Virtual Machine (also called the Java VM or JVM). The JVM can be implemented directly in hardware, but it is usually implemented in the form of a software program that interprets and executes byte codes.
This Java Virtual Machine takes Java Byte Code instructions one by one. Translates them into machine language for the given platform. Executes the machine language and produces desired results.
The Java Virtual Machine is different for every computer that is, there is one that generates PC
instructions, one that generates Mac instructions, and so on.
It has to be a different virtual machine for each platform as every machine has a different
machine language.
Processing Java - Summary
Java is an object-oriented programming (OOP) language.
The Java programming language is the language in which Java applications, applets, servlets, and components are written. When a Java program is compiled, it is converted to byte codes that are the portable machine language of a CPU architecture known as the Java Virtual Machine (also called the Java VM or JVM). The JVM can be implemented directly in hardware, but it is usually implemented in the form of a software program that interprets and executes byte codes.
The Java Virtual Machine
It is a virtual (or "pretend") machine inside your computer. Does everything a computer is expected to such as perform calculations, manipulate memory, produce output
… but it exists only in software!
… but it exists only in software!
This Java Virtual Machine takes Java Byte Code instructions one by one. Translates them into machine language for the given platform. Executes the machine language and produces desired results.
The Java Virtual Machine is different for every computer that is, there is one that generates PC
instructions, one that generates Mac instructions, and so on.
It has to be a different virtual machine for each platform as every machine has a different
machine language.
You quite likely have used a Java Virtual Machine before, but did not realize it.
Most web browsers come with the Java Virtual Machine.
Most web browsers come with the Java Virtual Machine.
Processing Java - Summary
- Source code is written in Java, a high-level language
- This Java source code is run through a Java compiler
- The Java compiler doesn’t produce machine language,
but instead produces generic Java Byte Code,
-Java Byte Code is then interpreted by the Java Virtual Machine to produce desired results.
- This Java source code is run through a Java compiler
- The Java compiler doesn’t produce machine language,
but instead produces generic Java Byte Code,
-Java Byte Code is then interpreted by the Java Virtual Machine to produce desired results.
_______________________________________________________
What Is Cyberethics?
Cyberethics is the study of moral, legal, and social issues involving cybertechnology. It examines the impact that cybertechnology has for our social, legal, and moral systems. It also evaluates the social policies and laws that have been framed in response to issues generated by the development and use of cybertechnology. Hence, there is a reciprocal relationship here.
Retrieved on November 10th, 2008 from http://higheredbcs.wiley.com/legacy/college/tavani/0471249661/presentation/ch01.ppt
_______________________________________________________
Please click here to send me an e-mail.
_______________________________________________________
Retrieved on November 10th, 2008 from http://higheredbcs.wiley.com/legacy/college/tavani/0471249661/presentation/ch01.ppt
_______________________________________________________
Please click here to send me an e-mail.
_______________________________________________________
Subscribe to:
Posts (Atom)