Unit 1 Intro to Computer Programming & Java (1/9 & 1/14)

  • Data → input → Process → output → Information

  • Process ←→ Storage

  • Memory unit

    • RAM - Random Access Unit

    • Volatile

    • Holds both data and program instructions.

    • Shared by all programs running.

    • Ordered sequence of storage cells (bytes). Each capable of holding a piece of information.

    • Each cell has its own unique address.

    • Capacity measured in bytes, kilobytes, megabytes, gigabytes, etc…

  • Decimal system

    • Base 10

    • 0 - 9

  • Binary system

    • Base 2

    • 0 and 1

  • Byte

  • Kilobyte → 1,024 (2^10)

  • Megabyte → about a million bytes (2²^0)

  • Gigabyte → about a billion bytes (2³^0)

  • Tbyte → about a trillion bytes (2^40)

  • Pbyte → (2^50)

  • Central processing unit (CPU)

    • Executes program instructions

    • Components

      • Control unit: controls the order in which the program instructions are executed.

      • Arithmetic/logic unit (ALU): performs arithmetic operations and makes logical decisions.

      • Speed measured in hertz, kilohertz, megahertz, etc…

    • Fetch - Execute - Decode cycle

      • Fetch

        • Fetch the instructions located in RAM

        • Copy the instruction to the instruction register

      • Decode

        • Input data

        • Perform an arithmetic/logical operation

        • Output data

      • ALU

        • Get data, if needed, from Memory to CPU registers

      • Execute instructions

  • System Software

    • Operating system

      • Administers all the computer resources and presents itself as the interface between the user and the computer.

        • Starts working when the computer is turned on.

        • Enables the user to access programs, manage files, and complete other tasks.

  • Application Software

    • Programs that enable the user to accomplish specific kinds of tasks.

      • Example

        • Word processing

        • Spreadsheets

        • Database management systems

  • Programming Life-cycle Phases

    • Problem-solving

    • Impemation

    • Maintenance

  • IPO - Input/Processing/Output

    • Input

      • Assigning values

      • Keyboard

      • File(s)

    • Processing

      • Calculations

    • Output

      • Screen

      • File(s)

  • Comments in Java

    • /*…. */

    • //

  • Class

    • If something is capitalized, it’s because it’s from a class and it MUST be capitalized.

  • Output

    • System.out.println("Hello World!!");

/*
 * Hayley Pappas
 * 
 * Hello.java
 * 
 * Display the message "Hello World!!"
 */

public class Hello {
	public static void main(String[] args)
	{
		// Display the message "Hello World!!"
		System.out.println("Hello World!!");
	}
}
  • Declaration

    • DataType Variable1, ……. ;

/*
 * Hayley Pappas
 * 
 * Rectangle.java
 * 
 * Given the width (1234.5) and the height (10.0) of a rectangle, 
 * calculate its area, and display the results.
 */

public class Rectangle {
	public static void main(String[] args)
	{
		// Variables
		double width, height, area;
		
		// Intro
		System.out.println("Rectanlge Area Calculator ...");
		System.out.println();  // Blank line
		
		// Assign values to the width & height
		width = 1234.5;
		height = 10.0;
		
		// Calculate area
		area = width * height;
		
		// Display result
		System.out.println("The area of a " + width + " by " + height 
				+ " rectangle is " + area + ".");
	}

}