Computer Programming: Java - Week 01 Notes

Introduction to Computer Programming with Java

Hardware vs. Software

  • Hardware: Physical electronic devices.
    • Examples: phone, computer components.
  • Software: Instructions that tell hardware what to do.
    • Examples: apps on a phone.

Integrated Development Environments (IDEs)

  • Using an IDE to write software.
  • Example IDE: Eclipse.
  • Choice of IDE is flexible (NetBeans, Dr. Java, etc.).

Types of Programming Languages

  • Low-Level Languages:
    • Directly understood by the computer.
    • Difficult to read and write.
    • Require many instructions for simple tasks.
  • High-Level Languages:
    • Easier to read and write.
    • Fewer commands accomplish more.
    • Example: Java (System.out.println(“Hi”);)

Java Code Structure

  • Java code is stored in files.
    • .java files: Contain the Java code you write.
    • .class files: Contain translated Java code that the computer understands.
  • Java code is organized into projects.

Basic Java Program Structure

  • All Java programs must follow a specific structure:

    public class ClassName {
        public static void main(String[ ] args) {
            // Your program goes here
        }
    }
    
  • The class name should match the file name (without the .java extension).

    • Example: HelloWorld.java

Variables

  • Definition: A named location in memory that stores a value.
  • Analogy: Like 'x' in the function f(x)=2x+4f(x) = 2x + 4.
    • If f(x)=2x+4f(x) = 2x + 4, then to evaluate f(1)f(1), we store 1 in 'x'.
  • In Java, variables can hold numbers, words, and other types of data.
  • Examples:
    • String myFirstVariable;
    • int mySecondVariable;
Variable Naming Conventions
  • Good Examples:
    • age
    • firstName
    • numberOfClasses
    • hour
    • fred
  • Bad Examples:
    • FirstName
    • firstname
    • VariablePractice.java
Common Errors with Variables
  1. String firstName = Joe;
    • Error: Missing quotes around Joe. Should be `String firstName =