Your SlideShare is downloading. ×
0
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Computer Programming: Chapter 1
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Computer Programming: Chapter 1

1,529

Published on

เอกสารประกอบการสอนวิชา Computer Programming บทที่ 1

เอกสารประกอบการสอนวิชา Computer Programming บทที่ 1

Published in: Education, Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total Views
1,529
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
1
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Computer Programming Chapter 1 : Introduction Atit Patumvan Faculty of Management and Information Sciences Naresuan University
  • 2. 2 What is Programming? • Computers are programmed to perform tasks • Different tasks = different programs • Program • Sequence of basic operations executed in succession • Contains instruction sequences for all tasks it can execute • Sophisticated programs require teams of highly skilled programmers and other professionalsAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 3. 3 History TimelineAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 4. 4 The Evolution of Programming Languages • To build programs, people use languages that are similar to human language. The results are translated into machine code, which computers understand. • Programming languages fall into three broad categories: • Machine languages • Assembly languages • Higher-levelAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 5. 5 Assembly Languages • Assembly languages (second-generation languages) are only somewhat easier to work with than machine languages. • To create programs in assembly language, developers use cryptic English-like phrases to represent strings of numbers. • The code is then translated into object code, using a translator called an assembler.Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 6. 6 Assembly Languages Assembly Code Assembler Assembly CodeAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 7. 7 Higher-Level Languages • Higher-level languages are more powerful than assembly language and allow the programmer to work in a more English-like environment. • Higher-level programming languages are divided into three "generations," each more powerful than the last: • Third-generation languages • Fourth-generation languages • Fifth-generation languagesAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 8. 8 Third-generation languages • Third-generation languages (3GLs) are the first to use true English-like phrasing, making them easier to ! use than previous languages. • 3GLs are portable, meaning the object code created for one type of system can be translated for use on a different type of system. • The following languages are 3GLs FORTAN BASIC PHP C Java JavaScript COBOL Pascal Ruby C++ C# PythonAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 9. 9 A Typical Program Development Environment Edit Program is created in the editor and stored on disk Preprocess Preprocessor program processes the code Compile Compiler creates object code and stores it on disk. Link Linker links the object code with the libraries Load Loader puts program in memory Execute CPU takes each instruction and executes itAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 10. 10 Fourth-Generation Languages • Fourth-generation languages (4GLs) are even easier to use than 3GLs. • 4GLs may use a text-based environment (like a 3GL) or may allow the programmer to work in a visual environment, using graphical tools. • The following languages are 4GLs: Visual Basic MagicAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 11. 11 Fifth-Generation Languages • Fifth-generation languages (5GLs) are an issue of debate in the programming community – some programmers !cannot agree that they even exist. • These high-level languages would use artificial intelligence to create software, making 5GLs extremely difficult to develop. • Solve problems using constraints rather than algorithms, used in Artificial Intelligence Prolog CLIPsAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 12. 12 History of Java Language • JDK 1.0 (January 23, 1996) • Java SE 7 (July 7, 2011) • JDK 1.1 (February 19, 1997) • Java SE 8 (expected in summer 2013) • J2SE 1.2 (December 8, 1998) • J2SE 1.3 (May 8, 2000) • J2SE 1.4 (February 6, 2002) • J2SE 5.0 (September 30, 2004) • Java SE 6 (December 11, 2006)Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 13. 13 Java Editions • J2ME (Micro Edition) : Used to create programs that run on small handheld devices, such as phones, PDAs (personal digital assistants), and appliances. • J2SE (Standard Edition) : Used primarily to create programs for desktop computers or for many computers too large for J2ME and too small for J2EE. • J2EE (Enterprise Edition) : Used to create very large programs that run on servers managing heavy traffic and complicated transactions. These programs are the backbone of many online services,Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 14. 14 Common Misconceptions About Java • Java is an extension of programmer • Java is an easy programming to learn • Java is an easy environment in which to program • Java will become a universal programming for all platforms • Java is just another programming languageAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 15. 15 Common Misconceptions About Java • Java is interpreted, so it is too slow for serious applications on a specific platform. • All Java program run inside a Web pages. • Java applets are a major security risk. • JavaScript is a simpler version of Java • You should use Java instead of Perl for CGI scriptingAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 16. 16 Common Misconceptions About Java • Java will revolutionize client-server computing. • Java will allow the component-based model of computing to take off • With Java, I can replace my computer with a $500 “Internet appliance”Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 17. 17 The Java programming environment • Compared to C++: no header files, macros, pointers and references, unions, operator overloading, templates, etc. • Object-orientation: Classes + Inheritance • Distributed: RMI, Servlet, Distributed object programming. • Robust: Strong typing + no pointer + garbage collectionAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 18. 18 The Java programming environment • Secure: Type-safety and access control • Architecture neutral: architecture neutral representation • Portable • Interpreted • High performance through Just in time compilation and runtime modification of code • Multi-threadedAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 19. 19 Java Features • Well defined primitive data types: int, float, double, char, etc. • int 4 bytes [–2,147,648, 2,147,483,647] • Control statements similar to C++: if-then-else, switch, while, for • Interfaces • ExceptionsAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 20. 20 Java Features • Concurrency • Packages • Name spaces • Reflection • Applet modelAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 21. 21 The Java programming environment • Java programming language specification • Syntax of Java programs • Defines different constructs and their semantics • Java byte code: Intermediate representation for Java programs • Java compiler: Transform Java programs into Java byte codeAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 22. 22 The Java programming environment • Java interpreter: Read programs written in Java byte code and execute them • Java virtual machine: Runtime system that provides various services to running programs • Java programming environment: Set of libraries that provide services such as GUI, data structures,etc. • Java enabled browsers: Browsers that include a JVM + ability to load programs from remote hostsAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 23. 23 The Java Virtual Machine • The heart of the Java Platform is the concept of a "virtual machine" that executes Java bytecode programs. • Sits between the Java program and the machine it is running on. • Offers the program an “abstract computer” that executes the Java code • virtual machine isnt running on a CPU - it is being emulated on the CPU of the host machine.Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 24. 24 How are Java programs written? HelloWorld.java Compiler 01: public class HelloWorld { 02: javac HelloWorld.java 03: public static void main(String[] args) { 04: System.out.println("Hello, World!"); 05: } 06: } HelloWorld.class (Java bytescodes) 01: ????1" 02: @ Hello, World! 03: init>()VCodeLineNumberTableLocalVariableTabl ethis LMidterm;main([Ljava/lang/ String;)Vargs[Ljava/lang/String; Interpreter java HelloWorldAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 25. 25 Write once, run any Where HelloWorld.java 01: public class HelloWorld { Compiler 02: 03: public static void main(String[] args) { javac HelloWorld.java 04: System.out.println("Hello, World!"); 05: } 06: } HelloWorld.class HelloWorld.class Interpreter Interpreter Interpreter Java API Java Virtual Machine Hardware-Based Platform Win32 Linux MacOSAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 26. 26 How Will Java Change Your Life? • Get started quickly • Write once, run any where • Write less code • Distribute software • Write better code more easily • Develop program more quickly • Avoid platform dependencies with 100% pure JavaAtit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 27. 27 Analyzing Your First Program 01: package com.patumvan.atit.courses.compro.ch01.hello; 02: 03: public class HelloPrinter { 04: 05: public static void main(String[] args) { 06: System.out.println("Hello, World!"); 07: } 08: }Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 28. 28 Syntax Errors • Caused when the compiler cannot recognize a statement. • Are violations of the language • The compiler normally issues an error message to help the programmer locate and fix it • Also called compile errors or compile-time errors 01: public class Hello { 02: pooblic static void main(String[] args) { 03: System.owt.println("Hello, world!")_ 04: } 05: }Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction
  • 29. 29 Run-time Errors • Other major kind of error you’ll see • Happens when a program is running • We will talk more about these later • The compiler cannot identify these errors at compile time.Atit Patumvan, Faculty of Management and Information Sciences, Naresuan University Computer Programming, Chapter 1 : Introduction

×