Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— 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 static int 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; }


Download ppt "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."

Similar presentations


Ads by Google