1 / 7

Java TA

Java TA. Session 1. Software. Java Runtime Environment (JRE) java.exe Java Development Kit (JDK) java.exe, javac.exe Version 1.6 = Version 6, Version 1.7 = Version 7 Edit System Variables: JAVA_HOME=C:Program FilesJavajdk1.6.0_32 PATH=[…];C :Program FilesJavajdk1.6.0_32bin

otto-kline
Download Presentation

Java TA

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 TA Session 1

  2. Software • Java Runtime Environment (JRE) • java.exe • Java Development Kit (JDK) • java.exe, javac.exe • Version 1.6 = Version 6, Version 1.7 = Version 7 • Edit System Variables: • JAVA_HOME=C:\Program Files\Java\jdk1.6.0_32 • PATH=[…];C:\Program Files\Java\jdk1.6.0_32\bin • Editor: Notepad++, gedit

  3. Java Startup • Open Test.java • Run javac: • C:\Users\user\Documents>javac Test.java • Run java: • C:\Users\user\Documents>java Test • Salam class Test { public static void main(String[] args) { System.out.println("Salam"); } }

  4. Errors C:\Users\user\Documents>javac Add1.java Add1.java:3: cannot find symbol symbol : class Scanner location: class Add1 Scanner s = new Scanner(System.in); ^ Add1.java:3: cannot find symbol symbol : class Scanner location: class Add1 Scanner s = new Scanner(System.in); ^ 2 errors

  5. Add Import statement import java.util.Scanner; class Add1 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int a = s.nextInt(), b = s.nextInt(); int c = a+b; System.out.println("Sum is " + c); } }

  6. What to Import? • You can read the Java API Specification at: • http://docs.oracle.com/javase/6/docs/api/ • Use search engines to find what you need: • For example you can use the following query to search for “scanner” in the Java 6 API, using google: scanner site:docs.oracle.com/javase/6/docs/api/

  7. Functions • Use functions declared as public and static: public staticint sum(int x, int y) • Rewriting the previous code with a function: import java.util.Scanner; class Add1 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int a = s.nextInt(); int b = s.nextInt(); int c = sum(a, b); System.out.println("Sum is " + c); } public static int sum(int x, int y) { return x+y; } }

More Related