150 likes | 259 Views
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
E N D
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 Visual Basic Programming Languages • Ada • BASH • BASIC • C • COBOL • FORTRAN • Pascal
Why Java? • Java • Java is... • popular • interpreted • platform-independent • object-oriented language
Why Java?It's popular • Uses popular syntax • Based on C's syntax • Also used by: • C • C++ • C# • JavaScript • Perl • PHP
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
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!
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
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
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
Running (Executing) Java Programs Java Source Code (.java) Java Byte Code (.class) java javac Program Execution 11001001000101110101010100100010101101010101000101011101011010101001 Hello World!
Hardware • How does the computer execute Java programs? • Secondary Storage • Main Memory • CPU • Input Devices • Output Devices
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
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