Вы находитесь на странице: 1из 18

AP Computer Science Lecture Mtg.

#1
Understanding computer science fundamentals

During this session:


We will cover: - Binary conversion - Hexadecimal conversion - Understanding Object-oriented programming concepts - Creating your first program

How is programming related to computer science?

Computer science is about data structures how the computer organizes, stores, and processes data. Since computers are machines and cannot think, we must give the computer instructions using its medium the programming language. We use the programming constructs (ways to perform functions) so the computer will know how to process the given data..

How does the computer process data?


Binary numbers Binary digits are base-2 numbers (meaning that the computer uses only the digits of 0 and 1 to process information). Binary digits are switches or light bulbs on a chip, transistor or motherboard that makes the computer work (that is, the process of storing information). Base-2 numbers are powers of 2. Zero (0) means OFF. One (1) means ON.

How does the computer process data?

Lets try to convert base 10 numbers to binary! - Go to your word processing program. - Create a table with 8 columns and 2 rows. - In the first row, from right to left (go to column 8) type the number in column 8; 2 in column 7 (and so on); 4, 8, 16, 32, 64, 128, 256 - What is the binary conversion of the value 56?

How does the computer process data?

Hexadecimal values are base 16 numbers: digits that represent the decimal values 10 through 15 using letters A through F.
123456789ABCDEF

10 11 12 13 14 15

How does the computer process data?


How are hexadecimal values converted to numbers?

Problem: Find the values of 2A8E.


Draw a table or create in your word processor program. Make about 5 columns and 2 rows. Place the powers of 16 into the first column starting from right to left. 161, 162, 163 and so on. Place hexadecimal value into the 2nd row. What is the value? (Get a calculator!)

How does the computer process data?


The computer also processes data using objectoriented programming concepts.
Class: Animal

Object: Cat Object: Fish

Object: Dog

Method:

Method:

Swim

Bark

Java is an object oriented programming language. Objects are the fundamental elements that make up the program.

Object-oriented programming
Class Object Method - is the format of the class definitions
class

object

method

We will learn about class definitions and creating methodsfor now.

Object-oriented programming
To get an object to work, we have to create the class, followed by creating a method, then we call or invoke on the object.
class

object

method

Think about a karate fighter in a video game.

Object oriented programming


What are the functions of a karate fighter?

Basic structure of a Java program

The basic structure of a Java program: 1. The first few lines of the program are comments that start with // 2. The rest of the program is a class definition:

Basic structure of a Java program


public class Hello World { public static void main (String[] args) { System.out.println(Hello World); } }

Basic structure of a Java program


In each program, you have to define the class, also known as a class definition. To define a class, you begin with an opening and closing brace. Inside the braces, are comments to describe the purpose of the main method, which is defined directly below the comments. Comments are: // or slash-asterisk (/*) or asterisk-slash (*/). The slash-asterisk are commonly used for the javadoc tool. We will discuss javadoc later. However, both forms of comment symbols are fine to use. NOTE: DO NOT PUT COMMENTS NEXT TO EACH LINE OF CODE. COMMENTS ARE NORMALLY PLACE AT THE BEGINNING OF EACH PROGRAM

Basic structure of a Java program


The words used when writing programs are called identifiers such as class, static, public, void, main, String, args, System, out, println.
When we make up words in a program, you can simply choose the words you want. Example: Lincoln can be replaced with HelloWorld. A common identifier, args, which means to make an argument for the identifier. Example: String[]args means to make a call or argument for the String identifier.

Basic structure of a Java program


Reserved words are identifiers that have special meaning and are predefined in a programming language. Reserved words cannot be used for any other purpose. Examples are: Class is reserved for the object. Public is reserved for a class that is public or available to anyone. Static works on the main object. Void is reserved for the class and does not return a value on the object.

Basic structure of a Java program


A character string is an object in Java, defined by the class String. We enclose strings using double quotation marks, known as a string literal. Below are popular string literals: Today is Friday 602 Greenbriar Court, East Point, GA 30154 X empty string literal System.out means for the system to send output (usually to the monitor). Println means to print the line of text.

Next lesson:
Next Elluminate student session is August 20 at 4pm

Next Elluminate lecture session is August 20 at 9pm


If you cannot attend the lecture session, please view the recording and complete the make-up assignment located in the Discussion tab.

If you attend the session, no written assignment. Your attendance is your grade! Important: JCreator and the JDK 5 compiler must be up and running!