0% found this document useful (0 votes)
265 views6 pages

Module 2

The document provides an overview of setting up the environment and learning basic syntax for computer programming. It discusses setting up a text editor, compiler, and interpreter. It then demonstrates "Hello World" programs in C and Java to illustrate basic concepts like main functions, functions, comments, semicolons, and syntax errors. The document serves as an introduction to programming fundamentals for a Computer Programming 1 course.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
265 views6 pages

Module 2

The document provides an overview of setting up the environment and learning basic syntax for computer programming. It discusses setting up a text editor, compiler, and interpreter. It then demonstrates "Hello World" programs in C and Java to illustrate basic concepts like main functions, functions, comments, semicolons, and syntax errors. The document serves as an introduction to programming fundamentals for a Computer Programming 1 course.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DPT 6102 COMPUTER PROGRAMMING 1

1
[Environment Setup & Basic Syntax]

Module 2<Week 2><Environment Setup & Basic


Syntax>

Course Learning Outcomes:


1. To be able to setup necessary requirements before coding
2. To be able to learn the basic syntax of coding within the frameworks of C,
Java , and Python programming.

< DPT 6102 COMPUTER PROGRAMMING 1 - ENVIRONMENT >


While Environment Setup is not an aspect of any programming language, it is the first step
to be followed in writing a program before setting on.

When we say Environment Setup, that simply implies a foundation that we can do our
programming on top of. So we need the requisite software setup, i.e. installation on our PC
that will be used to write, compile, and execute computer programs.
If you need to access the Internet, for example, you need the following setup on your
desktop − A working Internet connection to connect to the Internet A Web browser like
Internet Explorer, Chrome, Safari, etc.
Similarly, to start programming using any programming language, you'll need the following
setup.
A computer programmable text editor.
A compiler to compile a binary format for the programs.
An interpreter which directly executes the programs.

< Text Editor>


A text editor is a device used to write programs for your machine. You must have a Notepad
on your Windows computer which can be used to type programs. You can initiate it by
following these steps:
Start Icon → All Programs → Accessories → Notepad → Mouse
Click on Notepad

You can use this app to type your computer program into any place and save it to a server.
Many strong editors such as Notepad++ can be downloaded and installed which is freely
available.

Course Module
If you're a Mac user, you'll either have TextEdit to start with or you can install some other
commercial editor such as BBEdit.

< Compiler>
Using your chosen programming language, you write your computer program and save it to
a text file called the program file.
Now let's try to get a little more information on how the machine understands a program
that you use a programming language to write. The machine can't really understand your
program directly in the text format, so we need to convert it to a binary format.
Conversion from text program to binary file is performed by another software named
Compiler and this method of conversion from text formatted program to binary format file
is called compilation of program. Finally, the configured function can be performed by
running binary disk.
We don't go through the specifics of a compiler and the various compilation phases.

< Interpreter>
We just thought about the compilers and the process of compiling. If you are writing your
program in a programming language that needs to be translated into binary format before
it is executed, compilers are needed.
There are other programming languages like Python, PHP and Perl that do not need to be
compiled in binary format, but can be used to read these programs with an interpreter
which reads them line by line and interprete them without conversion.

<Online Compilation>
If you can't set up any editor, compiler or interpreter on your computer, then there online
compilers that provides you with a one-click facility for compiling and running almost all of
the programs online.
So don't worry and let's start to have a exciting experience in quick and fast measures to
become a computer programmer.

< DPT 6102 COMPUTER PROGRAMMING 1 – BASIC SYNTAX >


Let's start with a bit of coding, which really will make you a programmer. We must write a
one line computer program to write Hello, World! Let's see how various programming
languages can be used to write it.

<Hello World Program in C>


Try typing the following code in an online compiler:

#include <stdio.h>
int main() {
/* printf() function to write Hello, World! */
DPT 6102 COMPUTER PROGRAMMING 1
3
[Environment Setup & Basic Syntax]

printf( "Hello, World!" );


}
You will get the following output:
Hello, World!
This program will help us see the uses of various basic concepts related to C Programming.

<Program Entry Point>


Right now, just forget about the #include <stdio.h> statement but keep a note that you have
to add the sentence to the top of a system C.

C program begins with main(), which is called the main function, and then a curly left brace
follows. The remainder of the instruction for the program is written in between and a right
curly brace eventually stops the course.
The coding part inside these two curly braces is called the program body. The left curly
brace can be in the same line as main(){ or in the next line like it has been mentioned in the
above program.

<Functions>

Functions are small units of systems, which are used to perform a specific function. For
instance the program above uses two functions: main() and printf(). Here the main()
function provides the program execution entry point and the other printf() function is used
to display an information on the computer screen.
You can write your own functions that we will see in a separate chapter, but C
programming itself offers various built-in functions such as main(), printf(), etc. that we
can use depending on our requirement in our programs.
Some of the programming languages instead of feature use the term sub-routine but their
functionality is more or less the same.

<Comments>
A C program can contain statements inside of /* ..... */. These statements are called
comments and are used to make the programs user friendly and easily understandable. The
positive thing about comments is that compilers and interpreters neglect them entirely. So
you can use your comments in whatever language you wish to post.

<Whitespaces>
When we write a program using any programming language, we use various printable
characters to prepare programming statements. These printable characters are a, b, c,......z,
A, B, C,.....Z, 1, 2, 3,...... 0, !, @, #, $, %, ^, &, *, (, ), -, _, +, =, \, |, {, }, [, ], :, ;, <, >, ?, /, \, ~. `. ", '.
Hope I'm not missing any printable characters from your keyboard.

Course Module
Apart from these characters, there are some characters which we use very frequently but
they are invisible in your program and these characters are spaces, tabs (\t), new lines(\n).
These characters are called whitespaces.
#include <stdio.h>
int main() {
/* printf() function to write Hello, World! */
printf( "Hello, World!" );
}
Output:
Hello, World!

<Semicolons>
Every individual statement in a C Program must be ended with a semicolon (;), for example,
if you want to write "Hello, World!" twice, then it will be written as follows −
#include <stdio.h>
int main() {
/* printf() function to write Hello, World! */
printf( "Hello, World!\n" );
printf( "Hello, World!" );
}
Output:
Hello, World!
Hello, World!

<Syntax Error>
If you don't obey the rules specified by the programming language, you will get syntax
errors at compilation time and the program won't be compiled. Just a single dot or comma
or a single semicolon matters from a syntax point of view and you should also take note of
these limited syntax. In the example below we skipped a semicolon, let's try to compile the
program −
#include <stdio.h>
main() {
printf("Hello, World!")
}
This program will produce the following result −
main.c: In function 'main':
main.c:7:1: error: expected ';' before '}' token
DPT 6102 COMPUTER PROGRAMMING 1
5
[Environment Setup & Basic Syntax]

}
^

<Hello World Program in Java>


public class HelloWorld {
public static void main(String []args) {
/* println() function to write Hello, World! */
System.out.println("Hello, World!");
}
}

which produces the following result −


Hello, World!

References and Supplementary Materials


Books and Journals
1. <Rachel Rivera, Eileen Choe, Ray Toal, Alexander Schneider>; <2016>; <Programming
Language Explorations>; <New York, USA>; <A Chapman & Hall Book>

2. <Cory Althoff>; <2017>; <The Self-Taught Programmer: The Definitive Guide to


Programming Professionally>; <USA>; <Self-Taught Media>

Online Supplementary Reading Materials


1. <Complete title of online reading material>; <Complete URL of online reading
material>; <Date of access to online reading material>
(Online supplementary reading materials should come from sources that are not
within the domain of “.com”)

Online Instructional Videos


1. <Brief description of video>; <Complete URL of online video>; <Date of access to
online video>
(Online instructional videos should come from sources that are not within the domain
of “.com”. In cases when videos are only available within the “.com” domain, it is
expected that 2 back-up links will be provided.)

Note:
Course Module
 There should only be one file for module per week.
 Avoid plagiarism by paraphrasing information and texts coming from the Internet and
other sources.

You might also like