Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose.

Similar presentations


Presentation on theme: "CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose."— Presentation transcript:

1 CS591x A very brief introduction to Java

2 Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose language designed to support network programming

3 Java Java is a semi-compiled language Java compiler produces bytecode Bytecode not executable by itself like a binary executable (… except…) Must run Java bytecode in an execution environment Java Virtual Machine – JVM This give Java programs portability

4 Java Must download and install Java Software Developers Kit (SDK) A lot of kinds of Java out there You want J2SE 1.4.2 SDK Download it from java.sun.com install You may want a Java IDE

5 Java - Installation Installation should be straight-forward download open the installer package see installation instructions on java.sun.com/j2se Follow installation instructions/answer questions

6 Java Java SDK comes with a number of tools Java compiler  javac myprogram.java  compiler produces class files Java runtime environment (JVM)  java myprog Java Archiver – jar  jar cvf myjar.jar myprog.class ….

7 Java – Basic Syntax public class myprog { public static void main(String[] args) { System.out.println(“Hello from myprog”); }

8 Java – Basic syntax a Java program must start with a class name class name must match the program’s file name compiler will produce a.class file with the same name

9 Java – Basic syntax Java programs contain classes and methods There are Java applications and Java applets A Java application must have a main method public static void main(String[] args){ … }

10 Java – Basic Syntax Classes have zero or more properties and zero or more methods properties are variables associated with class methods are procedures for operating on the class, objects or properties Objects are instances of classes

11 Java – sample program public class sample { public static void main(String[] args) { String str; str = “first string”; System.out.println(str); str = “2 nd string”; System.out.println(str); }

12 Java Data Types chr – single unicode character String – string of characters int – integer float – floating point number boolean – boolean value

13 Java – Data Types byte – single byte signed integer short – two byte signed integer long – very double precision integer double – double precision float

14 Java Arithmetic operators + - * / % ++ -- use parentheses to set precedence Logical operators && - logical AND || logical OR ! logical NOT Assignment int x = 12; String st = “Hello”; float a = 12.5; a=b; a+=b; a-=b; a*=b; a/=b; a%=b; Comparison operators == != > = <=

15 Java Statements if (comparison-op) { code to be exec;} if (comparison-op) {do_this_code;} else {do_this_code_instead;} switch(num) { case 1 : {do_this;} case 2 : {do_that;} case 3 : {do_the_other;}

16 Java Statements for (initial_val; exit_test; increment) {iterative_code;} works just like c while (test_cond) { do_this_code;} do {do_this_code;} while (test_cond);

17 Java - Statements break; breaks out of a loop if (x==3) break; continue; drops through a loop if (x==3) continue; labels bigloop: for… continue bigloop;

18 Java Statements return – returns to the calling method can return values from called methods

19 Java - statements Arrays int[] x = {4,5,6}; String[] days = {“Monday”,”Tuesday”,…};

20


Download ppt "CS591x A very brief introduction to Java. Java Developed by Sun Microsystems was intended a language for embedded applications became a general purpose."

Similar presentations


Ads by Google