0% found this document useful (0 votes)
44 views60 pages

Week2 Student

This document provides an overview of computer programming fundamentals. It discusses that computer programming involves writing instructions for a computer to perform tasks. It describes low-level languages like machine language and assembly that are closer to what computers understand, and high-level languages like Python and Java that are easier for humans. It explains how programming languages are translated into binary machine code using tools like assemblers, compilers, and interpreters. The document also covers debugging and syntax versus logical errors.

Uploaded by

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

Week2 Student

This document provides an overview of computer programming fundamentals. It discusses that computer programming involves writing instructions for a computer to perform tasks. It describes low-level languages like machine language and assembly that are closer to what computers understand, and high-level languages like Python and Java that are easier for humans. It explains how programming languages are translated into binary machine code using tools like assemblers, compilers, and interpreters. The document also covers debugging and syntax versus logical errors.

Uploaded by

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

CC102 Fundamentals of Computer Programming

Fundamentals of
Computer Programming

XENIORITA ALONDRA BIO WEEK 2


RECAP
COMPUTER PROGRAMMING
Is an art/science of creating/writing a program. It is done by
programmers to instruct a computer how a task should be done.
Attempting to get a computer to complete a specific task without
making mistakes.
Computer program instructions are also called program source
code and computer programming is also called program coding.
MACHINE LANGUANGE

This is the default computer language that is built


in primitive instructions represented to the
computer in binary code. Thus, if you want to
instruct a computer, you must write in binary code.
ASSEMBLY LANGUANGE
Assembly language are alternatives to machine languages. They use
mnemonics to represent machine language instructions. Since
computers cannot understand assembly language, we use a program
called an assembler to convert assembly language code into machine
language code. Compared to machine language, assembly language
are relatively easier to learn and use, but they are still tedious
because they are closer to machine language.
HIGH LEVEL PROGRAMMING LANGUANGE
The late 90’s ushered in the development of a new generation of
computer programming languages called high-level programming
languages. High-level programming languages are English-like
computer programming languages that are platform independent,
which means code written in high-level language can run on any
machine or computer.
Example: Python, Java, C++, JavaScript, Ruby
PROGRAMMING LANGUAGE
Programming languages serve as a middle-man of sorts.
Using a programming language, programmers write a series of program statements,
similar to English sentences, to carry out the tasks they want the program to
perform.
Fortunately, programming has evolved into an easier task because of the
development of high-level programming languages. A high-level programming
language allows you to use a vocabulary of reasonable terms, such as read, write, or
add, instead of the sequences of on and off switches that perform these tasks.
Each high-level language has its own syntax, or rules of the language.
TRANSLATORS
TRANSLATORS - ASSEMBLERS
We use translators to convert source code into binary language
(Machine Language). The binary code translated then becomes what
programmers refer to as ‘object code’. Translators can be:

ASSEMBLER
We use these to convert low-level languages into machine code.
Example of low-level languages: Machine language and assembly
language
TRANSLATORS - COMPILERS

Compilers convert source code to binary code then


execute the binary. If the program runs into an error
during the execution process, the compilation stops
without creating a binary. The most popular compiled
languages are: C, C++, Objective C, Swift, and Pascal.
TRANSLATORS - INTERPRETER

Interpreters are similar to compilers but instead of running the


entire program, they convert the code line by line (statement).
This means that every line of code runs until an error occurs.
Once the program returns an error, the interpreter
automatically stops and reports the error. The most popular
interpreted languages are: Python, Ruby, JavaScript and Pearl.
COMPILERS VS INTERPRETER

A compiler translates all of a program’s


statements before executing any, whereas an
interpreter executes each program statement
as soon as it is translated.
TRANSLATORS - HYBRID

Hybrid translators are a combination of compilers and


interpreters. They convert the source code into Bytecode.
Runtime engines then translate and execute the bytecode. The
main example here is Java that uses the Java Virtual Machine
(JVM) .
Programming
Language
The Java Buzzwords
Although the fundamental forces that necessitated the invention of Java are portability and
security, other factors also played an important role in molding the final form of the language. The
key considerations were summed up by the Java team in the following list of buzzwords:
• Simple • Multithreaded
• Secure • Architecture-neutral
• Portable • Interpreted
• Object-oriented • High performance
• Robust • Dynamic
• Distributed
The program
development process
PHASES OF PROGRAMMING

Program Source
WRITE Code Bytecode
COMPILE RUN
(SOURCE CODE)

The programmer write Java compiler takes java JVM translate bytecode
the code using Java as program as input and into machine language
programming language. generate java bytecode and executes each
as output. program statement as
soon as it is translated.
JAVA BYTECODE
Bytecode refers to a low-level representation of code. It is an
intermediate representation of code that is generated by a
compiler from the source code written by a programmer. It is
not directly executed by the computer's hardware or
operating system, but rather by a virtual machine or
interpreter that understands the bytecode instructions.
SUMMARY:
In summary, the JRE provides the runtime environment to execute
Java applications, the JVM executes Java bytecode and manages
runtime operations, the JDK is used for developing Java applications
and includes the compiler, the compiler translates human-readable
Java source code into bytecode, and the JVM (partly) acts as an
interpreter to execute bytecode efficiently.
SYNTAX ERROR VS LOGICAL ERROR
A syntax error occurs when the code violates the rules of the programming language's
syntax. These rules dictate how statements and expressions should be structured,
including proper placement of brackets, parentheses, semicolons, keywords, and other
language-specific elements.

A logical error occurs when the program's code is syntactically correct but does not
produce the expected output due to incorrect logic or flawed reasoning in the
program's design. Logical errors stem from incorrect algorithmic or logical decisions
made by the programmer.
DEBUGGING
Debugging is the process of finding and fixing mistakes in computer
programs. These mistakes, or "bugs," can cause problems like crashes,
wrong results, or unexpected behavior. Errors can occur due to
various reasons, such as syntax mistakes, logical flaws, incorrect data,
unexpected behavior, or performance issues. Debugging is an
essential skill for programmers to ensure the correctness and
reliability of their code.
Integrated Development Environment
• The answer is we use an IDE (Integrated Development Environment) to
write code
• A place to write, run and debug code and also convert it to machine code
• IDE are like any other program on your computer except used for the
facilitation of code.
• Examples: Netbeans, Eclipse, IntelliJ, visual studios, sublime etc.
• Built in Error-checking
• Auto fill for frequently used words
Remember that computers can only understand and perform the
manipulation of 0’s and 1’s. These 0’s and 1’s are called binary digits.
The smallest unit of information that a computer supports refers to
bits. For the user to communicate with computers, these digits are
being combined to represent a character, number or symbol. As
programmers, it is essential to understand how data is being
translated from one form to another.
BIT vs BYTE
The term "bit" stands for "binary digit." A bit is the smallest unit of data in a
computer and can represent one of two states: 0 or 1. It's like the atom of
computing. Computers process and store information using bits. For instance, a bit
can represent the state of a switch being on (1) or off (0).
A "byte" is a group of 8 bits. It's a fundamental unit of data that's often used to
represent a character, like a letter, number, or symbol. Bytes provide a way to
work with larger pieces of information than just individual bits. A byte can
represent 256 different values (2^8), which includes all the possible combinations
of 8 bits.
NUMBER SYSTEM
NUMBER SYSTEM

Number system is also called numeral system. Number system is


any notation that represents numerals or numbers. There are a
few common number systems that people use:
DECIMAL SYSTEM
This is the most common number system we have ever known and the basis of
how we count, as we know it. Decimal number system has a base or radix of 10.
This means that the numbers are notated with one digit starting a sequence from
1 to 9, ending the sequence with a 0 prefixed with another digit, and then start
another sequence from 1-9.
The decimal system uses ten (10) digits, 0-9 to represent all quantities and each
digit represents a power of ten.
BINARY SYSTEM
This is considered as the computer machine language. It means that on the
machine level, this is only recognizable data to computer. The binary simulates the
toggle switches that a computer uses to perform its calculations. It has the base or
radix of 2.
The binary system uses two digits (0 and 1) to represents all quantities, each digits
represents a power of 2.
OCTAL SYSTEM
The octal number system is a result of simplifying the representation of
characters in programming a computer. As computing became more and more
advanced, as well as convenient for users, programmers needed to find a way to
simplify the way the data is represented. So they group the binary bits into three
(3) called octets. Thus, 23 is equal to 8, deriving the name octal.
The octal system uses eight digits (0-7) to represents all quantities, each digits
represents a power of 8.
HEXADECIMAL SYSTEM
This number system is a spin off from the octal system. Due to significant
developments in the way computers are being used, the instructions and character
representations fe into it have grown as well. The hexadecimal system has a base
or radix of 16.
The hexadecimal system uses 16 digits (0-9 and A-F) to represents all quantities,
each digits represents a power of 16.
ASCII TABLE
(American Standard Code for Information Interchange)

As the computer evolved to be an-around computing device, the need to input


and represent different characters must be made. Thus, a system has to be
introduced to translate characters to binary digits. The idea was to assign a
specific decimal number for each character(numbers, letters, punctuation and
other special character) converting it into String of bits. This String of bits is now
what we call a byte, consisting of 8 binary bits that could represents 255
characters. (A-Z is from 65-90, a-z is from 97-122)
ASCII TABLE
Anatomy of a Java
Basic Syntax
Understanding main method
Adding a Comment
Documenting your program code helps you remember why you wrote lines
of code the way you did. Program comments are nonexecuting statements
that you add to a program for the purpose of documentation. Programmers
use comments to leave notes for themselves and for others who might read
their programs in the future.
Commenting out
If a program is not performing as expected, you can “comment out”
various statements and subsequently run the program to observe the
effect. When you comment out a statement, you turn it into a
comment so the compiler does not translate it, and the JVM does not
execute its command. This can help you pinpoint the location of errant
statements in malfunctioning programs.
COMMENTS IN JAVA
There are three types of comments in Java:
• Line comments start with two forward slashes ( // ) and continue to the
end of the current line. A line comment can appear on a line by itself or at
the end (and to the right) of a line following executable code. Line
comments do not require an ending symbol.
COMMENTS IN JAVA
There are three types of comments in Java:
• Block comments start with a forward slash and an asterisk ( /* ) and end
with an asterisk and a forward slash ( */ ). A block comment can appear on
a line by itself, on a line before executable code, or on a line after
executable code. Block comments also can extend across as many lines as
needed.
COMMENTS IN JAVA
There are three types of comments in Java:
• Javadoc comments are a special case of block comments. They begin with
a forward slash and two asterisks ( /** ) and end with an asterisk and a
forward slash ( */ ). You can use javadoc comments to generate
documentation with a program named javadoc.
main() method
main( ) is simply a starting place for your program. It is the method called
when a Java application begins. A complex program will have dozens of
classes, only one of which will need to have a main( ) method to get
things started. Furthermore, for some types of programs, you won’t
need main( ) at all. However, for most of the programs main( ) is
required.
main() method
Keep in mind that Java is case-sensitive. Thus, Main is different from main. It
is important to understand that the Java compiler will compile classes that
do not contain a main( ) method. But java has no way to run these classes.
So, if you had typed Main instead of main, the compiler would still compile
your program. However, java would report an error because it would be
unable to find the main( ) method.
Understanding main method
The keyword static allows main( ) to be
The public keyword is an access called without having to instantiate a The keyword void simply tells
modifier, which allows the particular instance of the class. the compiler that main( ) does
programmer to control the visibility not return a value.
of class members.
The last character on the line is
the {. This signals the start of
main( )’s body. All of the code
System is a that comprises a method will
predefined class occur between the method’s
that provides opening curly brace and its
access to the closing curly brace.
system, and out is
the output stream
that is connected
to the console.
println() is a method. Method
"Hello World!" is a literal string
Dots separate names are always followed by
Closing curly braces of method that is the argument to the
classes, objects, parentheses.
main. println() method.
and methods.
Closing curly braces of class
DemoWeek2.
ANY QUESTIONS?
IDENTIFIERS,
VARIABLES, AND DATA TYPES
IDENTIFIERS
▪ Identifier - In programming languages, identifiers are used for identification purposes.
▪ Case-sensitivity - Java is case sensitive, which implies that the identifier Hi and hi
would have distinctive importance in Java.
▪ Java Identifier- All Java components require names. Names utilized for classes,
variables and strategies are called identifiers. In Java, there are a few focuses to recall
about identifiers.

➢ All identifiers ought to start with a letter (beginning to end or a to z),


underscore (_) or special character ($).
➢ After the first character, identifiers can have any mix of characters.
➢ You cannot use a keyword as an identifier.
➢ Most significantly, identifiers are case-sensitive. So, Sample is not same as
sample. Examples of identifiers include $salary, age, __1_value and _value.
➢ Examples of illicit identifiers include –compensation and 123abc.
IDENTIFIERS
Beginning an identifier with a lowercase letter and capitalizing subsequent
words within the identifier is a style known as camel casing. An identifier such
as lastName resembles a camel because of the uppercase “hump” in the middle.
ANY QUESTIONS?
VARIABLES
Variables in a program are used to store data such as numbers
and letters. They can be thought of as containers of a sort. The
number, letter, or other data item in a variable is called its value.
This value can be changed, so that at one time the variable
contains, say, 6, and at another time, after the program has run
for a while, the variable contains a different value, such as 4.
Primitive Data Types:
Primitive data types are the basic, fundamental types that Java
uses to represent simple values. Unlike reference data types,
which hold references to objects, primitive data types store the
actual values themselves. These types are used to represent
basic, atomic values like numbers and characters.
PRIMITIVE DATA TYPES
An item’s data type describes the type of data that can be stored there, how much memory the item
occupies, and what types of operations can be performed on the data. Java provides for eight
primitive types of data. A primitive type is a simple data type.
byte:
• byte information sort is a 8-bit marked two’s supplement whole number.
• Maximum worth is 2^7 -1, which is equal to 127. This value is also included in the range of
these values.
• Minimum worth is -2^7, which is equal to -128.
• Default value stored in a variable of this type is 0. byte information sort is utilized to spare
space in vast exhibits, principally set up of numbers, since a byte is four times littler than an int.
• Example: byte x = 200, byte y = -20
short:
• short information sort is a 16-bit marked two’s supplement number.
• Maximum value is 2^15 -1, which is equal to 32,767. This number is also included in the range.
• Minimum value is -2^15, which is equal to -32,768. short information sort can likewise be
utilized to spare memory as byte information sort.
• A short is 2 times littler than an int. The default value for this data type is 0.
• Example: short x = 425164, short y = -76686
PRIMITIVE DATA TYPES
int:
• int information sort is a 32-bit marked two’s supplement number.
• Maximum value for this data type is 2^31 -1, which is equal to 2,147,483,647. This
number is also included in the range for this data type.
• Minimum value for this data type is -2^31, which is equal to - 2,147,483,648.
• int is for the most part utilized as the default information sort for its indispensable
qualities unless there is a worry about memory.
• The default value for this data type is 0.
• Example: int x = 826378, int y = -64782

long:
• long information sort is a 64-bit marked two’s supplement whole number.
• Maximum value for this data type is 2^63 -1, which is equal to
9,223,372,036,854,775,807.
• Minimum value for this data type is -2^63, which is equal to -9,223,372,036,854,775,808.
This sort is utilized when a more extensive memory range than int is required.
• The default value for those data type is 0l.
• Example: long x = 174636l, int y = -536452l
PRIMITIVE DATA TYPES
float:
• float is a data type, which is know for its solitary exactness, 32-bit IEEE 754 gliding
point.
• float is for the most part used to spare memory in vast exhibits of coasting point
numbers.
• The default value for this data type is 0.0f. float information sort is never utilized
for exact values, for example, money.
• Example: float x = 254.3f

double:
• double information sort is a float with two fold exactness 64-bit IEEE 754 drifting
point.
• This information sort is for the most part utilized as the default information sort for
decimal qualities.
• double information sort ought to never be utilized for exact values, for example,
money.
• The default value for this data type is 0.0d.
• Example: double x = 321.4
PRIMITIVE DATA TYPES
boolean:
• boolean information sort speaks to one bit of data.
• Any boolean variable can assume one of the two values: true or false.
• This information sort is utilized for basic banners that track genuine/false
conditions.
• The default value for this data type is false.
• Example: boolean check = true;

char:
• char information sort is a solitary 16-bit Unicode character.
• Maximum value for a variable of this type is “\uffff” (or 65,535
comprehensive).
• Minimum value for a variable of this type is “\u0000” (or 0).
• char information sort is utilized to store any character.
• example: char text =‘a’
Reference Data Types (Reference Types):
In Java, a reference data type refers to a type that represents
references to objects in memory rather than holding the actual
data directly. These types allow you to work with more complex
data structures and objects. Unlike primitive types that store the
actual value, reference types store a reference or memory
address pointing to the location where the object's data is stored.
REFERENCE DATA TYPES
Reference data types are used to store references to objects, rather
than the actual data.

• Classes: User-defined data types that can have fields, methods,


and constructors.
• Interfaces: Define a contract for methods that implementing
classes must provide.
• Arrays: Homogeneous collections of elements.
• Enums: A special type used to define a set of constants.
• Others: References to instances of various built-in classes like
String, ArrayList, etc.
VARIABLE DECLARATION
Variables are containers for storing data values. In a Java program, you must
declare a variable before it can be used. A variable declaration has the
following form:
How can we declare variables?
datatype identifier;
datatype identifier = value;
datatype identifier1, identifier2;
datatype identifier1 = value, identifier2 = value;
code
example:
ASSIGNMENT STATEMENTS
The most straightforward way to give a variable a value or to change its value
is to use an assignment statement. For example, if answer is a variable of type
int and you want to give it the value 42, you could use the following
assignment statement:
answer = 42;
The equal sign, =, is called the assignment operator when it is used in an
assignment statement. It does not mean what the equal sign means in other
contexts. The assignment statement is an order telling the computer to change
the value stored in the variable on the left side of the assignment operator to
the value of the expression on the right side. assignment statements take the
form Variable = Expression;
Combining a Variable Declaration and an
Assignment
You can combine the declaration of a variable with an assignment
statement that gives the variable a value.

SYNTAX
Type Variable_1 = Expression_1, Variable_2 = Expression_2,
. . .;

EXAMPLES
int numberSeen = 0, increment = 5;
double height = 12.34, prize = 7.3 + increment;
char answer = 'y';
ANY QUESTIONS?
Fundamentals of Computer Programming

The End

XENIORITA ALONDRA BIO WEEK 2

You might also like