Fundamentals of Programming PDF

Summary

This document provides an overview of fundamental programming concepts, including low-level (machine and assembly) and high-level (procedural, object-oriented, functional) programming languages. It also touches upon concepts such as syntax, semantics, compilation, and interpretation.

Full Transcript

Fundamentals of Programming ❖ Week 1: Introduction to Programming What are Programming Languages? A programming language is a formal language comprising a set of instructions that produce various kinds of output​. is a vocabulary and set of grammatical rul...

Fundamentals of Programming ❖ Week 1: Introduction to Programming What are Programming Languages? A programming language is a formal language comprising a set of instructions that produce various kinds of output​. is a vocabulary and set of grammatical rules for instructing a computer or computing device to perform specific tasks.​ Types of Programming Languages Low-Level Languages ​Machine Language The most basic level of programming language, consisting of binary code (0s and 1s). It is directly executed by the computer’s CPU.​ Assembly Language A slight abstraction above machine language, using symbolic names instead of binary code. It requires an assembler to convert it into machine code.​ ◆ Example of Assembly Language: // notebook notes: Binary (101010) - what computer reads, the computer only reads binary. A user requires an assembly in order to convert human language into binary. High-Level Languages ​These are more abstract and closer to human languages. They are easier to read, write, and maintain​ Procedural Languages Such as C, Pascal, and Fortran. They focus on a sequence of procedures or routines.​ // notebook notes: procedural reads the code line by line. Object-Oriented Languages ​Such as Java, C++, and Python. They focus on objects that contain data and methods.​ // notebook notes: Java can run diversely due to its object-oriented language system. object oriented system reads the code by class, ex: “public class HelloWorld”; the system will read the class “HelloWorld” Functional Languages Such as Haskell and Lisp. They focus on mathematical functions and avoid changing-state and mutable data.​ //notebook notes: cannot add more data and limited library. Scripting Languages Such as JavaScript, PHP, and Ruby. They are often used for automating tasks and building web applications.​ Key Concepts in Programming Languages​ ​Syntax The set of rules that defines the combinations of symbols that are considered to be correctly structured programs in that language.​ Example: In Java, a statement ends with a semicolon (;).​ Semantics The meaning of the symbols, expressions, and statements in a programming language. Example: ​ ◆ The statement int x = 5; in Java means that a variable x of type integer is being declared and initialized with the value 5. Compilation vs. Interpretation Compiled Languages The code is translated into machine code by a compiler before execution (e.g., C, C++). Interpreted Languages The code is executed line-by-line by an interpreter (e.g., Python, JavaScript). How Programming Languages Work Source Code: The human-readable instructions written by a programmer.​ Compiler/Interpreter: A tool that translates the source code into machine code​ Compiler: Translates the entire program into machine code before execution.​ Interpreter: Translates and executes the program line-by-line.​ Machine Code: The binary code that the computer’s processor can execute directly.​​ Examples of Programming Languages C language A procedural language known for its efficiency and control over system resources. Java An object-oriented language known for its portability across platforms. Python A high-level, interpreted language known for its readability and simplicity. JavaScript A high-level, interpreted language known for its readability and simplicity. Choosing a Programming Language Factors to Consider: Project Requirements The specific needs of the project (e.g., web development, data analysis).​ Performance The speed and efficiency of the language.​ Ease of Learning The complexity of the language syntax and semantics.​ Community and Support The availability of resources and community support.​ The Program Development Cycle Problem Definition Problem Analysis Algorithm Design and Representation (Pseudocode or flowchart) Coding and debugging // Extra notebook notes 4bit - encodes 4 binary numbers ○ 0110 x 10 = 1100 Octacore / 8 Cores ○ 1 core is equal to millions of binary numbers. ○ The more core the CPU has, the more efficient the user can run more instructions with the CPU. It will be able to handle multitasking as well. ○ 1mb can’t go for millions of binary code. ❖ Week 2: Introduction to Java Programming Brief History Java was created in 1991 by James Gosling, Mike Sheridan, and Patrick Naughton of Sun Microsystems and was released in 1995 as a core component of Sun Microsystems’ Java Platform. Initially called Oak, in honor of the tree outside Gosling's window, its name was changed to Java because there was already a language called Oak. The original motivation for Java was the need for platform independent language that could be embedded in various consumer electronic products like toasters and refrigerators. One of the first projects developed using Java was a personal hand-held remote control named Star 7. It was about the same time, the World Wide Web and the Internet were gaining popularity. Gosling et. al. realized that Java could be used for Internet programming. Principles There were five primary goals in the creation of the Java language: It should be "simple, object-oriented and familiar". It should be "robust and secure". It should be "architecture-neutral and portable". It should execute with "high performance". It should be "interpreted, threaded, and dynamic". Nature of Java Language A Programming Language As a programming language, Java can create all kinds of applications that you could create using any conventional programming language. A Development Environment As a development environment, Java technology provides you with a large suite of tools: a compiler, an interpreter, a documentation generator, a class file packaging tool, and so on. An Application Environment Java technology applications are typically general-purpose programs that run on any machine where the Java runtime environment (JRE) is installed. A Deployment Environment There are two main deployment environments: First, the JRE supplied by the Java 2 Software Development Kit (SDK) contains the complete set of class files for all the Java technology packages, which includes basic language classes, GUI component classes, and so on. The other main deployment environment is on your web browser. Some Features of Java The Java Virtual Machine The JVM provides the hardware platform specifications to which you compile all Java technology code. This specification enables the Java software to be platform-independent because the compilation is done for a generic machine known as the JVM. Garbage Collection Lack of memory allocation might cause memory leaks. In Java, the programmer is freed from the burden of having to deallocate that memory themselves by having what we call the garbage collection thread. The garbage collection thread is responsible for freeing any memory that can be freed. This happens automatically during the lifetime of the Java program. Code Security Code security is attained in Java through the implementation of its Java Runtime Environment (JRE). The Class Loader is responsible for loading all classes needed for the Java program. It adds security by separating the namespaces for the classes of the local file system from those that are imported from network sources. This limits any Trojan horse applications since local classes are always loaded first. After loading all the classes, the memory layout of the executable is then determined. This adds protection against unauthorized access to restricted areas of the code since the memory layout is determined during runtime. Phases of a Java Program Create a Java program by writing it in a notepad. After creating and saving your Java program, compile the program by using the Java Compiler. The output of this process is a file of Java bytecodes with the file extension.class. The.class file is then interpreted by the Java interpreter that converts the bytecodes into the machine language of the particular computer you are using. 2 Methods of creating a Java Program Using a Text Editor and Console Examples of Text Editors: Notepad, VI, emacs, MSWord, Wordpad, Open Office Text Document, etc. Using an Integrated Development Environment A programming environment integrated into a software application that provides a GUI builder, a text or code editor, a compiler and/or interpreter and a debugger. // Extra notebook notes Install JRE to run Java, Java Runtime Environment Install SDK, it contains complete sets of class. ❖ Week 3: Expressions and Operators & Java’s Selection Structure Java Expressions and Operators Are fundamental components of the language syntax, crucial for manipulating data and making decisions in programs. An expression in Java typically combines variables, constants, and operators to produce a value. Operators in Java Arithmetic operators (+, -, *, /, %) Relational operators (>,

Use Quizgecko on...
Browser
Browser