Programming introduction

From Juneday education
Jump to: navigation, search

NOTE-TO-SELF: This book seems to be more about computer introduction than programming introduction? The Compiler section seems to be the only thing associated with programming - the rest seems more like the Computer introduction book?

Meta information about this chapter

  Created Reviewed Ready
Exercises ok ok no
Solutions ok no no
Videos ok ok ok

Expand using link to the right to see the full content.

Introduction

In this presentation the student will be introduced to programming by comparing programming to normal every day actions, such as washing clothes.

In this lecture we will get a better understanding of the compiler and the steps performed when compiling source code.

Purpose

The purpose of this presentation is to make it easier for the student to understand the following lectures.

Writing software in languages such as C, C++ and Java means you at some point must transform your source, which is in text form, into a form executable by either the operating system or a virtual machine.

Requirements

It is assumed that the student is familiar with OS (operating system), program, file system, file and file types.

No previous programming knowledge is required.

The following concepts:

  • hardware
  • os
  • virtual-machine
  • filetype

Goal

After this lecture the student shall have basic understanding of what a program is, how it is written and how it relates to every day actions we humans do.

The student should:

  • understand the role of a compiler

Concepts

Instructions to the teacher

Common problems

Videos

All videos in this chapter:

See below for individual links to the videos.

Programming

Description

Programming is the practice of writing text files (so called source code files) where you express instructions to be performed by a computer. You express these instructions using a so called programming language, which is a set of rules for how to write said instructions.

The product of programming is a set of source code text files which typically are transformed into a a file or several files in language which is also understood by the computer or some existing computer program. This transformation from source code to files that are meaningful to the computer (or some existing computer software) is generally referred to as compiling.

Further on in this book, we will also address different ways to analyse what we want our programs to do, as well as different ways to accomplish that. Those activities may also be seen as activities belonging to the practice of programming.

Videos

  1. Hardware (eng) (sv) (download presentation)

Exercises

  1. What is the hardware used to store information temporarily (until the power goes off) called?

Solutions

Expand using link to the right to see the full content.


  1. Memory

Links

Compiler

Description

A program that transforms (or transform) software written in one programming language to another programming language. It will take an entire course to give you enough information about compilers and how to write them but in our courses this will do fine.

Examples of compilers are Java Compiler which translates from Java source code to Java byte code (to be executed by the Virtual Machine) and C Compiler which translates from C source code to machine code.

Expand using link to the right to see an example of compilation of a C program.

C compilation

Let's give an example in C. Here's the source of a file called hello.c:

#include <stdio.h>

int main(void)
{
  printf("Hello world\n");
  
  return 0;
}

Source code can be found at github: hello.c (download with curl: curl -O https://raw.githubusercontent.com/progund/junedaywiki/master/compiler/hello.c).

To compile the file above you type the following:

$ gcc hello.c -o hello

Now we have transformed hello.c (yet kept the original) into a program called hello.

To execute the program (as result from compiling hello.c you can type the following:

$ ./hello
Hello world

If we want to check the file type we can do the following:

$ file hello
hello: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 3.2.0, BuildID[sha1]=59c0391f9cb05af1e15cf6f96db55b6bf141ad8b, not stripped

Note: the printout from file is from the author's laptop running GNU/Linux. The printout may differ on your computer.

Expand using link to the right to see an example of compilation of a Java program.

Java compilation

Let's give an example in Java. Here's the source of a file called Hello.java:

public class Hello {

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

}

Source code can be found at github: Hello.java (download with curl: curl -O https://raw.githubusercontent.com/progund/junedaywiki/master/compiler/Hello.java).

To compile the file above you type the following:

$ javac Hello.java

Now we have transformed Hello.java (yet kept the original) into a file called Hello.class.

To execute the program (as result from compiling Hello.java you can type the following:

$ java Hello 
Hello world

If we want to check the file type we can do the following:

$ file Hello.class 
Hello.class: compiled Java class data, version 52.0 (Java 1.8)

Note: the printout from file is from the author's laptop running GNU/Linux. The printout may differ on your computer.

Videos and slides

  1. Compiler (eng) (sv) (download presentation)

Links

Programming with Java book

previous chapter next chapter

External links

Wikipedia links for the keen student:

Compiler