Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
19 views51 pages

Module01 4

The CCCS 300 Programming Techniques 1 course introduces students to computer programming using Java, requiring logical thinking rather than extensive mathematical background. It emphasizes the importance of practice, engagement with assignments, and seeking help when needed, with a grading scheme that includes assignments, a midterm, quizzes, and a final exam. Students must adhere to academic integrity, utilize required software, and follow specific coding practices as they learn fundamental programming concepts.

Uploaded by

janani.22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views51 pages

Module01 4

The CCCS 300 Programming Techniques 1 course introduces students to computer programming using Java, requiring logical thinking rather than extensive mathematical background. It emphasizes the importance of practice, engagement with assignments, and seeking help when needed, with a grading scheme that includes assignments, a midterm, quizzes, and a final exam. Students must adhere to academic integrity, utilize required software, and follow specific coding practices as they learn fundamental programming concepts.

Uploaded by

janani.22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 51

CCCS 300 Programming Techniques 1

Slide 1:Introduction to Computers, Programs, and


Java

1
What is this course about
• Introduction to computer programming.
• Programming language: Java
• Little or no background needed.
The ability to think logically and in an abstract manner is more
important than any college-level mathematical background.

Note:
• This course is NOT about how to use a computer.

2
Is this course hard?

Learning how to program can be very time consuming


• The programs we write need to be “perfect” – computers
cannot “fill in the blanks”.

• On a good note, we can keep improving our program until it


works!

• The hard part is not writing a program, it’s fixing it.

3
Hints for taking this course
• Practice!
Whenever you see examples in class try them on your laptop!
• Do the homework.
Finding a solution on the web does not help. You need to engage
with the material in order to fully understand the topics and be ready
for the tests.
• Ask for help.
Make sure you don’t fall behind. Ask questions in class.
• Don’t give up!
If you cannot follow everything that is going on in the classroom,
don’t feel discouraged. Some topics need time to sink in.
4
Lectures
• 3 hours per day:
– Thursday: 6:00 pm to 9:00 pm
• 15 min break mid way

• Make sure to ask questions if you don’t understand.

• The lecture is recorded, but please come to the class..

5
Assignments (35%)
• 4 assignments
• Very important to complete ALL the assignments.
• The assignments must represent your personal effort!
• You must follow the assignment description and instructions.
• Start them early!
• Late policy:
Late submission of assignments is not allowed.(i.e., 0 grade).

6
Midterm (20%)

When?
Where: Online.

• You must attend.


• No make up exam.

7
Quizzes (10%)

When: Random
Where: Online

Length: 20 minutes.

8
Final (35%)

When: TBD
Where: Online

• You must attend.


• No make up exam.

9
Session Overview
• Grading scheme

Assignments: 35%
Midterm: 20%
Quizzes:10%
Final: 35%

10
Plagiarism
• Don’t do it!

• There are severe consequences that are not worth the risk.
You can read all about it here: www.mcgill.ca/integrity/

• It is easy to detect similarities in your assignments. We will be


using software detection tools. It would take you more effort to
try to conceal the fact that an assignment was copied than
actually do it yourself.

11
Required Software
You will need the following software for this course:
• Required: Java Development Kit (JDK).
https://www.oracle.com/technetwork/java/javase/downloads/jd
k8-downloads-2133151.html
• Highly Recommended: Eclipse or Intellij
You can use any plain-text editors to write your programs, but I
recommend Eclipse. It provides an editor that allows you to write
your program, as well as commands to compile and run it.
• Please follow the following tutorial to create your first java
program.
https://www.youtube.com/watch?v=pTFO5r03p_g
12
Any Questions?

Q Any Questions?

13
Coming up next

• What is computer science?

• What is programming?

• What are algorithms?

• Binary numbers

• What is programming language?

• Your first Java program


14
What is computer science?
• Computer science is the study of computing concepts.

• It requires thinking both in abstract terms and in concrete terms.

• Computer science can be seen as a science of problem solving. A


computer scientist
– must be able to model and analyze problems
– design solutions, and
– verify that they are correct.

15
What is Programming?

Programming can be thought as a 3 step process:


1. Think of a solution

2. Translate it into a sequence of instructions that specifies how


to perform a computation (i.e., a program). (coding)

3. Check to see if it is correct (testing) and fix any problems


(debugging).

16
What are algorithms?
• An algorithm is a sequence of steps that specifies how to solve
a problem.

• Using the terminology we have just learned, we can say that


computer science is the science of algorithms.

17
Examples
• A recipe to cook your favourite pie.
• The list of instructions you need to follow to install a game.
• The moves to solve a maze.
• The procedure we follow to build a house.

18
How does a computer work?
• Computers are made of wires. Current (electricity) can either pass through each
wire, or not.

• It is a huge amount of light switches that can be turned on and off.


• To do so, we use the ‘base 2’ system – called binary
– Off = 0
– On = 1

19
Recall decimal: base 10
When we refer to a decimal (base 10) number, like , we are
referring to the value obtained by carrying out the following
addition:

That is, we add together:


• Ones: 4
• Tens: 6
• Hundreds: 7
• Thousands: 5
20
From Decimal to Decimal

C in decimal notation (base 10)?

Note that taking the remainders from bottom to top gives us the
answer.

21
From Decimal to Binary

What is in binary?

Now, the base representation comes from reading off the


remainders from bottom to top!

22
Binary to Decimal
• Convert to a decimal number.
Position/ 7 6 5 4 3 2 1 0
Exponent

Powers of 128
Se 64 32 16 8 4 2 1

Digits 1 1 0 1 0 1 0 1

Output: 128+ 64+16 + 4+1=𝟐𝟏𝟑

23
Binary represent anything

24
What is programming language
• It’s a language (Like English or French).
• So the program can be written as a series of human
understandable computer instructions that can be read by a
compiler and translated into machine code that the computer
understand and run it.

25
Any Questions ?

Q Any Questions?

26
Our very first program
The first program we learn in programming is the Hello World
program.
Here’s the code written in Java:
public class HelloWorld {
public static void main (String[] args) {
System.out.println(“Hello, World!”);
}
}

What does it do?


 It simply displays “Hello, World!” on your screen.
27
Curly Braces

public class HelloWorld {


public static void main (String[] args) {
System.out.println(“Hello, World!”);
}
}

• Java uses curly braces to group things together.


• They denote a block of code.
• They help us keep track of what parts of the code are related.
• If one of them is missing or there’s an extra one  syntax error

28
Statements

public class HelloWorld {


public static void main (String[] args) {
System.out.println(“Hello, World!”);
}
}

• A statement is a line of code that performs a basic operation.


• All statements in Java end in a semi-colon.
• The statement in this program is a print statement: it displays a
message on your screen.

29
Printing to the console

public class HelloWorld {


public static void main (String[] args) {
System.out.println(“Hello, World!”);
}
}

• You can print a phrase on your screen using the


System.out.println() command. The phrase you
would like to see should be put inside the round parentheses.
• NOTE, Java is case-sensitive: System system SYSTEM

30
Strings

public class HelloWorld {


public static void main (String[] args) {
System.out.println(“Hello, World!”);
}
}

• Phrases that appear in quotation marks are called Strings.


• Strings literals must start and end with double quotes.

31
Methods and Classes

public class HelloWorld {


public static void main (String[] args) {
System.out.println(“Hello, World!”);
}
}

• Almost every line of code you will write in Java will be inside a
method.
• Every method you will ever write will be part of a class.
• In this program: HelloWorld is a class, main is a method.

32
Methods

public class HelloWorld {


public static void main (String[] args) {
System.out.println(“Hello, World!”);
}
}

• A method is named sequence of statements


• These open and close curly brackets tell the computer where
the main method (named block of code) starts and ends.

33
Methods

public class HelloWorld {


public static void main (String[] args) {
System.out.println(“Hello, World!”);
}
}

• This program defines a method called main, which is public,


static, and void (but don’t worry about this for now)
• The main method is a special one:
– The execution of a program always starts from the first statement in
the main method and ends when it finishes the last statement.

34
Classes

public class HelloWorld {


public static void main (String[] args) {
System.out.println(“Hello, World!”);
}
}

• This program must be saved as a file named HelloWorld.java


• Convention: names of classes starts with capital letter.
• A class is a collection of methods.
• This program defines a class called HelloWorld which is:
– public (we’ll see more about this later)
– defined by what is in between the curly brackets.

35
Comments
public class HelloWorld {
// This line is ignored
public static void main (String[] args) {
/* As well as this one
and this one
and this last one */
System.out.println(“Hello, World!”);
}
}

• A single line comment in Java starts with // and ends when you press
enter.
• A multi-line comment starts with /* and ends with */.
• All comments are ignored by the computer.

36
Demo
• Write the HelloWorld program and add some comments.

37
Code structure
• All of your methods must be inside a class.

• (Almost) all of your statements will be inside of a method.

38
Good Practice
• In Java most spaces are optional.
– But, you cannot write

publicstaticvoidmain (String[] args) {

– But it is ok to write our program as:

public class HelloWorld { public static void main


(String[] args) { System.out.println(“Hello, World!”);}}

– Tabs and newlines are optional, but without them the program becomes hard to
read!

39
When to press enter

In general, when writing your code, you should go to a new line


each time:
• You type an open curly bracket
• You type a close curly bracket
• You finished typing a statement ending in a semi-colon.
public class HelloWorld {
public static void main(String[] args) {
System.out.println(“Hello world!”);
}
}

40
Indentation
• Whenever we start a new “block” of instructions (i.e., we have
an open curly bracket) we indent (press tab) the subsequent
lines of code in.
• Whenever we end the block (i.e. we type a close curly bracket),
we un-indent the subsequent lines of code.
public class HelloWorld {
public static void main(String[] args) {
System.out.print(“Hello ”);
System.out.println(“world!”);
}
}

41
Statements
• A method in Java can have as many statements as you want.
• The computer will execute the statements (inside a method)
from top to bottom.

public class Help {


public static void main(String[] args) {
System.out.println(“Help! I need somebody.”);
System.out.print(“Help! ”);
System.out.println(“Not just anybody”);
}
}

42
print() vs println()
• println() appends to whatever is it displaying a special character called
newline.
• If you don’t want a newline at the end you can use print.
• What would the following program display?
public class Help {
public static void main (String[] args) {
System.out.print(“Help! ”);
System.out.println(“I need somebody.”);
}
}

 Help! I need somebody.


43
Escape Sequences
• Escape sequence: a sequence of characters that represents a special character.
• Examples:
– \n represents the character newline
– \” represents quotation marks (which otherwise would indicate a string)
– \t represents a tab.

public class Help {


public static void main (String[] args) {
System.out.print(“Help! I need somebody.\n”);
System.out.println(“Help! Not just anybody.”);
}
}

44
Displaying numbers
• We can also print numbers using the same methods.
• Note that in this example, we don’t need to have the double
quotes.
public class Test {
public static void main (String[] args) {
System.out.print(53);
}
}

 What happens if we try to display a String without the quotes?


45
Evaluation
System.out.println()

Whatever is between the () gets evaluated before it is printed to


the screen.
public class HelloWorld {
public static void main (String[] args) {
System.out.print(“Hello” + “World!”);
}
}

HelloWorld!
What prints?
46
Evaluation

We can combine two Strings together in Java using the ‘+’


operator.
public class HelloWorld {
public static void main (String[] args) {
System.out.print(“Hello ” + “World!”);
}
}

What prints?
Hello World!

47
The + Operator

In java, the + operator can do two different things:


1.If it is between two Strings, it concatenates them together:
“Apple” + “Banana”  “AppleBanana”

2.If it is between two numbers, it adds them together:


2 + 3  5

NOTE that you cannot perform mathematical operations on


Strings (even if they look like numbers!).

48
Difference

public class Mistery {


public static void main(String[] args)
{
System.out.print(4 + 5);
}
} What is the
difference between
the two programs?
public class Mistery {
public static void main(String[] args)
{
System.out.print(“4” + “5”);
}
}

49
Exercises
• What is in decimal?
• What is in binary?

• Write a program called MySong. This program should output


the title of your favourite song on one line, followed by the
band/singer that performs it on the next line. For example,
your program might print something like this:
Behind Blue Eyes
by The Who

50
Thank You!
Any Questions?

51

You might also like