0
Learning Java
DeAnna Riddlespur
Spring 2014
Introduction to Computers,
Programs, And Java
Objectives
●

●

●

●

To Understand computer basics, programs, and
operatin...
Objectives
●

To display output on the console

●

To explain the basic syntax of a Java Program

●

To create, compile an...
Introduction
The central theme we focus on is to learn how to solve
problems by writing a program
●

●

●

What is program...
●

●

●

There are many programming languages
Each language was invented for a specific purposeto build on the strengths o...
1.2 What is a computer?

A computer is an electronic device that stores and processes data.
●

●

●

●

A computer include...
Computer Components
●

Central Processing unit(CPU)

●

Memory ( main memory)

●

Storage devices ( disks and CDs)

●

Inp...
●

●

●

●

●

●

Motherboard is a circuit case that connects all of the
parts of a computer together
The bus is build int...
●

●

●

●

●

●

CPUs are build on small silicon semiconductor chips
tht contain millions of tiny electric switches calle...
●

●

●

●

●

CPUs were oriinally developed with only one core.
The core is the part of the processor that performs
the r...
●

Storing information in a computer is simply a matter
of setting a sequence of switches on or off.

●

The minimum stora...
●

In ASCII encoding scheme the character c is
represented by 01000011 in one byte.

Computer's storage capacity
●

Kiloby...
●

●

●

●

●

A computer's memory consists of an ordered
sequence of bytes for storing programs as well as
data that the ...
●

●

●

●

●

Memory is also referred to as random access
memory(RAM)
Because the bytes in the memory can be accessed
in ...
●

●

●

●

●

●

Memory is built on silicon semiconductor chips that
have millions of transistors embedded on their
surfa...
Three main types of storage devices:
●

Magnetic disk drives

●

Optical disc drives (CD and DVD)

●

USB flash drives

●
...
●

●

●

●

●

CD-RW can be used like a hard disk; you can write
data onto the disc and then over wtite that data with
new...
●

Input and output devices let the user communicate
with the computer

●

A keyboard is a device for entering input

●

A...
●

The insert delete page up and page down keys
are used in word processing and other programs for
inserting text and obje...
●

●

●

●

●

●

●

Pixesl (picture elements) are tiny dots that form an
image on the screen
Dot pitch is the amount of s...
●

●

Wireless networking is available in homes
businesses and schools.
A wireless adapter enables the computer to connect...
●

●

●

●

●

Assembly language uses a short descriptive word
known as a mnemonic to represent each of the
machine langua...
●

●

●

●

●

●

●

High level languages are platform independent
Platform indemendent means that you can write a
program...
●

An interpreter reads one statement from the source
code translates it to the machine code or virtual
machine code and t...
Popular Programming
Languages
Ada
●

Named for Ada lovelace, who worded on mechanical
general- purpose computers. The Ada ...
C
●

●

Developed at Bell Laboraories.
C combines the power of an assembly language with
the ease of use and portability o...
FORTRAN
●

●

FORmula TRANslation.
Popular for scientific and mathematical applications.

Java
●

Developed by Sun Microsy...
Python
●

A sinple general purpose scripting language good for
writing short programs

Visual Basic
●

●

Visual Basic was...
●

●

An interpreter translates and executes a program
one statement at a time
A compiler translates the entire source pro...
Major Tasks of an Operating
system
●

Controlling and monitoring system activities

●

Allocating and assigning system res...
●

●

●

●

●

●

●

Operating systems perform basic tasks
An operating system must also ensure that different
programs an...
●

●

Multiprocessing or parallel processing uses two
or more processors together to perform subtasks
concurrently and the...
Java, the World Wide Web
and Beyond
Java is a powerful and versatile programming
language for developing software running ...
●

●

●

●

Java is popular particularly because of its promise
that you can write a program once and run it
anywhere
Java...
●

●

●

●

●

The World Wide Web is an electronic information
repository that can be accessed on the Internet from
anywhe...
●

●

●

●

●

●

Applets make the Web responsive, interactive, and
fun to use
Applets are embedded in an HTML file
HTML( ...
The software for Android cell phones is
developed using Java
The Java Language Specification,Api,JDK, and
IDE

●

Java syn...
●

●

●

●

●

Computer languages have strict rules of usage
If you do not follow the rules the computer will not be
able ...
Three Editions of Java
●

●

●

Java Standard Edition (Java SE) to develop clientside standalone applications or applets
J...
●

●

JDK consists of a set of separate programs, each
invoked from a command line for developing and
testing Java prorams...
A simple Java Program
A Java program is executed from the main
method in the class.
●

●

●

Console- an old computer term...
1 public class Welcome {
2
public static void main
( String [] args) {
3
//Display message Welcome
to Java! On the console...
Note the line numbers are for
reference purposes only!!!!
Line 1 defines a class.
●

Every Java program must have at least...
●

●

●

●

●

●

●

A method is a construct that contains statements
The main method in our program contains the
System.o...
●

●

●

●

●

●

Class compiler understands that the word after
class is the name for the class
Public, static, and void ...
●

●

●

●

●

●

●

Block or paragraph comments are on several lines
When the compiler sees // it ignors all text after /...
●

●

●
●

Blocks can be nested meaning that one
block can be placed within another

An opening brace must be matched by a...
Special Characters
●

●

The most common errors made as one
learns to program are syntax errors
The multiplication operator in Java is *
Create, Compiling and
Executing a Java Program
●

●

●

●

You save a Java program in a .java file and compile it into
a ....
●

A java compiler translates a Java source
file into a Java bytecode file
To compile Welcome.java:
javac Weclome.java

●
...
●

The java language is a high level language

●

Java bytecode is a low level language

●

●

●

●

●

Bytecode is simila...
●

●

●

●

●

●

To extcute a java program is to run the program's
bytecode
You can execute the bytecode on any platfor w...
●

●

●

The JVM first loads the bytecode of the class to memory
using a program called the class loader
If your program u...
Displaying Text in a Message
Dialog Box
You can display text in a graphical dialog box
●

●

To display text in a message ...
WelcomeInMessageDialogBox.java
1 /* This application program displays Welcome to Java!
2 * in a message dialog box.
3 */
4...
Upcoming SlideShare
Loading in...5
×

Java 101 @ chattahoochee

227

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
227
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Java 101 @ chattahoochee"

  1. 1. Learning Java DeAnna Riddlespur Spring 2014
  2. 2. Introduction to Computers, Programs, And Java Objectives ● ● ● ● To Understand computer basics, programs, and operating systems To describe the relationship between Java and the World Wide Web The understand the meaning of Java language specification, AOI, JDK, and IDE To write a simple Java program
  3. 3. Objectives ● To display output on the console ● To explain the basic syntax of a Java Program ● To create, compile and run Java programs ● ● ● To display output using the JOptionPane message dialog boxes To become famiiar with Java programming style and documentaton. To explain the differences between syntax errors, runtime errors and logic errors
  4. 4. Introduction The central theme we focus on is to learn how to solve problems by writing a program ● ● ● What is programming? The term programming means to create( or develop) software, which is also called a program. Software contains the instructions that tell a computer ( or device) what to do. Programming languages are powerful tools that software developers use to create software.
  5. 5. ● ● ● There are many programming languages Each language was invented for a specific purposeto build on the strengths of a previous language or to give the programmer a new and unique set of tools. The key is to learn how to solve a problem using a programming approach.
  6. 6. 1.2 What is a computer? A computer is an electronic device that stores and processes data. ● ● ● ● A computer includes both hardware and software. Hardware - comprises the visible, physical elements of the compute Software - provides the invisible instructions that control the hardware and make it perform a specific task. Knowing computer hardware can help you better understand the effects that a program's instructions have on the computer and its components.
  7. 7. Computer Components ● Central Processing unit(CPU) ● Memory ( main memory) ● Storage devices ( disks and CDs) ● Input devices ( mouse and keyboard) ● Output devices ( such as monitors and printers) A computer's components are interconnected by a subsystem called a bus.
  8. 8. ● ● ● ● ● ● Motherboard is a circuit case that connects all of the parts of a computer together The bus is build into the computer's motherboard. The central processing unit (CPU) is the computer's brain.It retrieves instructions frommemory and executes them. The CPU usually has two components ---The control unit controls and coordinates the actions of the other components. ---The arithmetic/logic unit performs numeric operations ( addition, subtraction, multiplication, division) and logical operations ( comparisions )
  9. 9. ● ● ● ● ● ● CPUs are build on small silicon semiconductor chips tht contain millions of tiny electric switches called transistors for processing information. The internal clock emits electronic pusles at a constant rate. These pulses are used to control and synchronize the pace of operations. A higher clock speed enables more instructions to be executed in a given period of time. The unit of measurement of clock speed is the hertz (Hz), with 1 hertz equaling 1 pulse per second. In the 1990's computers measured clocked speed in megahertz(MHz) The clock speed of a computer is now usually stated in gigahertz (GHz)
  10. 10. ● ● ● ● ● CPUs were oriinally developed with only one core. The core is the part of the processor that performs the reading and executing of instructions. Multicore CPU is a single component with two or more independent processors. A computer is nothing more than a series of switches. Each switch exists in two states : on or off ● If the switch is on its value is 1 ● If the switch is off the value is 0 ● These 0s and 1s are interpreted as digits in the binary number system and are called bits ( binary digits)
  11. 11. ● Storing information in a computer is simply a matter of setting a sequence of switches on or off. ● The minimum storage unit in a computer is a byte ● A byte is composed of eight bits ● ● ● ● To store a number that cannot fit into a single byte, the computer uses several bytes. An encoding scheme is a set of rules that govern how a computer translates characters, numbers and symbols into data the computer can actually work with. Most schemes translate each character into a predetermined string of numbers
  12. 12. ● In ASCII encoding scheme the character c is represented by 01000011 in one byte. Computer's storage capacity ● Kilobyte(KB) 1,000 bytes ● megabyte(MB) 1 million bytes ● Gigabyte (GB) 1 billion bytes ● Terabyte(TB) 1 trillion bytes 1 MB can store 50 pages of documents . 1 GB can store 50,000 pages of documents. Two hour high resolution movie 8 GB
  13. 13. ● ● ● ● ● A computer's memory consists of an ordered sequence of bytes for storing programs as well as data that the program is working with Memory is like the computer's work area for executing a program A program and its data must be moved into the computer's memory before they can be executed by the CPU Every byte in the memory has a unique address The unique address is used to locate the byte for storing and retreiving data.
  14. 14. ● ● ● ● ● Memory is also referred to as random access memory(RAM) Because the bytes in the memory can be accessed in any order the memory is also referred to as random access memory The more RAM a computer has, the faster it can operate. But there are limits A memory byte is never empty, but its initial content may be meaningless to your program Current content of a memory byte is lost when new information is placed in it.
  15. 15. ● ● ● ● ● ● Memory is built on silicon semiconductor chips that have millions of transistors embedded on their surface. Compared to CPU chips, memory chips are less complicated, slower, and less expensive. RAM is a volatile form of data storage Volatile means any information that has been stored in memory si lost when the system's power is turned off Programs and data are permanently stored on storage devices Programs and data are moved to memory when the computer actually uses them.
  16. 16. Three main types of storage devices: ● Magnetic disk drives ● Optical disc drives (CD and DVD) ● USB flash drives ● ● ● ● ● --Drives are devices for operating a medium. ----A storage medium physically stores data and program instructions. Hard disks are used for permanently storing data and programs CD stands for compact disc CD-R is for read only permanent storage; the user cannot modify its contents once they are recorded
  17. 17. ● ● ● ● ● CD-RW can be used like a hard disk; you can write data onto the disc and then over wtite that data with new data DVD digital versatile disc or digital video disc Universal serial bus (USB) connectors allow the user to attach many kids of peripheral devices to the computer. A USB flash drive is a device for storing and transporting data . A flash drive acts like a protable hard drive that can be plugged intor your computer's USB port.
  18. 18. ● Input and output devices let the user communicate with the computer ● A keyboard is a device for entering input ● A keyboard consists of the keys for entering input ● ● ● ● Function keys are located across the top of the keyboard and are prefaced with the letter F. A modifier key is a special key that modifies the normal action of another key when the two are pressed at the same time The numberic keypad is located on the right side of most keyboards, it is a spearate set of keys styled like a claculator to use for entering numbers quickly. Arrow keys, are used to move the mouse on the screen in many kinds of programs
  19. 19. ● The insert delete page up and page down keys are used in word processing and other programs for inserting text and objects, deleting text and objects and moving up or down through a document one screen at a time ● ● ● ● A mouse is a pointing device A cursor is a graphical pointer ( usually in the shape of an arrow) The monitor displays information. The screen resolution and dot pitch determine the quality of the display The screen resloution specifies the number of pixels in horizontal and vertical dimensions of the display device.
  20. 20. ● ● ● ● ● ● ● Pixesl (picture elements) are tiny dots that form an image on the screen Dot pitch is the amount of space between mizels, measured in milimeters. The smaller the dotpitch the sharper the display. A modem uses a phone line and can transfer data at a speed up to 56,000bps ( bits per second) A digital subscriber line(DSL) connection also uses a standard phone line but it can transfer data 20 time faster than a standard dial up A cable modem uses the cable TV line maintained by the cable company and is generally faster than DSL A network interface card(NIC) is a device that connects a computer to a local area network .
  21. 21. ● ● Wireless networking is available in homes businesses and schools. A wireless adapter enables the computer to connect to a local area network and the internet. Computer programs, known as software, are instructions that tell a computer what to do .Computers do not understand human languages so programs must be written in a language a computer can use. All programs must be converted into a language the computer can understand. ● ● Machine Language-a computer's native language – a set of built in primitive instructions These instructions are in the form of binary code.
  22. 22. ● ● ● ● ● Assembly language uses a short descriptive word known as a mnemonic to represent each of the machine language instructions. The mnemonic add typically means to add numbers and sub means to subtract the numbers Assembly languages were developed to make programming easier An assembler is a program used to translate assembly language programs into machine code. Assembly language is referred to as a low level language because assembly language is close in nature to machine language and is machine dependent.
  23. 23. ● ● ● ● ● ● ● High level languages are platform independent Platform indemendent means that you can write a program in a high level language and run it in different types of machines. Higl level languages are english like and easy to learn and use The instructions in a high level programming language are called statements. A program written n a high level language is called a source program or source code A source program must be translated into machine code for execution. Translation can be done using an interpreter or a compiler
  24. 24. ● An interpreter reads one statement from the source code translates it to the machine code or virtual machine code and then executes it right away.
  25. 25. Popular Programming Languages Ada ● Named for Ada lovelace, who worded on mechanical general- purpose computers. The Ada language was developed for the Department of Defense and is used mainly in defense projects BASIC ● Beginner's All purpose Symbolic Instruction Code. It was designed to be learned and used easily by beginners.
  26. 26. C ● ● Developed at Bell Laboraories. C combines the power of an assembly language with the ease of use and portability of a high level language C++ ● C++ is an object oriented language, based on C C# ● ● Pronounced “C Sharp” it is a hybrid of Java and C++ and was developed by Microsoft. COBOL ● Common Business Oriented Language ● Used for business applications
  27. 27. FORTRAN ● ● FORmula TRANslation. Popular for scientific and mathematical applications. Java ● Developed by Sun Microsystems ● Now a part of oracle ● It is widely used for developing platform independent internet applications Pascal ● ● Named for Blaise Pascal who pioneered calculating machines in the seventeenth century It is a simple structured general purpose language primarly for teaching programming
  28. 28. Python ● A sinple general purpose scripting language good for writing short programs Visual Basic ● ● Visual Basic was developed by microsoft Enables the programmers to rapidly develop graphical user interfaces
  29. 29. ● ● An interpreter translates and executes a program one statement at a time A compiler translates the entire source program into a machine language file for execution The operating system(OS) is the most important program that runs on a computer The OS manages and controls a computer's activities. ● ● ● The popular operating systems for general purpose computers are Microsoft Windows, Mac OS and Linus Application programs cannot run unless and operating system is installed and running on the computer.
  30. 30. Major Tasks of an Operating system ● Controlling and monitoring system activities ● Allocating and assigning system resources ● Scheduling operations
  31. 31. ● ● ● ● ● ● ● Operating systems perform basic tasks An operating system must also ensure that different programs and users working at the same time do not interfere with each other. The OS is responsible for security, ensuring tht unauthorized users and programs do not access the system. The OS is responsible for determining what computer resources a program needs and for allocating and assigning them to run the program The OS is responsible for scheduling programs' activities to make efficient use of system resources. Multiprogramming allows multiple programs to run simultaneously by sharing the same CPU Multithreading allows a single program to execute multple tasks at the same time
  32. 32. ● ● Multiprocessing or parallel processing uses two or more processors together to perform subtasks concurrently and then combine solutions of the subtasks to obtain a solution for the entire task. It is like a surgucal operation where several doctors work together on one patient.
  33. 33. Java, the World Wide Web and Beyond Java is a powerful and versatile programming language for developing software running on mobile devices, desktop computers and servers. Java was developed by a team ed by James Gosling at Sun Microsystems. Originally called Oak, Java was designed in 1991 for use in embedded chips in consumer electronic appliances. In 1995 , renamed Java it was redesigned for developing Web applications.
  34. 34. ● ● ● ● Java is popular particularly because of its promise that you can write a program once and run it anywhere Java is simple, object oriented, distributed, interpreted, robust, secure, architechure neutral, protable, high performance, multithreaded and dynamic. Java is a full- featured, general- purpose programming language that can be used to develop robust mission- critical applications. Java was used to develop the code to communicate with and control the robotic rover on Mars.
  35. 35. ● ● ● ● ● The World Wide Web is an electronic information repository that can be accessed on the Internet from anywhere in the world. The internet has been around for more than forty years. Java became attractive because Java programs can be run from a Web browser. Java programs run in a Web browser are called applets Applets employ a modern graphical interface with buttons, text fields, text areas, radio buttons and more
  36. 36. ● ● ● ● ● ● Applets make the Web responsive, interactive, and fun to use Applets are embedded in an HTML file HTML( Hypertext Markup Language) is a simple scripting language for laying out documents, linking documents on the internet and bringing images, sound and video alive on the Web. Java is very popular for developing applications of Web Servers Java is a versatile programming language You can use java to develop applications for desktop computers servers and small hand held devices
  37. 37. The software for Android cell phones is developed using Java The Java Language Specification,Api,JDK, and IDE ● Java syntax is defined in the Java language specification, and the Java library is defined in the Java API, The JDK is the software for developing and running Java programs. An IDE is an integrated development environment to rapidly developing programs
  38. 38. ● ● ● ● ● Computer languages have strict rules of usage If you do not follow the rules the computer will not be able to understand The Java language specification and the Java API define the Java standards. The Java language specification is a dechnical definition of the Java programming language's syntax and semantcs application program interface ( API) also known as the library contains The predefined classes and interfaces for developing Java programs.
  39. 39. Three Editions of Java ● ● ● Java Standard Edition (Java SE) to develop clientside standalone applications or applets Java Enterprise Edition ( Java EE) to develop serverside applications, such as Java servelets, JavaServer Pages (JSP) and JavaServer Faces (JSF) Java Micro Edition ( Java ME) to develop applications for mobile devices. Java SE is the foundation upon which all other Java technology is based. ● The Java Development Toolkit is called JDK
  40. 40. ● ● JDK consists of a set of separate programs, each invoked from a command line for developing and testing Java prorams. Java development tools ----NetBeans ----Eclipse ---Textpad ● ● Software that provides and integrated development enviorment ( IDE) for developing Java programs quickly Editing, compiling, building, debugging and online help are integrated in one graphical user interface
  41. 41. A simple Java Program A Java program is executed from the main method in the class. ● ● ● Console- an old computer term that refers to the text entry and display device of a computer Console input means to receive input from the keyboard Console output means to display output on the monitor
  42. 42. 1 public class Welcome { 2 public static void main ( String [] args) { 3 //Display message Welcome to Java! On the console 4 System.out.println(“Welcome to Java!”); 5 6} }
  43. 43. Note the line numbers are for reference purposes only!!!! Line 1 defines a class. ● Every Java program must have at least one class ● Each class has a name ● Class names start with an uppercase letter. ● Out class name in the example is Welcome Line 2 defines the main method ● ● ● The program is executed from the main method A class may contain several methods The main method is the entry point where the program begins execution
  44. 44. ● ● ● ● ● ● ● A method is a construct that contains statements The main method in our program contains the System.out.println statement This statements displays the string on the console String is a programming term meaning a sequence of characters A string must be enclosed in double quotation marks Every statement in Java ends with a semicolon(;) known as the statement terminator Reserved words or keywords have a specific meaning to the compiler and cannot be used for other purposes in the program
  45. 45. ● ● ● ● ● ● Class compiler understands that the word after class is the name for the class Public, static, and void are also reserved words in Java Line 3 is a comment that documents what the program is and how it is constructed Comments help programmers to communicate and understand the program Comments are ignored by the compiler Comments are preceded by two slashes (//) on a line called a line comment or enclosed between /* and */ on one or several lines
  46. 46. ● ● ● ● ● ● ● Block or paragraph comments are on several lines When the compiler sees // it ignors all text after // on the same line When it sees /* it scans for the next / and ignores any text between /* and*/ A pair of curly braces in a program forms a block that groups the program's components. In Java each bock begins with an opening brace ({) and ends with a closing brace (}) Every class has a class block that groups the data and methods of the class. Every method has a method block that groups the statements in a method
  47. 47. ● ● ● ● Blocks can be nested meaning that one block can be placed within another An opening brace must be matched by a closing brace Java source programs are case sensitive Main and main do not mean the same thing.
  48. 48. Special Characters
  49. 49. ● ● The most common errors made as one learns to program are syntax errors The multiplication operator in Java is *
  50. 50. Create, Compiling and Executing a Java Program ● ● ● ● You save a Java program in a .java file and compile it into a .class file. The .class file is executed by the Java Virtual Machine. You have to create your program and compile it before it can be executed. If your program has errors you have to modify it to fix them then recompile it The rourse file must have the same exact name as the public class name
  51. 51. ● A java compiler translates a Java source file into a Java bytecode file To compile Welcome.java: javac Weclome.java ● If you have no syntax errors, the compiler generates a bytecode file with a .class extension.
  52. 52. ● The java language is a high level language ● Java bytecode is a low level language ● ● ● ● ● Bytecode is similar to machine instructions but is architecture neutral and can run on any platform that has a JVM The virtual machine is a program that interprets Java bytecode Java bytecode can run on a variety of hardware platforms and operating systems Java source code is compiled into Javabytecode and Java bytecode is interpreted by the JVM The JVM executes your code along with the code in the library
  53. 53. ● ● ● ● ● ● To extcute a java program is to run the program's bytecode You can execute the bytecode on any platfor with a JVM The JVM translates the individual instructions in the bytecode into the target machine language code one at a time rather than the whole program as a single unit Each step is executed immediately after it is translated. If you execute a file that does not exist a NoCLassDefFoundError will occur If you execute a class file that does not have a main method or you mistyped the main method a NoSuchMethodError will occur
  54. 54. ● ● ● The JVM first loads the bytecode of the class to memory using a program called the class loader If your program uses other classes the class loader dynamically loads them just before they are needed After a class is loaded the JVM uses a program called the bytecode verifier to check the validity of the bytecode and to ensure that the bytecode does not violate Java's security restrictions
  55. 55. Displaying Text in a Message Dialog Box You can display text in a graphical dialog box ● ● To display text in a message dialog box you need to use the showMessageDialog method in the JOptionPane class JOptionPane is one of the many predefined classes in the java library
  56. 56. WelcomeInMessageDialogBox.java 1 /* This application program displays Welcome to Java! 2 * in a message dialog box. 3 */ 4 import javax.swing.JOptionPane; 5 6 public class WelcomeInMessageDialogBox { 7 public static void main(String[] args) { 8 // Display Welcome to Java! In message dialog box 9 JoptionPane.showMessageDialog(null,”Welcome to Java!”): 10} 11}
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×