1 / 15

CS 401

Introduction to Computers and Java. CS 401. Why Program?. Computers are tools that can be programmed to perform many functions, such as: Spreadsheets Word Processors Databases Games Computers are very good at tedious, repetitive tasks. C++ C# Java JavaScript Perl PHP Python

Télécharger la présentation

CS 401

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Computers and Java CS 401

  2. Why Program? • Computers are tools that can be programmed to perform many functions, such as: • Spreadsheets • Word Processors • Databases • Games • Computers are very good at tedious, repetitive tasks

  3. C++ C# Java JavaScript Perl PHP Python Visual Basic Programming Languages • Ada • BASH • BASIC • C • COBOL • FORTRAN • Pascal

  4. Why Java? • Java • Java is... • popular • interpreted • platform-independent • object-oriented language

  5. Why Java?It's popular • Uses popular syntax • Based on C's syntax • Also used by: • C • C++ • C# • JavaScript • Perl • PHP

  6. Why Java?It's interpreted & platform-independent • Source .java code is compiled into intermediate (byte) code • Byte code is executed in software via another program called an interpreter • Benefits: • More safety features and run-time checks can be built into the language • Code can be platform-independent • As long as the correct interpreter is installed, the same byte code can be executed on any platform

  7. The same .class file can execute on any platform, as long as the JRE is installed there JRE for Mac Java Source Code (.java)‏ Java Byte Code (.class)‏ JRE for Windows Java Compiler Program Execution JRE for Linux 11001001000101110101010100100010101101010101000101011101011010101001 Hello World!

  8. Why Java?It's interpreted & platform-independent • Drawback: • Interpreted code can execute more slowly than regular compiled code • Since program is run in software rather than hardware, it may not match the execution times of code that is compiled for specific hardware • Ex: C, C++ code • No language is best for every application • However, newer Java implementations can use JIT compilation of bytecode to execute faster

  9. Why Java?It's Object-Oriented • Object-oriented • Primary mode of execution is interaction of objects with each other • We will discuss object-oriented programming in much more detail soon

  10. Running (Executing) Java Programs • First we must compile our source (.java) code into the intermediate (.class) code • We do this with the Java Compiler • javac program • Next we must interpret our .class code to see the result • We do this with the Java Interpreter, or Java Runtime Environment (JRE)‏ • java program • IDEs (e.g. Eclipse) simplify this process

  11. Running (Executing) Java Programs Java Source Code (.java)‏ Java Byte Code (.class)‏ java javac Program Execution 11001001000101110101010100100010101101010101000101011101011010101001 Hello World!

  12. Hardware • How does the computer execute Java programs? • Secondary Storage • Main Memory • CPU • Input Devices • Output Devices

  13. Hardware • Secondary Storage (e.g. Hard drives, CDs, DVDs, ...)‏ • Holds program files (source code and bytecode)‏ • Input files (and output files)‏ • Libraries • Input Devices (e.g. keyboard and mouse)‏ • User-supplied input • Output Devices (e.g. screen and printer)‏ • Provides user with output from program

  14. Hardware • Main Memory • Also called RAM (Random Access Memory)‏ • Contains currently running programs and their data • Divided into parts, accessible by different addresses • More on this in a few weeks • CPU • Performs the work for the program • Reads instructions and executes them

More Related