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: | 304 Weeks Ago, 2 Days 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