Download Lesson_01

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Lesson 01 – An introduction to Java and the Java Programming Environment
1.
background on the Java programming language
a. JDK – Java Development Kit. Necesssary to create a Java class
 JDK provides a compiler – javac.exe
b. JRE – Java Runtime Environment. Also referred to as the JVM – Java Virtual Machine
 JRE provides an interpreter – java.exe
c. A Java program must first be successfully compiled, then it can be interpreted to run the program
2.
Java program types:
a. application
b. servlet
c. applet
3.
4.
5.
6.
7.
command line / GUI
runs on a web server
application that runs inside a web browser
introduction to Java Programming Concepts
 class
 global variables (aka fields or instance and class variables)
 method(s)
 method main – where execution always begins
 method main header: public static void main(String args[])
 statement(s)
keywords:
special keywords used in Java are: class, public, static, void, import, throws
punctuation: ( ) [ ] { } , ; " " (String literal) ' ' (character literal)
frequently used classes: System, Math, String, Scanner, PrintWriter, JOptionPane
variables
a. global
b. local
not declared inside of a method (must be outside of all methods)
local variables are declared within a method (method level).
8.
Java Development
a. code a source file
a source file is a file with an extension of .java that contains a class declaration
b. compile a source file to produce a class file
a class file is a file with an extension of .class that contains compiled Java source code
the JDK (Java Development Kit) is required to do this
c. a class file with a prescribed method main can be considered to be a program
the program must be run within the Java virtual machine (it is NOT the same as an executable program).
9.
translation
a. compiling
example:
JDK command javac
javac HelloWorld.java
b. Interpreting JRE command java
example: java HelloWorld
bytecode
[ the JDK contains the Java compiler ]
[ produces HelloWorld.class ]
[ the JRE contains the Java interpreter ]
[ runs HelloWorld.class ]
a successful compile in Java produces a .class file which contains "bytecodes"
10. platform independence ( "write once, run anywhere…" )
11. Using the command line to compile/run programs
a. javac [ used to invoke the compiler ]
b. Java [ used to invoke the JVM to run a program ]
javac CarpentersCustomDesks.java
java CarpentersCustomDesks
12. Check the version of your Java compiler (JDK) and interpreter (JRE)
a. Run cmd to bring up a command prompt
b. Enter the command “javac –version” to check the version of the compiler
c. Enter the command “java –version” to check the version of the interpreter