1 / 18

Java Programming

Java Programming. Course Overview Introduction www.ict.up.ac.th/thanawats/pro_lang. Course. Lecture – Lab session การสอบกลางภาคและสอบปลายภาค การสอบการเขียนโปรแกรม (ภาคปฏิบัติ) การบ้าน ทดสอบย่อย โปรเจค. Evaluation. การทดสอบภาคปฏิบัติ 1 10% การสอบกลางภาค 25 %

sylvias
Download Presentation

Java Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Programming Course Overview Introduction www.ict.up.ac.th/thanawats/pro_lang

  2. Course • Lecture – Lab session • การสอบกลางภาคและสอบปลายภาค • การสอบการเขียนโปรแกรม (ภาคปฏิบัติ) • การบ้านทดสอบย่อย • โปรเจค

  3. Evaluation • การทดสอบภาคปฏิบัติ 1 10% • การสอบกลางภาค 25% • การทดสอบภาคปฏิบัติ 2 10% • การสอบปลายภาค 25% • โปรเจค 20% • การบ้านแบบฝึกหัด รายงาน 5% (ให้เขียนด้วยลายมือ) • จิตพิสัย 5%

  4. Textbooks • Beginning Java 2 SDK 1.4 Edition, by Ivor Horton; Wrox Press; ISBN: 1861005695 • Thinking in Java, 3/e by Bruce Eckel; Prentice Hall; ISBN: 0131002872 • วีระศักดิ์ ซึงถาวร (2541). Java Programming Volume 1. กรุงเทพมหานคร : ซีเอ็ดยูเคชั่น. • วีระศักดิ์ ซึงถาวร (2543). Java Programming Volume 2. กรุงเทพมหานคร : ซีเอ็ดยูเคชั่น.

  5. Topics • Java Basics • OOP, Classes, Inheritance, Interfaces • Exceptions • Collections • I/O Streams • Files, Directories, Serialization • Threads • GUI • *** Networking

  6. Introduction • What is Java? • A high level programming language • Similar to C++ (in some ways) • Operating system independent • Java Virtual Machine (JVM) • Provides a secure operating environment that runs as a layer on top of the operating system • Sandbox • Object oriented programming language • In Java, everything is a class (well, almost) • Unlike C++, where OOP support is built on top of the language, in Java, OOP support is a fundamental component

  7. Java Features • Lots of built in pre-defined classes! • In Java, before you write any code, check to make sure somebody hasn’t already done it for you! • Dynamic memory management • Automatic garbage collection • No pointers! (Even though every class variable is a pointer and all objects are passed by reference) • No memory leaks! • Error handling built into language (Exceptions) • Threads and synchronization primitives • Security

  8. Java NonFeatures • What C++ programmers might try to do but can’t: • Use pointers (but like we said before, everything is a pointer) • Include files (use packages instead) • Use global variables (although the concept of global variables can easily be simulated) • Operator overloading • templates (although the new Java 5.0 has introduced support for these) • Multiple inheritance (interfaces are used instead) • Destructors (nobody liked them anyways)

  9. The JVM and Bytecode • Unlike C++ programs, Java programs are not compiled into machine language • Instead they are compiled into Java bytecode • The bytecode is then interpreted by the Java Virtual Machine (JVM) • This is the key to Java’s universality. Any compiled Java bytecode can be run on any valid JVM installed on any Operating System (on any device, not just a computer) • With C++ and other compiled languages, programs must be recompiled for each particular architecture that it needs to be run on

  10. Java Programs • As we said before, in Java, everything is a class • Each class is contained within its own file • The name of each file should be exactly the same as the name of the class that it contains along with a .java extension • i.e. MyFirstJavaClass.java would contain the class MyFirstJavaClass • Note: this name convention is not a suggestion, it is a requirement in order for your Java programs to compile correctly MyFirstJavaClass.java public class MyFirstJavaClass { public static void main(String[] args) { System.out.println(“Hello World”); } }

  11. Software • Java programs can be compiled and run with a tool called the Java SDK (Software Development Kit) • It can be downloaded for free from http://java.sun.com/j2se/1.4.2/download.html • It is also already pre-installed and available on several public RPI campus machines • Currently Java 1.5.0 (also known as Java 5.0) is available. We will not be using any of the additional features in this version and therefore you should use version 1.4.2

  12. Java Platform • Java Platform มีความหลากหลาย แต่สามารถแบ่งเป็นกลุ่มใหญ่ๆได้ 3 กลุ่มดังนี้ • J2SE : Java(tm) Standard Edition • Suitable for 'usual' Desktops • J2EE : Java(tm) Enterprise Edition • Suitable for Servers • J2ME : Java(tm) Micro Edition • Suitable for Mobile

  13. Java Platform

  14. SDK Details • The following tools are available in the SDK for compiling and running your Java programs (among others) • javac • Java compiler • Generates Java bytecode from given source code • java • Java intepreter • Runs a Java program from the given bytecode • jar • Used in creating Java Archive (jar) files • Can be a convenient method for distributing finished Java programs

  15. How to use the Compiler • javac [java filenames] • Pass an unbounded number of source code files (.java) as command line arguments • Will take each file and generate a .class file of the same name (bytecode file) • i.e. MyFirstJavaClass.java would result in a bytecode file called MyFirstJavaClass.class • javac *.java will compile and generate bytecode files for every .java file in the current working directory

  16. How to use the Interpreter • java [classname] • When running Java programs, you must indicate which class you wish to run • Note that you do not give the filename, just the class name. This is why the naming conventions for the filenames is important • The interpreter will then search for the bytecode file named [classname].class in the directory or directories indicated by something called the classpath • The given class should have a method with the prototype: • public static void main() • It is this method that will automatically be run by the Java intepreter

  17. More about the classpath • By default the classpath is set to the current working directory • Depending on the software and operating system you are using, you can indicate the classpath in a number of ways • You can always directly indicate the classpath by using the –classpath or –cp switch from the command line: • java –cp /home/kelleo/java/ MyFirstJavaClass • Under Windows, the classpath can also typically be modified from the Environment Variables section of the System settings in the Control Panel • Third party software such as Eclipse and Borland JBuilder may also do things differently

  18. ที่มา • Rensselaer Polytechnic Institute: Owen Kellett

More Related