Quick Introduction to Java
|
|
|
- Audrey Patrick
- 9 years ago
- Views:
Transcription
1 Quick Introduction to Java Dr. Chris Bourke Department of Computer Science & Engineering University of Nebraska Lincoln Lincoln, NE 68588, USA /10/30 20:02:28 Abstract These are lecture notes used in CSCE 155 and CSCE 156 (Computer Science I & II) at the University of Nebraska Lincoln. They represent a short introduction to the Java programming language for students who already have a strong foundation in at least one high-level programming language. Contents 1 Overview History Key Aspects Hello World Demo Variables Primitives Assignments & Literals Declaration Operators 8 4 Strings 8 5 Arrays 9 1
2 6 Conditionals 10 7 Loops 11 8 Input & Output Command Line Arguments Standard I/O File Output Searching & Sorting Classes Exceptions 18 Code Samples 1 Hello World Java Program Demonstration of Java Wrapper Classes Different Bases in Java Casting in Java Strings in Java Arrays in Java Conditionals in Java Loops in Java Java Command Line Arguments Java Buffered Input Java Scanner Java File Output Searching & Sorting Bank Account class in Java Exceptions in Java
3 1 Overview 1.1 History Developed by James Gosling, Sun Microsystems (1995) Designed with 5 basic principles Simple, Object-oriented, familiar Robust and secure Architecture-neutral and portable High performance Interpreted, threaded and dynamic Version History introduced JDBC, inner classes, reflection Collections framework JNDI, HotSpot JVM Library improvements Generics introduced, enhanced-for loop (foreach loop), concurrency utilities SE JVM improvements (synch, compiler, garbage collection), Update 26 (June 7, 2011) 1.7 July : Oracle purchases Sun Summer 2012: Oracle loses lawsuit to Google (APIs, interfaces cannot be copyrighted) 1.2 Key Aspects C-style syntax: semicolons, bracketed code blocks, identifiers Objected-oriented: everything is a class or belongs to a class No memory management Built-in garbage collection When no valid references to an object exist, it is eligible for garbage collection 3
4 JVM uses sophisticated algorithms to determine when it is optimal to perform garbage collection Little or no control on when or how this occurs Portable Write once, compile once, run anywhere Compiled code is run within a Java Virtual Machine 1.3 Hello World Demo Packages Packages allow you to organize code into a tree-like structure Period delimits packages-subpackages Naming convention: all lower case, underscores; should go from general to specific Actual code is stored in a directory tree corresponding to the package names Class declarations Java: everything is a class or belongs to a class Code must be in a file with the same name as the class, HelloWorld.java Naming convention: UpperCamelCase Comments follow C-style comments //single line comments /* multi line comments */ Javadoc style comments Main method declaration Standard output (System.out.println) JDK Libraries java.lang, java.util, java.io, java.sql, java.net, java.math, java.security Collections: List, ArrayList, Set, HashSet, Map, HashMap 4
5 Code Sample 1: Hello World Java Program 1 package unl. cse ; // package declaration 2 3 // imports would go here 4 5 /** 6 * A basic hello world program in Java 7 */ 8 public class HelloWorld { 9 10 // static main method 11 public static void main ( String args []) { 12 System. out. println (" Hello World!"); 13 } } Command line demo Editing Compiling: javac HelloWorld.java Produces a.class file (Java Bytecode) Running: java HelloWorld IDE (Eclipse) demo Create a project, package, class Compiling: automatic; running 2 Variables 2.1 Primitives A primitive is a type that is built-in to a language Java defines 8 primitives (see Table 1) Java does define default values for variables: zero for numeric types, false for boolean types Wrapper classes provide an object-equivalent version for each primitive type 5
6 Type Details Wrapper Class byte 8-bit signed 2s complement integer Byte short 16-bit signed 2s complement integer Short int 32-bit signed 2s complement integer Integer long 64-bit signed 2s complement integer Long float 32-bit IEEE 754 floating point number Float double 64-bit floating point number Double boolean may be set to true or false Boolean char 16-bit unicode character Character Table 1: Primitive types in Java Wrapper classes have many utility functions for conversion, parsing, etc. Instances can be null, may need to make null pointer checks Instances of such classes are immutable: once created, they cannot be changed; only new instances can be created Code Sample 2: Demonstration of Java Wrapper Classes 1 // convert a string to an integer : 2 String s = " 1234 " 3 int a = Integer. parseint (s); 4 String a_bin = Integer. tostring (a, 2); 5 System. out. println (a + " in binary is " + a_bin ); 6 Integer b; 7 a += b; // would result in a NullPointerException 2.2 Assignments & Literals The standard assignment operator, = Standard numerical literals integers, floats (f), longs (l); scientific notation supported, 4.2e1 or 4.2E1 Different bases supported (see Code Sample 3) Character literals delimited by single quotes, char a = C or unicode (hex) escape: char a = \u4ffa String literals delimited by double quotes, String s = "hello"; Standard escape sequences 6
7 Sequence Meaning \b backspace \t tab \n line feed \f form feed \r carriage return \" double quote \ single quote \\ backslash Code Sample 3: Different Bases in Java 1 int n; 2 n = 0 b0010_1010 ; // binary, Java 7 only 3 n = 052; // octal, leading zero 4 n = 42; // decimal 5 n = 0 x2a ; // hex 2.3 Declaration Java is strongly typed; every variable must be declared to have a particular type and will always be that type (aka statically typed) Identifier rules: Identifiers can include characters A-Z, a-z, 0-9, _, $ but cannot begin with a digit Identifiers are case sensitive Naming convention: lowercamelcase Naming convention: CAPS_FOR_STATIC_CONSTANTS Cannot be a reserved word (see java/nutsandbolts/_keywords.html) Scoping rules: variables are only valid within the block in which they are declared Casting: java does not allow implicit type casting when downcasting, does allow explicit; see Code Sample 4 Code Sample 4: Casting in Java 1 Double x = 10; // compile error 2 double y = 10; // okay (!) 7
8 3 Integer z = 10. 0; // compile error 4 int a = 10. 0; // compile error 5 // explicit type casting is required : 6 int a = 10; 7 double b = 10. 5; 8 double x = a + b; // okay 9 int c = a + b; // compile error 10 int d = ( int ) ( a + b); // explicit cast ok, truncation occurs 3 Operators Unary operators: increment/decrement, ++, -- Arithmetic: * / + - % Relational <, <=, >, >= Equality: ==,!=: careful when used with objects: reference comparison Logical:!, &&, (can only be applied to boolean expressions or variables, not integers!) 4 Strings Strings are a class provided as standard by the language Immutable; mutable version: StringBuilder Concatenation operator: + Comparison Using == is a reference operator, not a content comparison Strings are naturally ordered (lexicographically) by the language Meaning: they implement the Comparable interface They have a method: a.compareto(b) which returns: 0 if a, b have the same content < 0 if a precedes b (a comes before b) > 0 if a succeeds b (b comes before a) 8
9 a b Result foo bar positive bar baz negative foo foo zero aaa aaaa negative Table 2: Examples results of a.compareto(b) Various other member and static methods exist: public char charat(int) - returns the character at the specified position public String substring(int, int) - returns the substring between the indices (inclusive/exclusive) public String replaceall(string, String) - replaces all matches to the (first) regular expression with the second More: Code Sample 5: Strings in Java 1 String s1 = " Hello " + " " + " World!"; 2 System. out. println (s1); 3 4 StringBuilder sb = new StringBuilder (); 5 sb. append (" Goodbye "); 6 sb. append (" "). append (" World!"); 7 String s2 = sb. tostring (); 8 System. out. println (s2); 9 10 if(s1. compareto (s2) > 0) { 11 System. out. println (" Goodbye World! comes second "); 12 else if(s1. compareto (s2) < 0) { 13 System. out. println (" Hello World! comes second "); 14 } else { 15 System. out. println (" They are equal somehow "); 16 } // replace all whitespace with underscores : 19 String s3 = s1. replaceall ("\s", "_"); 5 Arrays All arrays are statically typed 9
10 Implicit size declaration: String mystrings[] = {"Hello", "world", "how", "are", "you"}; Dynamic declaration using the new operator: String mystrings[] = new String[10]; int myids[] = new String[20]; Arrays are zero-indexed and contiguous; size is kept track through a.length property: Multidimensional arrays supported Dynamic Collections alternative: ArrayList Code Sample 6: Arrays in Java 1 int myids [] = new int [ 10]; 2 myids [0] = 10; 3 System. out. println (" myids is an array of size " + myids. length + ", and the first element is " + myids [ 0]) ; 4 5 int mymatrix [][] = new int [5][5]; 6 mymatrix [ 0][ 4] = 10; // first row, last column 7 8 ArrayList < Integer > mylist = new ArrayList < Integer >() ; 9 mylist. add (10) ; 10 mylist. add (20) ; 11 mylist. add (30) ; 12 System. out. println (" mylist is an array list of size " + mylist. size () + ", and the first element is " + mylist. get (0) ); 6 Conditionals All the basic if-statements are supported Switch statements supported for integers Switch statements supported for Strings as of Java 7 Code Sample 7: Conditionals in Java 1 if(a > b) { 2 System. out. println (" foo "); 3 } 10
11 4 5 if(a > b) { 6 System. out. println (" foo "); 7 } else { 8 System. out. println (" bar "); 9 } if(a > b) { 12 System. out. println (" foo "); 13 } else if (a == b) { 14 System. out. println (" bar "); 15 } else { 16 System. out. println (" baz "); 17 } int month =...; 20 switch ( month ) { 21 case 1: 22 System. out. println (" January "); 23 break ; 24 case 2: 25 System. out. println (" February "); 26 break ; 27 case 3: 28 System. out. println (" March "); 29 break ; 30 default : 31 System. out. println (" Smarch "); 32 break ; 33 } 7 Loops Basic loops supported: for, while, do-while Enhanced for-loop for collections (arrays or any class that implements the Iterable interface) Code Sample 8: Loops in Java 1 for ( int i =0; i <10; i ++) { 2 System. out. println ("i = " + i); 3 } 4 11
12 5 int j = 0; 6 while (j < 10) { 7 System. out. println ("j = " + j); 8 j ++; 9 } j = 0; 12 do { 13 System. out. println ("j = " + j); 14 j ++; 15 } while (j <10); String mystrings [] = {" hello ", " world ", " foo ", " bar ", " baz "}; 18 for ( String s : mystrings ) { 19 System. out. println (s); 20 } // older idiom for Iterable collections : 23 while (c. hasnext ()) { 24 System. out. println (c. next ()); 25 } 8 Input & Output 8.1 Command Line Arguments Most programs do not involve a user interface or even involve human interaction. Instead, programs executed from the command line can be configured by specifying command line arguments which are passed to the program when invoking it. For example: ~>./programname argument1 argument2 When a Java class is executed through the JVM via the command line, arguments can be passed to the class in a similar manner: ~>java JavaClass arg1 arg2 arg3 Note: Arguments are accessible in the main method through the args array: public static void main(string args[]) In most languages, the first argument is the name of the executable file. However, for Java, the first argument is not the class In the example above, arg[0] would hold the string arg1, etc. 12
13 Code Sample 9: Java Command Line Arguments 1 /** 2 * This program demonstrates command line argument usage 3 * by printing out all the arguments passed to it when invoked. 4 */ 5 public class CommandLineArgumentDemo { 6 public static void main ( String args []) { 7 if( args. length == 0) { 8 System. out. println (" No command line arguments provided " ); 9 } else { 10 for ( int i =0; i< args. length ; i ++) { 11 System. out. println (" args [" + i + "] = " + args [i]); 12 } 13 } 14 } 15 } 8.2 Standard I/O Standard Output: System.out (methods: print, println, printf) Printf-style formatting: String.format or System.out.printf Object-oriented formatting: java.util.formatter class Several classes exist BufferedReader, BufferedWriter, InputStream, OutputStream Better alternative: Scanner Code Sample 10: Java Buffered Input 1 try { 2 String line = null ; 3 // create a BufferedReader from a FileReader 4 BufferedReader br = new BufferedReader ( new FileReader (" input. txt ")); 5 // read the first line 6 line = br. readline (); 7 // while the line read is not null ( end of file ) 8 while ( line!= null ) { 9 // process the line 10 System. out. println ( line ); 11 // read the next line 13
14 12 line = br. readline (); 13 } 14 } catch ( Exception e) { } Code Sample 11: Java Scanner 1 // read from the standard input : 2 Scanner s = new Scanner ( System. in); 3 System. out. println (" Enter an integer : "); 4 int n = s. nextint (); 5 6 // read from a file 7 Scanner s = new Scanner ( new File (" input. txt ")); 8 int x = s. nextint (); 9 double y = s. nextdouble (); 10 String s = s. next (); 11 String line = s. nextline (); 12 while (s. hasnext ()) { 13 line = s. nextline (); 14 } // by default, Scanner tokenizes on whitespace, 17 // you can reset this to any regular expression : 18 s. usedelimiter (","); 8.3 File Output Buffered text output: BufferedWriter and FileWriter Binary output: FileOutputStream Non-buffered text output: PrintWriter Code Sample 12: Java File Output 1 // Buffered text output : 2 File f = new File (" outfile. txt "); 3 BufferedWriter bw = new BufferedWriter ( new FileWriter ( f)); 4 // can write string or character data 5 bw. write (" Hello World \n"); 6 7 // Binary data output : 8 byte barray [] =...; 14
15 9 File f = new File (" outfile. bin "); 10 FileOutputStream fos = new FileOutputStream ( f); 11 fos. write ( barray ); // Non - buffered text output ( easier, but fails silently ): 14 File f = new File (" outfile02. txt "); 15 PrintWriter pw = new PrintWriter ( f); 16 pw. print (" Hello "); 17 pw. print (10) ; 18 pw. print (3.14) ; 19 // or: 20 pw. printf ("%s, %d, %.4 f\n", " Hello ", 10, 3.14) ; 9 Searching & Sorting The Arrays class provides two sort methods for arrays Arrays.sort(...) Arrays.sort(T a[], Comparator<? super T> c) The Collections class provides two sort methods for lists Collections.sort(List<T> list) Collections.sort(List<T> list, Comparator<? super T> c) First version is for anything that is naturally ordered: any class that implements the Comparable interface Second version is for any type, but you must provide a Comparator for it Searching: binarysearch methods, collections have contains, indexof methods Code Sample 13: Searching & Sorting 1 int ids [] =...; 2 Arrays. sort ( ids ); 3 4 Comparator < Student > c = new Comparator < Student >() { 5 public int compare ( Student s1, Student s2) { 6 if(s1. getgpa () > s2. getgpa ()) { 7 return -1; 8 } else if (s1. getgpa () < s2. getgpa ()) { 9 return 1; 10 } else { 15
16 11 return 0; 12 } 13 } 14 }; Student roster [] =...; 17 Arrays. sort ( roster, c); ArrayList < Student > roster = new ArrayList < Student >() ; 20 Collections. sort ( roster, c); 10 Classes Object-oriented programming involves the interaction of complex, abstract data types (ADTs), often realized in programming languages as classes. Java is a class-based OOP language. Classes can be viewed as a blueprint for creating (called instantiating) instances which provide both state and behavior. Declaration Member variables: visibility-level type name; Visibility keywords (cf. Table 3), accessors/mutators: getters and setters Member methods: declared inside a class Constructors: same name as the class, no return type, multiple constructors can be defined; default one provided if none are defined Instantiation (new keyword invokes a constructor) Usage: dot operator Other modifiers static can be used with a method or variable to make it a member of the class instead of instances of the class. Access would then be through the class rather than an instance: BankAccount.foo() final can be used with a variable to make it a constant; attempts to modify a final variable are a compiler error final can also be used on methods (to make them non-virtual); and classes (to make them non-derivable) 16
17 Code Sample 14: Bank Account class in Java 1 public class BankAccount { 2 3 public static final String BANK_NAME = " First International Bank Co."; 4 5 private int bankaccountid ; 6 private String label ; 7 private double balance ; 8 private double apr ; 9 10 public BankAccount ( int bankaccountid, String label, double balance, double apr ) { 11 this. bankaccountid = bankaccountid ; 12 this. label = label ; 13 this. balance = balance ; 14 this. apr = apr ; 15 } public BankAccount ( int bankaccountid, String label ) { 18 this ( bankaccountid, label, 0.0, 0. 0) ; 19 } public int getbankaccountid () { 22 return this. id; 23 } public void setbalance ( double balance ) { 26 this. balance = balance ; 27 } // more getters and setters as desired here public void deposit ( double deposit ) { 32 this. balance += deposit ; 33 } public double getmonthlyinterestearned () { 36 return this. balance * this. apr / 12. 0; 37 } private double getapy () { 40 return Math. exp ( this. apr ) - 1; 41 } 42 17
18 44 public String tostring () { 45 return this. label + " (" + this. bankaccountid + ") $" + this. balance ; 46 } 47 } BankAccount a = new BankAccount (1234, " Checking "); 52 a. setbalance (1000.0) ; 53 a. deposit (100.0) ; 54 a. deposit (a. getmonthlyinterestearned ()); 55 System. out. println (a); System. out. println (" Bank Name : " + BankAccount. BANK_NAME ); Keyword Class Package Subclass(es) World public Y Y Y Y protected Y Y Y N public Y Y N N private Y N N N Table 3: Visibility Keywords and Access Levels 11 Exceptions Run-time errors occur when something goes wrong and your program cannot handle it (or by design shouldn t) We may be able to recover from some errors by handling them An Exception is an error that is not usual, but could be anticipated (FileNotFoundException ) Exceptions can be thrown or caught and handled Handling can be done in a try-catch-finally block Many predefined standard exceptions Uncaught exceptions will bubble up until caught or it kills the JVM process 18
19 Code Sample 15: Exceptions in Java 1 String s =...; 2 int n; 3 try { 4 // potentially unsafe code : 5 n = Integer. parseint (s); 6 } catch ( NumberFormatException nfe ) { 7 System. out. println (" String does not contain a valid numeric representation "); 8 } catch ( NullPointerException npe ) { 9 System. out. println (" String is null!"); 10 } catch ( Exception e) { 11 System. out. println (" Some other exception occurred, stack track follows... "); 12 e. printstacktrace (); 13 } finally { 14 // this code block will be executed whether or not an exception is thrown 15 // could be used to clean up any outstanding resources 16 } // throwing : 19 if(n == 0) { 20 throw new RuntimeException (" cannot divide by zero!"); 21 } 19
Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.
Handout 1 CS603 Object-Oriented Programming Fall 15 Page 1 of 11 Handout 1 Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner. Java
AP Computer Science Java Subset
APPENDIX A AP Computer Science Java Subset The AP Java subset is intended to outline the features of Java that may appear on the AP Computer Science A Exam. The AP Java subset is NOT intended as an overall
Introduction to Java
Introduction to Java The HelloWorld program Primitive data types Assignment and arithmetic operations User input Conditional statements Looping Arrays CSA0011 Matthew Xuereb 2008 1 Java Overview A high
Java Programming Fundamentals
Lecture 1 Part I Java Programming Fundamentals Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Introduction to Java We start by making a few
Fundamentals of Java Programming
Fundamentals of Java Programming This document is exclusive property of Cisco Systems, Inc. Permission is granted to print and copy this document for non-commercial distribution and exclusive use by instructors
Object-Oriented Programming in Java
CSCI/CMPE 3326 Object-Oriented Programming in Java Class, object, member field and method, final constant, format specifier, file I/O Dongchul Kim Department of Computer Science University of Texas Rio
public static void main(string[] args) { System.out.println("hello, world"); } }
Java in 21 minutes hello world basic data types classes & objects program structure constructors garbage collection I/O exceptions Strings Hello world import java.io.*; public class hello { public static
Introduction to Java Applications. 2005 Pearson Education, Inc. All rights reserved.
1 2 Introduction to Java Applications 2.2 First Program in Java: Printing a Line of Text 2 Application Executes when you use the java command to launch the Java Virtual Machine (JVM) Sample program Displays
Crash Course in Java
Crash Course in Java Based on notes from D. Hollinger Based in part on notes from J.J. Johns also: Java in a Nutshell Java Network Programming and Distributed Computing Netprog 2002 Java Intro 1 What is
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2015 The third
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4
JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4 NOTE: SUN ONE Studio is almost identical with NetBeans. NetBeans is open source and can be downloaded from www.netbeans.org. I
Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program
Free Java textbook available online "Thinking in Java" by Bruce Eckel, 4th edition, 2006, ISBN 0131872486, Pearson Education Introduction to the Java programming language CS 4354 Summer II 2014 Jill Seaman
Chulalongkorn University International School of Engineering Department of Computer Engineering 2140105 Computer Programming Lab.
Chulalongkorn University Name International School of Engineering Student ID Department of Computer Engineering Station No. 2140105 Computer Programming Lab. Date Lab 2 Using Java API documents, command
Computer Programming I
Computer Programming I COP 2210 Syllabus Spring Semester 2012 Instructor: Greg Shaw Office: ECS 313 (Engineering and Computer Science Bldg) Office Hours: Tuesday: 2:50 4:50, 7:45 8:30 Thursday: 2:50 4:50,
Introduction to Java Lecture Notes. Ryan Dougherty [email protected]
1 Introduction to Java Lecture Notes Ryan Dougherty [email protected] Table of Contents 1 Versions....................................................................... 2 2 Introduction...................................................................
CS 111 Classes I 1. Software Organization View to this point:
CS 111 Classes I 1 Software Organization View to this point: Data Objects and primitive types Primitive types operators (+, /,,*, %). int, float, double, char, boolean Memory location holds the data Objects
An Overview of Java. overview-1
An Overview of Java overview-1 Contents What is Java Major Java features Java virtual machine Java programming language Java class libraries (API) GUI Support in Java Networking and Threads in Java overview-2
Chapter 2: Elements of Java
Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction
Moving from CS 61A Scheme to CS 61B Java
Moving from CS 61A Scheme to CS 61B Java Introduction Java is an object-oriented language. This document describes some of the differences between object-oriented programming in Scheme (which we hope you
Java Interview Questions and Answers
1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java
Lecture 5: Java Fundamentals III
Lecture 5: Java Fundamentals III School of Science and Technology The University of New England Trimester 2 2015 Lecture 5: Java Fundamentals III - Operators Reading: Finish reading Chapter 2 of the 2nd
Basic Java Constructs and Data Types Nuts and Bolts. Looking into Specific Differences and Enhancements in Java compared to C
Basic Java Constructs and Data Types Nuts and Bolts Looking into Specific Differences and Enhancements in Java compared to C 1 Contents Hello World Program Statements Explained Java Program Structure in
CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java
CS1020 Data Structures and Algorithms I Lecture Note #1 Introduction to Java Objectives Java Basic Java features C Java Translate C programs in CS1010 into Java programs 2 References Chapter 1 Section
Basic Programming and PC Skills: Basic Programming and PC Skills:
Texas University Interscholastic League Contest Event: Computer Science The contest challenges high school students to gain an understanding of the significance of computation as well as the details of
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
Exam Name MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) The JDK command to compile a class in the file Test.java is A) java Test.java B) java
The Sun Certified Associate for the Java Platform, Standard Edition, Exam Version 1.0
The following applies to all exams: Once exam vouchers are purchased you have up to one year from the date of purchase to use it. Each voucher is valid for one exam and may only be used at an Authorized
Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:
Introduction to Programming and Algorithms Module 2 CS 146 Sam Houston State University Dr. Tim McGuire Introduction To Computers And Java Chapter Objectives To understand: the meaning and placement of
Pemrograman Dasar. Basic Elements Of Java
Pemrograman Dasar Basic Elements Of Java Compiling and Running a Java Application 2 Portable Java Application 3 Java Platform Platform: hardware or software environment in which a program runs. Oracle
First Java Programs. V. Paúl Pauca. CSC 111D Fall, 2015. Department of Computer Science Wake Forest University. Introduction to Computer Science
First Java Programs V. Paúl Pauca Department of Computer Science Wake Forest University CSC 111D Fall, 2015 Hello World revisited / 8/23/15 The f i r s t o b l i g a t o r y Java program @author Paul Pauca
java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner
java.util.scanner java.util.scanner is a class in the Java API used to create a Scanner object, an extremely versatile object that you can use to input alphanumeric characters from several input sources
JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.
http://www.tutorialspoint.com/java/java_quick_guide.htm JAVA - QUICK GUIDE Copyright tutorialspoint.com What is Java? Java is: Object Oriented Platform independent: Simple Secure Architectural- neutral
6.1. Example: A Tip Calculator 6-1
Chapter 6. Transition to Java Not all programming languages are created equal. Each is designed by its creator to achieve a particular purpose, which can range from highly focused languages designed for
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq
qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq Introduction to Programming using Java wertyuiopasdfghjklzxcvbnmqwertyui
D06 PROGRAMMING with JAVA
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch16 Files and Streams PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for
CS 106 Introduction to Computer Science I
CS 106 Introduction to Computer Science I 01 / 21 / 2014 Instructor: Michael Eckmann Today s Topics Introduction Homework assignment Review the syllabus Review the policies on academic dishonesty and improper
Chapter 2. println Versus print. Formatting Output withprintf. System.out.println for console output. console output. Console Input and Output
Chapter 2 Console Input and Output System.out.println for console output System.out is an object that is part of the Java language println is a method invoked dby the System.out object that can be used
www.virtualians.pk CS506 Web Design and Development Solved Online Quiz No. 01 www.virtualians.pk
CS506 Web Design and Development Solved Online Quiz No. 01 Which of the following is a general purpose container? JFrame Dialog JPanel JApplet Which of the following package needs to be import while handling
Explain the relationship between a class and an object. Which is general and which is specific?
A.1.1 What is the Java Virtual Machine? Is it hardware or software? How does its role differ from that of the Java compiler? The Java Virtual Machine (JVM) is software that simulates the execution of a
CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013
Oct 4, 2013, p 1 Name: CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013 1. (max 18) 4. (max 16) 2. (max 12) 5. (max 12) 3. (max 24) 6. (max 18) Total: (max 100)
Chapter 3. Input and output. 3.1 The System class
Chapter 3 Input and output The programs we ve looked at so far just display messages, which doesn t involve a lot of real computation. This chapter will show you how to read input from the keyboard, use
Java Application Developer Certificate Program Competencies
Java Application Developer Certificate Program Competencies After completing the following units, you will be able to: Basic Programming Logic Explain the steps involved in the program development cycle
Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.
Scanner The Scanner class is intended to be used for input. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit. For example, suppose the input
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007
Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007 The Java Type System By now, you have seen a fair amount of Java. Time to study in more depth the foundations of the language,
Java from a C perspective. Plan
Java from a C perspective Cristian Bogdan 2D2052/ingint04 Plan Objectives and Book Packages and Classes Types and memory allocation Syntax and C-like Statements Object Orientation (minimal intro) Exceptions,
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O
CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O 1 Sending Output to a (Text) File import java.util.scanner; import java.io.*; public class TextFileOutputDemo1 public static void
Week 1: Review of Java Programming Basics
Week 1: Review of Java Programming Basics Sources: Chapter 2 in Supplementary Book (Murach s Java Programming) Appendix A in Textbook (Carrano) Slide 1 Outline Objectives A simple Java Program Data-types
Variables, Constants, and Data Types
Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight
Programming Languages CIS 443
Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception
Files and input/output streams
Unit 9 Files and input/output streams Summary The concept of file Writing and reading text files Operations on files Input streams: keyboard, file, internet Output streams: file, video Generalized writing
Java CPD (I) Frans Coenen Department of Computer Science
Java CPD (I) Frans Coenen Department of Computer Science Content Session 1, 12:45-14:30 (First Java Programme, Inheritance, Arithmetic) Session 2, 14:45-16:45 (Input and Programme Constructs) Materials
WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.
WA2099 Introduction to Java using RAD 8.0 Student Labs Web Age Solutions Inc. 1 Table of Contents Lab 1 - The HelloWorld Class...3 Lab 2 - Refining The HelloWorld Class...20 Lab 3 - The Arithmetic Class...25
UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming
UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming 1 2 Foreword First of all, this book isn t really for dummies. I wrote it for myself and other kids who are on the team. Everything
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa September 14, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction
Event-Driven Programming
Event-Driven Programming Lecture 4 Jenny Walter Fall 2008 Simple Graphics Program import acm.graphics.*; import java.awt.*; import acm.program.*; public class Circle extends GraphicsProgram { public void
13 File Output and Input
SCIENTIFIC PROGRAMMING -1 13 File Output and Input 13.1 Introduction To make programs really useful we have to be able to input and output data in large machinereadable amounts, in particular we have to
Syllabus for CS 134 Java Programming
- Java Programming Syllabus Page 1 Syllabus for CS 134 Java Programming Computer Science Course Catalog 2000-2001: This course is an introduction to objectoriented programming using the Java language.
Creating a Simple, Multithreaded Chat System with Java
Creating a Simple, Multithreaded Chat System with Java Introduction by George Crawford III In this edition of Objective Viewpoint, you will learn how to develop a simple chat system. The program will demonstrate
Chapter 2 Introduction to Java programming
Chapter 2 Introduction to Java programming 1 Keywords boolean if interface class true char else package volatile false byte final switch while throws float private case return native void protected break
Sources: On the Web: Slides will be available on:
C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,
Programmation 2. Introduction à la programmation Java
Programmation 2 Introduction à la programmation Java 1 Course information CM: 6 x 2 hours TP: 6 x 2 hours CM: Alexandru Costan alexandru.costan at inria.fr TP: Vincent Laporte vincent.laporte at irisa.fr
CSC 551: Web Programming. Fall 2001
CSC 551: Web Programming Fall 2001 Java Overview! Design goals & features "platform independence, portable, secure, simple, object-oriented,! Language overview " program structure, public vs. private "instance
File class in Java. Scanner reminder. Files 10/19/2012. File Input and Output (Savitch, Chapter 10)
File class in Java File Input and Output (Savitch, Chapter 10) TOPICS File Input Exception Handling File Output Programmers refer to input/output as "I/O". The File class represents files as objects. The
Using Files as Input/Output in Java 5.0 Applications
Using Files as Input/Output in Java 5.0 Applications The goal of this module is to present enough information about files to allow you to write applications in Java that fetch their input from a file instead
Introduction to Java. CS 3: Computer Programming in Java
Introduction to Java CS 3: Computer Programming in Java Objectives Begin with primitive data types Create a main class with helper methods Learn how to call built-in class methods and instance methods
Install Java Development Kit (JDK) 1.8 http://www.oracle.com/technetwork/java/javase/downloads/index.html
CS 259: Data Structures with Java Hello World with the IntelliJ IDE Instructor: Joel Castellanos e-mail: joel.unm.edu Web: http://cs.unm.edu/~joel/ Office: Farris Engineering Center 319 8/19/2015 Install
Chapter 1 Java Program Design and Development
presentation slides for JAVA, JAVA, JAVA Object-Oriented Problem Solving Third Edition Ralph Morelli Ralph Walde Trinity College Hartford, CT published by Prentice Hall Java, Java, Java Object Oriented
Comp 248 Introduction to Programming
Comp 248 Introduction to Programming Chapter 2 - Console Input & Output Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia University, Montreal, Canada These slides has been
Java Crash Course Part I
Java Crash Course Part I School of Business and Economics Institute of Information Systems HU-Berlin WS 2005 Sebastian Kolbe [email protected] Overview (Short) introduction to the environment Linux
1 of 1 24/05/2013 10:23 AM
?Init=Y 1 of 1 24/05/2013 10:23 AM 1. Which of the following correctly defines a queue? a list of elements with a first in last out order. a list of elements with a first in first out order. (*) something
Java Cheatsheet. http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix
Java Cheatsheet http://introcs.cs.princeton.edu/java/11cheatsheet/ Tim Coppieters Laure Philips Elisa Gonzalez Boix Hello World bestand genaamd HelloWorld.java naam klasse main methode public class HelloWorld
CS 1302 Ch 19, Binary I/O
CS 1302 Ch 19, Binary I/O Sections Pages Review Questions Programming Exercises 19.1-19.4.1, 19.6-19.6 710-715, 724-729 Liang s Site any Sections 19.1 Introduction 1. An important part of programming is
CS106A, Stanford Handout #38. Strings and Chars
CS106A, Stanford Handout #38 Fall, 2004-05 Nick Parlante Strings and Chars The char type (pronounced "car") represents a single character. A char literal value can be written in the code using single quotes
Habanero Extreme Scale Software Research Project
Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead
02 B The Java Virtual Machine
02 B The Java Virtual Machine CS1102S: Data Structures and Algorithms Martin Henz January 22, 2010 Generated on Friday 22 nd January, 2010, 09:46 CS1102S: Data Structures and Algorithms 02 B The Java Virtual
java Features Version April 19, 2013 by Thorsten Kracht
java Features Version April 19, 2013 by Thorsten Kracht Contents 1 Introduction 2 1.1 Hello World................................................ 2 2 Variables, Types 3 3 Input/Output 4 3.1 Standard I/O................................................
The Java I/O System. Binary I/O streams (ascii, 8 bits) The decorator design pattern Character I/O streams (Unicode, 16 bits)
Binary I/O streams (ascii, 8 bits) InputStream OutputStream The Java I/O System The decorator design pattern Character I/O streams (Unicode, 16 bits) Reader Writer Comparing Binary I/O to Character I/O
PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON
PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London
Informatica e Sistemi in Tempo Reale
Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 25, 2010 G. Lipari (Scuola Superiore Sant Anna)
#820 Computer Programming 1A
Computer Programming I Levels: 10-12 Units of Credit: 1.0 CIP Code: 11.0201 Core Code: 35-02-00-00-030 Prerequisites: Secondary Math I, Keyboarding Proficiency, Computer Literacy requirement Semester 1
Building a Multi-Threaded Web Server
Building a Multi-Threaded Web Server In this lab we will develop a Web server in two steps. In the end, you will have built a multi-threaded Web server that is capable of processing multiple simultaneous
Chapter 7D The Java Virtual Machine
This sub chapter discusses another architecture, that of the JVM (Java Virtual Machine). In general, a VM (Virtual Machine) is a hypothetical machine (implemented in either hardware or software) that directly
Semantic Analysis: Types and Type Checking
Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors
Computer Programming I
Computer Programming I Levels: 10-12 Units of Credit: 1.0 CIP Code: 11.0201 Core Code: 35-02-00-00-030 Prerequisites: Secondary Math I, Keyboarding Proficiency, Computer Literacy requirement (e.g. Exploring
Lecture 1 Introduction to Java
Programming Languages: Java Lecture 1 Introduction to Java Instructor: Omer Boyaci 1 2 Course Information History of Java Introduction First Program in Java: Printing a Line of Text Modifying Our First
Programmierpraktikum
Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 21 10/16/2012 09:29 AM Java - A First Glance 2 of 21 10/16/2012 09:29 AM programming languages
How To Write A Program In Java (Programming) On A Microsoft Macbook Or Ipad (For Pc) Or Ipa (For Mac) (For Microsoft) (Programmer) (Or Mac) Or Macbook (For
Projet Java Responsables: Ocan Sankur, Guillaume Scerri (LSV, ENS Cachan) Objectives - Apprendre à programmer en Java - Travailler à plusieurs sur un gros projet qui a plusieurs aspects: graphisme, interface
Example of a Java program
Example of a Java program class SomeNumbers static int square (int x) return x*x; public static void main (String[] args) int n=20; if (args.length > 0) // change default n = Integer.parseInt(args[0]);
J a v a Quiz (Unit 3, Test 0 Practice)
Computer Science S-111a: Intensive Introduction to Computer Science Using Java Handout #11 Your Name Teaching Fellow J a v a Quiz (Unit 3, Test 0 Practice) Multiple-choice questions are worth 2 points
core. Volume I - Fundamentals Seventh Edition Sun Microsystems Press A Prentice Hall Title ULB Darmstadt
core. 2008 AGI-Information Management Consultants May be used for personal purporses only or by libraries associated to dandelon.com network. Volume I - Fundamentals Seventh Edition CAY S. HORSTMANN GARY
Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives
Introduction to Programming and Algorithms Module 1 CS 146 Sam Houston State University Dr. Tim McGuire Module Objectives To understand: the necessity of programming, differences between hardware and software,
Object Oriented Software Design
Object Oriented Software Design Introduction to Java - II Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 28, 2010 G. Lipari (Scuola Superiore Sant Anna) Introduction
No no-argument constructor. No default constructor found
Every software developer deals with bugs. The really tough bugs aren t detected by the compiler. Nasty bugs manifest themselves only when executed at runtime. Here is a list of the top ten difficult and
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals
CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals 1 Recall From Last Time: Java Program import java.util.scanner; public class EggBasket { public static void main(string[]
Java (12 Weeks) Introduction to Java Programming Language
Java (12 Weeks) Topic Lecture No. Introduction to Java Programming Language 1 An Introduction to Java o Java as a Programming Platform, The Java "White Paper" Buzzwords, Java and the Internet, A Short
Java Programming Language
Lecture 1 Part II Java Programming Language Additional Features and Constructs Topics in Quantitative Finance: Numerical Solutions of Partial Differential Equations Instructor: Iraj Kani Subclasses and
Getting Started with the Internet Communications Engine
Getting Started with the Internet Communications Engine David Vriezen April 7, 2014 Contents 1 Introduction 2 2 About Ice 2 2.1 Proxies................................. 2 3 Setting Up ICE 2 4 Slices 2
Android Application Development Course Program
Android Application Development Course Program Part I Introduction to Programming 1. Introduction to programming. Compilers, interpreters, virtual machines. Primitive data types, variables, basic operators,
We will learn the Python programming language. Why? Because it is easy to learn and many people write programs in Python so we can share.
LING115 Lecture Note Session #4 Python (1) 1. Introduction As we have seen in previous sessions, we can use Linux shell commands to do simple text processing. We now know, for example, how to count words.
Chapter 1 Fundamentals of Java Programming
Chapter 1 Fundamentals of Java Programming Computers and Computer Programming Writing and Executing a Java Program Elements of a Java Program Features of Java Accessing the Classes and Class Members The
