49
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

Object-Oriented Programming in Java - UTRGV · PDF file... Head First Java, 2nd Edion • Author: Kathy Sierra, Bert Bates • Publisher: O'Reilly Media, February 9, 2005 ... – Java

Embed Size (px)

Citation preview

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.DongchulKim•  Office:ENGR3.272•  Email:[email protected]•  Homepage:h"p://faculty.utrgv.edu/dongchul.kim/•  OfficeHours:Mon&Wed,1:30~2:30pm,byappointment,

oranyNmetheofficedoorisopen.•  CourseWebPage:

–  h"p://faculty.utrgv.edu/dongchul.kim/CSCI3326/

Course Information •  TAName:AdolfoGonzalezIII•  Email:[email protected]•  Office:ENGR3.273A•  OfficeHours:TBA

Textbook •  OpNonal•  Title: Starting Out with Java: From Control Structures •  Through Objects, 6th Edition •  Author: Tony Gaddis •  Publisher: Addison-Wesley, March 22, 2015 •  ISBN-13: 978-0133957051 •  Link: http://goo.gl/lHXMxJ

Textbook •  OpNonal•  Title:HeadFirstJava,2nd

EdiNon•  Author:KathySierra,BertBates•  Publisher:O'ReillyMedia,

February9,2005•  ISBN-13:978-0596009205•  Link:h`p://goo.gl/dA6rVy

Evaluation •  LabAssignments15%•  ProgrammingAssignments25%•  Exams40%•  Project20%

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 do Java programming

The Way Java Works

Source Compiler Output Virtual Machine

1.Createasourcedocument.Useanestablishedprotocol(inthiscase,theJavalanguage).

2. Run your document through a sourcecode compiler. The compiler checks forerrorsandwon’tletyoucompileunNlit’ssaNsfiedthateverythingwillruncorrectly.

3. The compiler creates a new document, codedintoJavabytecode.AnydevicecapableofrunningJavawillbeabletointerpret/translatethisfileintosomething it can run. The compiled bytecode isplamormindependent.

4.Thevirtualmachinereadsandrunsthebytecode.

What you’ll do in Java

Source Compiler Output Virtual Machine

1.Typeyoursourcecode.Saveas:Hello.java

2. Compile theHello.javafile by runningjavac (the compiler applicaNon). If youdon’t have errors, you’ll get a seconddocumentnamedHello.classThe compiler-generatedHello.class file ismadeupofbytecode

4.RuntheprogrambystarNngtheJava Virtual Machine (JVM) withthe Hello.class file. The JVMtranslates the bytecode intosomethingtheunderlyingplamormunderstands, and runs yourprogram.

3.Compiledcode:Hello.class

Java Compiler and JVM • Withmostprogramminglanguages,portabilityisachievedbycompilingaprogramforeachCPUitwillrunon.

•  JavaprovidesanJVMforeachplamormsothatprogrammersdonothavetorecompilefordifferentplamorms.

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 •  TheJavacompilerisacommandlineuNlity.•  Thecommandtocompileaprogramis:

–  javac filename.java –  javacmeansJavacompiler.

•  The.java fileextensionmustbeused.–  Example:TocompileajavasourcecodefilenamedHello.javayouwouldusethecommand:

– javac Hello.java

Run •  ToruntheJavaprogram,youusethejavacommandinthefollowing

form:–  java ClassFilename

•  ClassFilenameisthenameofthe.class filethatyouwishtoexecute.–  However,youdonottypethe.class extension.

•  Forexample,toruntheprogramthatisstoredintheHello.classfile,youwouldenterthefollowingcommand:–  java Hello –  ThiscommandrunstheJavainterpreter(theJVM)andexecutesthe

program.

Windows Command Prompt

IDE •  InaddiNontothecommandpromptprograms,thereare

alsoseveralJavaIntegratedDevelopmentEnvironments(IDEs).

•  Theseenvironmentsconsistofatexteditor,compiler,debugger,andotheruNliNesintegratedintoapackagewithasinglesetofmenus.

•  Aprogramiscompiledandexecutedwithasingleclickofabu`on,orbyselecNngasingleitemfromamenu.

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!