Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CSCI/CMPE 3326
Object-Oriented Programming in Java
Dr. Dongchul Kim
Department of Computer Science
University of Texas Rio Grande Valley
Course Information, JVM, Compile and Run, 
IDE, Android Studio  
Course Information
• Instructor: Dr. Dongchul Kim
• Office: ENGR 3.272
• Email: dongchul.kim@utrgv.edu
• Homepage: http://faculty.utrgv.edu/dongchul.kim/
• Office Hours: Tue & Thu, 1~3pm, by appointment, or 
anytime the office door is open.
• Course Web Page:
– http://faculty.utrgv.edu/dongchul.kim/courses/CSCI3326S17/
Course Information
• TA Name: Pengfei Gu
• Email: pengfei.gu01@utrgv.edu
• Office: ENGR 3.273A
• Office Hours: Tue and Thu 4:20~6pm
Textbook
• Optional
• Title: Starting Out with Java: 
Early Objects, 6th Edition 
• Author: Tony Gaddis
• Publisher: Addison-Wesley, 
March 22, 2015
• ISBN-13: 978-0133957051 
• Link: http://goo.gl/lHXMxJ
Textbook
• Optional
• Title: Head First Java, 2nd 
Edition
• Author: Kathy Sierra, Bert Bates
• Publisher: O'Reilly Media, 
February 9, 2005
• ISBN-13: 978-0596009205
• Link: http://goo.gl/dA6rVy
Evaluation
• Attendance 5%
• Lab Assignments 10%
• Programming Homework 20%
• Midterm Exam 20%
• Final Exam 25%
• Project 20%
Rule 1
• Any OS is okay (Windows, Mac OS, Linux, 
Chrome OS, and so on)
• Please come to my office if you couldn’t 
understand the course materials
• or ask TA
• Please don’t be shy
• There is no such thing as a stupid question
– Exception?
– Respect your classmates
Rule 2
• No late submission
• No cheating
– Respect your classmates
• Frequently check your UTRGV email, course 
website, and blackboard
• Come to class on time
• Start HW early
• Enjoy (Best chance to improve your 
programming skill)
Rule 3
• Excuse me
– Flexible course schedule
• Bring your laptop with fully charged 
battery
Rule 4
• I will do my best
• You should also do your best
– Everyday practice Java
The Way Java Works
Source Compiler Output
Virtual 
Machine
1. Create a source document.
Use an established protocol 
(in this case, the Java language).
2. Run your document through a source
code compiler. The compiler checks for
errors and won’t let you compile until it’s
satisfied that everything will run correctly.
3. The compiler creates a new document, coded
into Java bytecode. Any device capable of running
Java will be able to interpret/translate this file into
something it can run. The compiled bytecode is
platformindependent.
4. The virtual machine 
reads
and runs the bytecode.
What you’ll do in Java
Source Compiler Output
Virtual 
Machine
1. Type your source code.
Save as: Hello.java
2. Compile the Hello.java file by running
javac (the compiler application). If you
don’t have errors, you’ll get a second
document named Hello.class
The compiler-generated Hello.class file is
made up of bytecode
4. Run the program by starting the
Java Virtual Machine (JVM) with
the Hello.class file. The JVM
translates the bytecode into
something the underlying platform
understands, and runs your
program.
3. Compiled code: Hello.class
Java Compiler and JVM
• With most programming languages, 
portability is achieved by compiling a 
program for each CPU it will run on.
• Java provides an JVM for each platform so 
that programmers do not have to recompile 
for different platforms.
Java Software Edition
• The software you use to write Java programs is 
called the Java Development Kit, or JDK.
• There are different editions of the JDK:
– Java SE – Standard Edition
• Provides essential tools for developing applications and applets
– Java EE – Enterprise Edition
• Provides tools for creating large business applications that employ servers 
and  provide services over the Web
– Java ME – Micro Edition
• Provides a small, optimized runtime environment for consumer products 
such as cell phones, pagers, and appliances
• Available for download at 
https://www.oracle.com/java/index.html
Plz. Memorize Now!
**Details will be explained later on.
Install Java
• Java SE
• http://www.oracle.com/technetwork/java/javase
/downloads/index-jsp-138363.html


Install Java
Install Java
Setting Path in Windows
• Windows 8
– Drag the Mouse pointer to the Right bottom corner of the screen
– Click on the Search icon and type: Control Panel
– Click on → Control Panel → System → Advanced
– Click on Environment Variables, under System Variables, find PATH, and click on it.
– In the Edit windows, modify PATH by adding the location of the class (e.g. C:\Program 
Files\Java\jdk1.8.0_31\bin\) to the value for PATH. If you do not have the item PATH, you may select to 
add a new variable and add PATH as the name and the location of the class as the value.
– Close the window.
– Reopen Command prompt window, and run your java code.
• Windows 7
– Select Computer from the Start menu
– Choose System Properties from the context menu
– Click Advanced system settings → Advanced tab
– Click on Environment Variables, under System Variables, find PATH, and click on it.
– In the Edit windows, modify PATH by adding the location of the class (e.g. C:\Program 
Files\Java\jdk1.8.0_31\bin\) to the value for PATH. If you do not have the item PATH, you may select to 
add a new variable and add PATH as the name and the location of the class as the value.
– Reopen Command prompt window, and run your java code.
Setting CLASSPATH Variable
• Right-click the My Computer icon on
• your desktop and select Properties.
• Click the Advanced tab. Click the
• Environment Variables button. Under System Variables, click 
New.
• Enter the variable name as CLASSPATH.
• Enter the variable value (e.g. .;) 
• The CLASSPATH variable is one way to tell applications, 
including the JDK tools, where to look for user classes.
• Click OK.
• Click Apply Changes.
Setting JAVA_HOME Variable
• Right-click the My Computer icon on
• your desktop and select Properties.
• Click the Advanced tab. Click the
• Environment Variables button. Under System Variables, click 
New.
• Enter the variable name as JAVA_HOME.
• Enter the variable value (e.g. C:\Program Files\Java\jdk1.8.0_31) 
as the installation path for the Java Development Kit.
• Click OK.
• Click Apply Changes.
Compile
• The Java compiler is a command line utility.
• The command to compile a program is:
– javac filename.java
– javac means Java compiler.
• The .java file extension must be used.
– Example: To compile a java source code file named 
Hello.java you would use the command:
– javac Hello.java
Run
• To run the Java program, you use the java command in the following 
form:
– java ClassFilename
• ClassFilename is the name of the .class file that you wish to 
execute. 
– However, you do not type the .class extension. 
• For example, to run the program that is stored in the Hello.class
file, you would enter the following command:
– java Hello
– This command runs the Java interpreter (the JVM) and executes the 
program.
Windows Command Prompt
IDE
• In addition to the command prompt programs, there are 
also several Java Integrated Development Environments 
(IDEs). 
• These environments consist of a text editor, compiler, 
debugger, and other utilities integrated into a package with 
a single set of menus. 
• A program is compiled and executed with a single click of a 
button, or by selecting a single item from a menu.
Most Popular IDE: Eclipse
IDE from Oracle: NetBeans
Install Eclipse
Install Eclipse
Install Eclipse
Install Eclipse
Install Eclipse
Install Eclipse
Comment
• The // in line 1 marks the beginning of a comment.
• The compiler ignores everything from the double slash 
to the end of the line.
• Comments are not required, but comments are very 
important because they help explain what is going on 
in the program.
Lab1-1
• Install Eclipse
• Make a java program that displays “hello yourname”
• In the first line of your program, please put a comment 
with your name and lab number
– //Dongchul Kim, lab1-1
• Save as “Hello.java”
• Compile and Run
• Give a demo to your instructor or TA.
Install IDE for Android App
• http://developer.android.com/sdk/index.html
Install Android Studio
Install Android Studio
Install Android Studio
Install Android Studio
Install Android Studio
Hello World for Android App
Hello World for Android App
Hello World for Android App
Hello World for Android App
Hello World for Android App
Lab1-2
• Make a Android app that displays “Hello yourname” on 
Android phone
• Demonstrate it to your instructor!