CS241001 Software Studio Java Lab 1 Meng-Ting Wang PLLAB, Computer Science Department, National Tsing-Hua University.

Slides:



Advertisements
Similar presentations
JAVA Programming Environment © Juhani Välimäki 2003.
Advertisements

Object Oriented Programming in Java George Mason University Fall 2011
Lab#1 (14/3/1431h) Introduction To java programming cs425
Lab 9 Java Bytecode & The Jasmin Assembler
Introduction to Java ISYS 350. A Brief History Sun Microsystems released this language in 1996 – Versions: 1.0 – 1.6 Java Development Kit, JDK – Standard.
Tutorial 1 Introduction to Java Programming Bo Chen Department of Computer Science.
Lab 1 Instructor: Jolanta Soltis.
CS0007: Introduction to Computer Programming Setting Up Java.
Marlene Galea.  The JDK (Java Development Kit)  An IDE (Integrated Development Environment) ◦ Different IDEs include:  JCreator  NetBeans  BlueJ.
CMSC 202 Computer Science II for Majors Fall 2009 Introduction.
Introduction to Java Programming. Contents 1. Java, etc. 2. Java's Advantages 3. Java's Disadvantages 4. Types of Java Code 5. Java Bytecodes 6. Steps.
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
CSC 8505 Compiler Construction IR Example: Java Bytecode (looking inside class files)
Java 程序设计 Java Programming Fall, Contents for Today Java Program Structure  How to Compile a Java Program  How to Run a Java Program Environment.
M1G Introduction to Programming 2 4. Enhancing a class:Room.
Java Programming Robert Chatley William Lee
CSCI 273: Processing An Introduction. Programming Languages –An abstract "human understandable" language for telling the computer what to do –The abstract.
(C) 2010 Pearson Education, Inc. All rights reserved.  Java programs normally go through five phases  edit  compile  load  verify  execute.
CMSC 202 Computer Science II for Majors Object-Oriented Programming.
Fundamentals of Java.  Explain the structure of a Java class  List and explain steps to write a Java program  Identify the benefits of NetBeans IDE.
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
Session One Introduction. Personal Introduction Role of programmers Robot Examination HUD & HID Uploading Code.
UCSC All rights reserved. No part of this material may be reproduced and sold. 1 IT1202-Fundamentals Of Programming (Using JAVA) Interacting with.
FRST JAVA PROGRAM. Getting Started with Java Programming A Simple Java Application Compiling Programs Executing Applications.
The Basics of Javadoc Presented By: Wes Toland. Outline  Overview  Background  Environment  Features Javadoc Comment Format Javadoc Program HTML API.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Введение в JAVA. Java Java – язык программирования: объектно-ориентированный кроссплатформенный строго-типизированный.
Java Introduction to JNI Prepared by Humaira Siddiqui.
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and Server Side Programming Very rich GUI libraries Portability (machine independence) A.
Java ACO101: Introduction to Computer Science. The History of Java Started out as a research project at Sun Microsystems in 1991 Code named “Green” Based.
Jaeki Song ISQS6337 JAVA Lecture 03 Introduction to Java -The First Java Application-
Java and C# [this is a bonus – it is not a required lesson] ACO101: Introduction to Computer Science.
Java Basics - Prashant Nagaraddi. Features of Java n Java syntax is similar to C/C++ but there are many differences too n Java is strongly typed like.
© 2012 Pearson Education, Inc. All rights reserved. 1-1 Why Java? Needed program portability – Program written in a language that would run on various.
POS 406 Java Technology And Beginning Java Code
Java Programming Presented by Daniel Rosenthal Friday, November 30 th, 2007.
CSCI Processing CSCI Introduction to Algorithm Design An Introduction.
National Taiwan University Department of Computer Science and Information Engineering National Taiwan University Department of Computer Science and Information.
4-Nov-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic 1: The Java Environment Maj Joel.
Introduction to Java The Java Platform, The Java Language, JDK, Eclipse Svetlin Nakov Technical Trainer Software University
23-October-2002cse JavaIntro © 2002 University of Washington1 Intro to Java CSE 413, Autumn 2002 Programming Languages
Chapter 1: Introducing JAVA. 2 Introduction Why JAVA Applets and web applications Very rich GUI libraries Portability (machine independence) A real Object.
JAVA Programming “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
22-July-2002cse142-13B-Development © 2002 University of Washington1 Development Tools CSE 142, Summer 2002 Computer Programming 1
CS 4244: Internet Programming Network Programming in Java 1.0.
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Runtime System CS 153: Compilers. Runtime System Runtime system: all the stuff that the language implicitly assumes and that is not described in the program.
Overview of Java CSCI 392 Day One. Running C code vs Java code C Source Code C Compiler Object File (machine code) Library Files Linker Executable File.
The Java Platform, The Java Language, JDK, IntelliJ
© 2012 Pearson Education, Inc. All rights reserved types of Java programs Application – Stand-alone program (run without a web browser) – Relaxed.
introductory lecture on java programming
20-Feb-16 javap. Bytecode Java is compiled into bytecode, which is intermediate between Java and a “real” assembly language To implement Java, it is only.
3/5/2002e-business and Information Systems1 Java Java Java Virtual Machine (JVM) Java Application Program Interface (API) HW Kernel API Application Programs.
Know Your Java. Java is special Java source code Byte code/ native code Object code on windows Object code on Dos Object code on Lynux.
Computer Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Execution ways of program References: www. en.wikipedia.org/wiki/Integrated_development_environment  You can execute or run a simple java program with.
CS 201 Lecture 1 (b) Using an IDE Tarik Booker CS 201: Introduction to Programming California State University, Los Angeles.
SESSION 1 Introduction in Java. Objectives Introduce classes and objects Starting with Java Introduce JDK Writing a simple Java program Using comments.
CMSC 202 Computer Science II for Majors Fall 2010 Introduction Version 9/101.
Introduction to Algorithm. What is Algorithm? an algorithm is any well-defined computational procedure that takes some value, or set of values, as input.
Introduction CMSC 202 Fall Instructors Mr. Ryan Bergeron – Lecture Section 01 Tues/Thu 1:00 – 2:15 am, Sondheim 111 – Lecture Section 04 Tues/Thu.
CS-140 Dick Steflik Lecture 3. Java C++ Interpreted optimized for the internet Runs on virtual ized machine Derived from C++ Good object model Widely.
Lecture 1b- Introduction
Intro to ETEC Java.
Chapter No. : 1 Introduction to Java.
Getting Started ARCS Lab..
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
Introduction to Algorithm Design
Review of Previous Lesson
M S COLLEGE ART’S, COMM., SCI. & BMS
Presentation transcript:

CS Software Studio Java Lab 1 Meng-Ting Wang PLLAB, Computer Science Department, National Tsing-Hua University

Introduction to the JDK “Hello Java Example” Tools of the JDK: javac, java, javap, jdb, javah…

Java Development Toolkit What is JDK? – It is a pack of programs which is used for programming, compiling and executing Java program. It includes the Java library, the execution runtime, java compiler and debugger, and JNI tool. What's the difference between "JDK" and "JRE"? – JDK (Java Development Kit) is the package for develop java programs. – JRE (Java Runtime Environment) is an implementation of the Java Virtual Machine which actually executes Java programs

Java API Application Programming Interface is an interface in computer science that defines the ways by which an application program may request services from libraries and/or operating systems. Source:

C/C++ vs. Java Sorting – Bubble sort, merge sort, insertion sort… Math Data structure – Linked-list… – Array visit, add, and remove… – Heap, stack, queue, string…. In C/C++ - You need to write a high performance code by yourself. In Java SIMPLY CALL THE API !!! In C/C++ - You need to write a high performance code by yourself.

What else java API support….

JDK vs. JRE A.java public class A{ public static void main (Stirng[] args) { System.out.println (“Hello World!!”); } Java VM Java Program javac:CompileBytecode A.class 0: aload_0 1: invokespecial #1; //Method java/lang/Object." ":()V 4: return public static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello World! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/Str ing;)V 8: return Tools Java, javac, jar, javap, javah, jdb,… APIs Lang, util, collections, JDBC, math,... java:Execute JRE JDK Platform: Linux, windows, Solaris,… Java program

C/C++ vs. Java C C++ Compiler 1010 Compiler java Byte- code JVM Linux Windows Mac 1010 Compiler 1010 Compiler 1010 JVM 1010 JVM 1010

Install JDK SE

JDK Editions Java SE- Java Platform, Standard Edition Java EE- Java Platform, Enterprise Edition Java ME- Java platform, Micro Edition JavaFX- A software platform for creating and delivering rich Internet applications (RIAs) that can run across wide variety of connected devices.

Environment Setup Install Environment setup – Add “C:\Program Files\Java\jdk( 版本號碼 )\bin” to “Path” which is in “system variables”.

Environment Setup

Introduce Java SE API specifications

Hello Java!! Create a Hellojava.java file using Notepad++ javac HelloJava.java java HelloJava public class HelloJava{ public static void main (String[] args) { System.out.println ("Hello Java!!"); }

Tools for Programming Java IDE: Eclipse, Netbeans, IntelliJ,… Editor: NotePad++, JEdit, EditPlus,… Tools of JDK: – javac: Compile the java program into class file – java : Execute the class file. – javap: Dump bytecode from class file – jdb: java debugger – Javah: Generate the JNI header file – …..

Javac-compile -verbose -sourcepath – default:.;C:\Program Files\Java\jre6\lib\ext\QtJava.zip -classpath – Default:.;C:\Program Files\Java\jre6\lib\ext\QtJava.zip -encoding – Specify character encoding used by source files – CP950, Big5, UTF8,… -g Generate all debugging info -verbose Output messages about what the compiler is doing -d Specify where to place generated class files -encoding -help Print a synopsis of standard options

Java-execute Javaw.exe : A non console version java interpreter, only on windows platform. -classpath -jar jarfile -verbose

javap - The Java Class File Disassembler Javap HelloJava Compiled from "HelloJava.java" public class HelloJava extends java.lang.Object{ public HelloJava(); public static void main(java.lang.String[]); }

Compiled from "HelloJava.java" public class HelloJava extends java.lang.Object{ public HelloJava(); Code: 0: aload_0 1: invokespecial #1; //Method java/lang/Object." ":()V 4: return public static void main(java.lang.String[]); Code: 0: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream; 3: ldc #3; //String Hello World!! 5: invokevirtual #4; //Method java/io/PrintStream.println:(Ljava/lang/String;) 8: return } Javap -c HelloJava

Java Namespace Package: import package tw.edu.nthu.cs.pllab.cs examples; cs pllab.cs.nthu.edu.tw + examples ※ Rule: Reverse website address + package name import tw.edu.nthu.cs.pllab.cs examples.*; System.out.println(); ※ Default import java.lang.*;

Create an Instance HelloJava helloj = new HelloJava(); helloj.sayHello(); Hello!! HelloJava Factory helloj

Typewriter simulation

TypeWriter.java(1/2) 1.//package ?? 2.public class TypeWriter{ 3. private String msgArray[] = {"Y","o","u"," ","h","a","v","e"," ","t","o"," ","p","r","i","n", "t", " ", 4. "t","h","e"," ","r","i","g","h","t"," ","m","e","s","s", "a", "g","e", " ","o","u","t"," ", 5. "u","s","i","n","g", " ","t","h", "e", " ","e","x","a", "c", "t"," ","m","e","s","s", "a", "g","e", " ","l","e","n","g","t","h","."}; private String msgArray2[] = {"C","o","n","g","r","a","d","u","l","a","t","i","o","n","s", " ", 8. "y", "o", "u","'","v","e"," ","a","l","r","e","a","d","y"," ","m","e", "t", " ", 9. "t","h", "e", " ","r","e","q","u","i","r","e","m","e","n","t","."}; 10. private int sleepMS; public TypeWriter(int sleepMS){ 13.this.sleepMS = sleepMS; } public void sayHello(){ 16. System.out.println (“Hello, welcome to CS ”); } private void pause(){ 19. try{ 20. Thread.sleep(sleepMS); 21. }catch(InterruptedException e) { … } 22. }

TypeWriter.java(2/2) 23.public void say (int startIndex, int stopIndex){ 24. try{ 25.for (int i = startIndex ; i <= stopIndex ; i++ ) 26. { 27.System.out.print(); 28. pause(); 29.} 30. if(){ 31. System.out.println("\nTry differnet index number; this one is too small."); 32. } 33. else if(stopIndex==this.msgArray.length-1){ 34. System.out.println(" "); 35. for (int i = 0 ; i <= this.msgArray2.length ; i++ ) { 36. System.out.print(msgArray2[i]); 37.pause(); } 38. } 39. }catch(Exception e){ 40. //System.out.println("exp"+this.msgArray.length+" "+stopIndex); 41. /*Tell the user the number is too large here.*/ 42.…

TypeWriterCaller.java 1.//import ?? 2.public class TypeWriterCaller{ 3. TypeWriter TW; 4.public TypeWriterCaller(int end){ 5. 6.TW = new TypeWriter(200); 7.TW.sayHello(); 8.TW.say(0, end); 9.} 10. public static void main(String[] args){ 11.int end = Integer.parseInt(args[0]); 12.TypeWriterCaller TWC= new TypeWriterCaller(end); 13.} 14.}