The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 337 Weeks Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Lecture 1
163 williams st 3rd floor: tutor center
Monday, July 24, 2017
7:21 PM
Information processor: input and output (ex computer)
-repetitious process
-reliability
==>still need human interaction
Reference doc: java API
Run the program: press window key and R>type in cmd
Hardwarez;
Von Newman Architecture :
Input==> memory unit<====>CPU-CU ======>output
-ALU
CPU: central processing unit==> directs and controls information processing
CU: control unit
Memory unit: storage
-unit for data to be processed
-stores programs during execution
-Primary: RAM==>dynamic (goes away after execution)
-higher the ram bc mimic the speed of CPU speed
-Secondary: hard drive, CD, floppy
Computer:
-hardware:
-input: keyboard, mic, scanner. Mouse
-output: printer
-software
Cmputer instructions
-Input/output: transfer data btw peipherals and primary memory
-ALU: perform arithemtic operation or logical oerations on data stored in primary memory
-Selection statement:
-Interative (loops/repitition)
-Methods (functions)
Machine language
Binary: 0 1 switch/ transistor
Bit 0 or 1
Byte 8 bits
Low level language
=>assembly-represented by mnemonics
Address
001
101
Content
11011001
10111011
Mnemonic
ADD
SUB
MlY
PIV
Machine languge
11011
101101
11011
1101101
Compiler: translate low level language into machine code/language
Assembly program==>assembly lowpile==>machine code
High level language
-more english like (common english words)
-easier to read
-ex. C++, Ruby, etc==>machine dependent
==>Java: machine independent; HTML isnt a language
High level language program==>high level compiler==>machine code/language
Java
-objective orientated program
-platform (machine) neutral
One computer==>information processer
Two computer==>creates a network==>share information
More computers==>internet
Java source code (.java) ===> java compiler (javac.exe)===> Java byte code (.class)====> java interpreter/Virtue Machine (VM) (java.exe)
Compiled vs interpreted
-compiled info to .exe (faster): java, C++
-interpreted is line by line: shell, perl
Complier:
Syntax: formal rules governing the construction of valid instructions (grammar)
Semantics: the meaning of the instructions
Everything is process driven
c:\directory>javac.exe ===>Hello java
c:\directory>java.exe ===>Hello
(Hello world)
c:\directory>
Sample program:
Hello.java ( name of the class is captial and should be the same w the file name)
Comment(//): good comments are important
//hello world
Public class Hello {
public static void main (String [] args) {
System.out.println ("Hello World");
}//end main
}//end class
Note:
; ==>denote a statement
Java ignores everything except spaces btw words
Reserved words (p35): special meaning for java
Java doesn’t use reserved words for identifier
-identifier is a name associated with an object which the program can refer to
-ie:variable names, class names
==>must begin with a letter or "_" or '$' made up of (a-z, A-Z) and digits (0-9)
Sample 2: Assume NY area code is 212. Create a program that prints NY area code
AreaCode.java
public class AreaCode {
pubic static void main (String [] args) {
System.out.print ("the area code for"); //no new line (output instruction)
System.out.println ("NY is 212"); //new line (output instruction)
}//end main
}//end class
-very detailed ==> one step at a time
Java only sees statements
c:\ javac.exe AreaCode.java
c:\ java.exe AreaCode
Lecture 2
Monday, September 11, 2017
6:12 PM
Hw1: due on the 18th @6pm
Java
Object oriented programming (OOP):
-a concept in programming technique
-based on objects
-not focus on how but focus on "what"
Client server
Reuse improves reliability
3 ideas to OOP:
-data encapsulation: hiding details>focus on "what" not "how"
>data/function
-Inheritance
-Polymorphism
We are the user and the producer
Software Components:
-Java API (application programming interface)
P193
import package.class;
Or
import package*;
import java.util.Scanner
. (the dot notation): the dot tells you what function
Java program operate on data
program runs in the memory unit
-must declare a data type in memory location before use
8 Primitive data types:
-4 variations of a whole number (integer):
-byte: 8 bits>-128 to 127
-short:16 bits
-int: 32 bits
-long: 64 bits
-2 variation of decimal:
-float:
-double:
-char: one single character
-boolean: true/false
data type: the type of data in memory location
Java is a strong data type of language
Wrapper classes/objects: mainly used for conversion from one data type to another
-Byte
-Short
-Integer
-Long
-Float
-Double
-Character
-Boolean
-Void
Variable:
-an indentifier
-a name of a memory location where data is stored or retrieved
-we need to allocate space in memory to store value
-called variable because value changes
-no space in variable name
-syntax: data.type variable _name;
e.g. int x;
x=100;
x=50;
Double PayRate;
PayRate=15.0 (cant use $ because it changes the syntax)
Always declare the data type
Literal:
-a name constant: a memory location, like a variable; but does not change in value
-syntax: data.type variable rome=literal value;
final double PI=3.14;
final double taxpyc=.0935;
E.g. Output the sum of two numbers ( in notepad)
public class Sum {
public static void main (String [] args){
int num1; num1 30
int num2; num2 44
int sum; sum 74
num1 = 30;
num2 = 40;
sum = num1 + num2; The sum is 74
System.out.println("The sum is" + sum);
}
}
Definitions:
Statements (;):
-forms the smallest executable unit in a java program
Assignment (=):
-used to change a value in memory
-take the right side of assignment assigned to the left side of assignment
Expression:
-composed of one or more operations
-e.g. a=b+c (b,c are operands, "+"is an operator)
Arithmetic operators:
*: multipication, a*b
/ : division: a/b
%: modulus: a%b (remainder, only for integer types)
+: addition, a+b
-: subtraction, a-b
ex. a= a op b
a=a+b;
a +=b;
![]()
![]()
![]()
Lecture 3
9/27: midterm
-written in class no tech
Wednesday, September 13, 2017
6:09 PM
For hw#2 hints: 64 cents: 2 quarters, 1 dime, 0 nickles, 4 pennies
Ex. Given a radius. Calculate the circumference of a circle
public class Circumference {
public static void main(String [] args) {
int radius;
final double pi = 3.14;
double circumference;
radius = 20
circumference = 2 * radius * pi
System.out.println("The circumference is" + circumference);
}
}
On BB, under documents: all class examples
Float and double: double holds more value
Must declare a data type for each variable
Same example but more flexible: TYPICAL TEST QUESTION
import java.util.Scanner;
public class Circumference {
public static void main(String [] args) {
Scanner scan = new scanner (System.in);
int inputValue;
int radius;
//final double pi = 3.14;
final double pi = Math.PI;
double circumference;
System.out.println("Enter a radius value");
inputValue = scan.nextInt();
//System.outprintln("Input value is " + inputValue);
radius = inputValue;
circumference = 2 * radius * pi
System.out.println("The circumference is" + circumference);
}
}
Comments:
Scan:
inputValue: 15
radius: 15
pi: 3.14
circumference:
PC: dir
Equality, Relational and logical operators:
-used to control program
-evaluate to true or false (boolean expression)
! Logical not : ex. If boolean a=true, !a means false
< less than: n1<n2 (int n1, n2;)
<= less than or equal: n1<=n2
>greater than: n1>n2
>= greater than or equal: n1>n2
== equality: n1==n2
!=: not equal n1!=n2
&& logical and: expression && expression
|| logical or: expression || expression
Double quotes destrings
It changes the value
For this class we accept that we only input integers
Truth tables: must memorize this
And:
F F =>F
F T=>F
T F=>F
T T=>T
Or:
F F=>F
F T=>T
T F=>T
T T=>T
TYPICAL TEST QUESTIONS
Ex. (8>5) && (8<3)
(8>5): true
(8<3): false
&&: and
According to the truth table: And T F=>F
&& take precedence over ||
Precedence:
-operator precedence: order in which operators or evaluated in a compound expression
-need to understand to avoid confusion
-parenthesis will break the order of precedence and will get evaluated first
-Order of precedence
*,/,%
+,-
<,<=,>,>=
==, !=
&&
||
=
-some level of precedence will be evaluated from left to right
-evaluate()first
Ex. TYPICAL TEST QUESTION
6+3*4/2+2:
-6+12/2+2
-6+6+2=14
4*5+7*2:
-20+7*2
-20+14=34
4*(5+7*2):
-4*(5+14)
-4*19=76
Increment/decrement operators:
-Increment/decrement value in memory by 1
a++; //post increment: a=a+1(same as a+=1); execution after statement (;)
++a; //pre increment: execution before statement(;)
a--; //post decrement:
--a; //pre decrement:
Ex. Int num=34;
System.out.println ("num=" + num++);
==>num will be 35
int num=34;
int a;
a=2+num++
==>num is originally 34 but execute before; so num becomes 35, a=37
TYPICAL TEST QUESTION
Ex.
Int age;
Age=19;
If(age>=18){
System.out.println("ok to vote");
System.out.println("ok to drive");
} else
System.out.println("too young");
Logical statements:
-making decisions by a program
-if statement: test a particular boolean expression, if expression evaluate to true, an action or set up action are executed
-if (boolean expression) is true, execute the following one or multiple statements
-if else, else (execute if the statement was false)
Ex.
If (age>=18);
System.out.println("ok to vote")
==>semicolon killed the if statement
Ex. Read input (midterm and final)
-calculate average
-if average >=70, "pass"
Else "fail"
Import java.util.Scanner;
public class average {
public static void main(String[] args) {
Scanner scan = new Scanner (System.in);
int input;
int midterm_exam;
int final_exam;
double avg;
System.out.println ("Enter midterm");
midterm_exam = scan.nextInt();
System.out.println ("Enter final");
final_exam = scan.nextInt();
System.out.println("midterm=" + midterm_exam);
System.out.println("final=" + final_exam);
avg = (midterm_exam +final_exam) /2.0;
System.out.println("avg = " +avg);
//method one
if (avg>=90 )
System.out.println("A");
else
if (avg>=80 )
System.out.println("B");
else
if (avg>=70 )
System.out.println("C");
else {
System.out.println("F");
System.out.println("Try again");
}
//method two
/*
if (avg>=90 && avg <= 100)
System.out.println("A");
if (avg>=80 && avg<90)
System.out.println("B");
if (avg>=70 && avg<80)
System.out.println("C");
if (avg<70)
System.out.println("F");
*/
/*
if (avg >= 70)
System.out.println("Pass");
else
System.out.println("Fail");
*/
}
}
Comments:
final: a reserved word, cant be used as a variable
Everything is sequential unless its redirected
Variables:
-scan:
-midterm_exam: 90
-final_exam:80
-avg:85
Turn the results into letter grades
A:90-100
B: 80-90
C: 70-80
F: <70
Not use else at all (method 2) or you use else everywhere(method 1)
Else:
-only works on the most recent "if" statement
-else is mutually exclusive
/*: comment out stuff (for educational purposes in the example)
{}: its purpose is to have multiple expressions (under method one)
Attachments:
----------- ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly