Fundamentals in Programming

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

I.

BASIC PROGRAMMING
PROGRAM
 Software
 Instructions to the computer BRIEF HISTORY OF JAVA

TYPES OF PROGRAMMING LANGUAGES Java is a high-level language that uses compiler to convert
source code to byte code which is then run by Java Virtual
Computers only understand binary numbers, not human Machine (JVM)
languages.
Java was made by James Gosling and colleagues at Sun
(3) different types of programming languages Microsystem
1. Machine It was first called Oak and then changed to Java in May 20,
2. Assembly 1995
3. High-level
HotJava is the first Java-enabled web browser
Machine Language
Java can be used to develop standalone applications,
 Set of primitive instructions built in computers, applications for handheld devices and many more
these instructions are in form of binary code
 1101101010011010

Assembly Language
 Developed to make the programming easy
 Assembler program converts assembly language
programs into machine-readable code

High-level Language
 English-like statements and easy to learn and
program
 Java, Python, C++, and many more A SIMPLE JAVA CODE
 Area = 5 * 5 * 3.1415;
Source code – program written in a high-level language
Must be translated into machine code for execution
Translation is done in two ways:
1. Interpreter
2. Compiler
Interpreter – reads one statement from the source code,
translate to machine code and executes the code
Parts of the code
1. Class – programs must have at least one class
2. Main method – first method that compiler looks
for in program. Without it the program will not
run
3. Statements – it is the body of your program that
represents an action
Compiler – translate entire source code to machine code,
then machine code is executed
4. Statements terminator – semicolon (;) acts as the Example of algorithm
terminator
5. Reserved words – keywords that have specific Making a telephone call
meaning to the compiler, in above example the 1. Remember or read the telephone number
reserved words are public, class, static, and void 2. Lift the receiver
6. Blocks – a pair of braces { } that forms a block that 3. Is there a dial tone? If yes, dial the phone and
groups components of a program proceed to next step. If no, put down the receiver,
PROBLEM-SOLVING PHASES go back to step 2.
4. Speak
Programming involves three steps: 5. Put down the receiver
Pseudo Code
 False code
 Pseudo – imitation; code – instruction written in
programming language
In problem solving, there are three phases;
 Generic way of describing an algorithm without
1. Analysis – define the problem, explore possible using any programming language
solutions to solve the problem identified
Pseudo code properties:
2. General solution – once identified (problem),
develop a sequence of steps to solve the problem 1. Plain English texts
3. Verify – verify the solution by following each step 2. Emphasize on the design of computer program
by hand 3. Structured English
4. Detailed and readable to draw and inference
For implementation, make specific solution by translating
5. Enables programmers to concentrate on algorithm
the algorithm to code, and test to check if the computed
results done manually the same with the output of the Example: Pseudocode to calculate the Sum & Average of
code 10 numbers
For maintenance, uses the program and maintains it by
modifying the code to meet changed requirements or to
correct errors
CREATING GENERAL SOLUTIONS
To create general solutions, use algorithm.
Algorithm is a well-defined, step by step process to solve a
particular problem. It is expressed using natural verbal but
somewhat technical annotation
Properties of an algorithm:

 No ambiguity in instructions – the action indicated


Flowcharts
should be exact and specific. Only one
interpretation for that action  Visual representation of algorithm to solve a
 Specific instruction to task – instruction is problem
specifically designed to perform a certain task.  Uses various symbols to represent date or actions
When the instruction is specific, it sometimes ask in algorithm. It uses arrow symbol to represent
for specific input. connection among other symbols
 Finite – for any input, program should terminate
after a finite number of steps Symbols:
 General to write a program – algorithm should be
able to provide a general outline of the process to
write the program
 No program codes (as far as practicable) – it does
not follow a rules of programming language.
Algorithm should only provide the logical
sequence of steps to solve a problem
Example:

Java Syntax Notes

 Case sensitive – “Hello” is different from “hello”


 Class name – first character should be in upper
case
 Program file name – should be the same as class
name
 Public static void main (String[] args) – java only
starts running a program here
 Comment – all characters after “//” are ignored

You might also like