CO252 - Introduction To Programming and Networking For Electrical Engineering

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

CO252 Introduction to programming and networking for electrical engineering

Computer engineering University of Peradeniya

Admin stuff
3

credit course
Two lectures per week and labs which will start from 3rd week Also some assignments

Programming

I will do Networking Dr. Krishanthmohan

Computer engineering University of 2 Peradeniya

About the course


Teaching

programming Not a particular language Programming methods/techniques etc. Make your own notes Based on Introduction to Programming in Java @ MIT

Most notes are from them Many thanks for them!


Computer engineering University of 3 Peradeniya

Computer engineering University of 4 Peradeniya

CPU Instructions

Computer engineering University of 5 Peradeniya

Why programming languages


Difficult

to instruct a computer using CPU instructions!


Too low level More power (you have absolute control)

Write

in a higher level language and get it translated to what the CPU can understand

Computer engineering University of 6 Peradeniya

What is the challenge!


Mom: Son, go to the shop and bring 2 coconuts. If they have eggs bring 5 Son: brings home 5 coconuts Why: there were eggs in the shop How to specify without an ambiguity! Programming languages are restricted than natural
Computer engineering University of 7 Peradeniya

Many languages
Number

of different languages

Each made for a particular area Example: C, Java, Python, Haskell, F# etc. They have their advantages and disadvantages
Need to pick the correct language for the task Mostly differ in the syntax

We'll focus on Java (fortunately or unfortunately)

Computer engineering University of 8 Peradeniya

Java

Computer engineering University of 9 Peradeniya

Compiling Java

Computer engineering University of 10 Peradeniya

First program

Computer engineering University of 11 Peradeniya

Structure

- Class name and file name should be the same - Usually capital letter for class name

Computer engineering University of 12 Peradeniya

Handling outputs

Computer engineering University of 13 Peradeniya

Types recall from 1 year

st

Computer engineering University of 14 Peradeniya

Variables

Computer engineering University of 15 Peradeniya

Assignment
Can

be combined with declaration Can use other variables and computations Value can vary over time

Computer engineering University of 16 Peradeniya

Ex1

Computer engineering University of 17 Peradeniya

Operations

Computer engineering University of 18 Peradeniya

Order of Operations

Computer engineering University of 19 Peradeniya

Ex2

Computer engineering University of 20 Peradeniya

Idea of overloading operators


Operations

might mean different things for different data types


Operators can be overloaded We'll revisit this point later

Example:

what does + means for two

Strings?

Computer engineering University of 21 Peradeniya

Next lecture
More

on types

Computer engineering University of 22 Peradeniya

You might also like