Your SlideShare is downloading. ×
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Java overview
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Java overview

186

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
186
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Java OverviewName/Dept.: Lawrence HoDate: 2012.10.19
  • 2. Outline• History of Java• What’s Java?• An Overview of Object-Oriented Programming• What’s JVM?• Java Performance• JDK, JRE, JVM, Whats the Difference?
  • 3. Outline• Installing and Working with JDK• Integrated Development Environments (IDEs)• Eclipse IDE Installation• Eclipse user interface overview• Create a Java Project• An Overview of Java Statements• C and Java Comparison
  • 4. History of Java• 1991--Stealth Project for consumer electronics market (later Green Project) Language called Oak then renamed to Java.• 1995--Sun Microsystems released the first public implementation as Java 1.0 .• 2004—J2SE 5.0 release• 2006--Java SE 6 release• 2011--Java SE 7 release
  • 5. Whats Java?• Java is an object-oriented programming language.• Java is a platform that executes Java-based programs. – JRE installed on the device – Just-in-Time complier
  • 6. Automatic Memory Management• Java uses an automatic garbage collector to manage memory in the object lifecycle. 1. Find data objects in a program that cannot be accessed in the future 2. Reclaim the resources used by those objects
  • 7. Syntax(1)• Combines the syntax for structured, generic, and object-oriented programming• All code is written inside a class, and everything is an object.• Java does not support operator overloading or multiple inheritance for classes.• Comments: 1. // 2./* */ 3./** */
  • 8. Syntax(2)Example:// This is an example of a single line commentusing two slashes/* This is an example of a multiple linecomment using the slash and asterisk.This type of comment can be used to hold a lotof information or deactivatecode but it is very important to remember toclose the comment. *//*** This is an example of a Javadoc comment;Javadoc can compile documentation* from this text.*/
  • 9. An Overview of Object-Oriented Programming(1)• Encapsulation
  • 10. An Overview of Object-Oriented Programming(2)• Inheritance
  • 11. An Overview of Object-Oriented Programming(3)Animal Age Sex Mammal Weight Gestation PeriodCanine Hunting Tail Skills Length Domesticus Leash Indoor or Trained? OutdoorRetriever Duck Hunting Labrador Trained?
  • 12. An Overview of Object-Oriented Programming(4)• Polymorphism: Polymorphism (from Greek, meaning “many forms”) is a feature that allows one interface to be used for a general class of actions.
  • 13. Polymorphism public interface Animal{ public void voice(); public void voice(String a, int x); public String voice(int x); public int voice(String b); }public class Cat implements Animal{ public void voice(){ System.out.println(“Meow, meow~~~”); }} public class Dog implements Animal{ public void voice(“Thief”, 1){ System.out.println(““Woof, woof!!”); } }
  • 14. The benefits of OOP• Ease of maintenance: modular• Reusability• Extendibility: it’s achieved through inheritance
  • 15. Whats JVM?(1)• Traditional Programming Paradigm Source Code Compile Native Code
  • 16. Whats JVM?(2)• Often implemented to run on an existing operating system.• Provides an environment in which Java bytecode can be executed.• Automated exception handling.• Just-in-Time. Windows JVM Java Compile Bytecode UNIX JVM Source Code Linux JVM
  • 17. Java Performance(1)• This depends on how optimally its particular tasks are managed by the host Java Virtual Machine (JVM).• Slower than compiled languages such as C or C++.• Similar to other Just-in-time compiled languages such as C#.• Much faster than languages without an effective native-code compiler, such as Perl, Ruby, PHP and Python.
  • 18. Java Performance(2)• Java startup time is often much slower than many languages, including C, C++, Perl or Python.• A lot of classes (and first of all classes from the platform Class libraries) must be loaded before being used.
  • 19. JDK, JRE, JVM, Whats the Difference?• The JRE, which includes a JVM and the core libraries.• The JDK, which includes the JRE plus a compiler and other tools.• A JVM is a native application that runs bytecode.
  • 20. Installing and Working with JDK(1)• Download and installing JDK from here: http://www.oracle.com/technetwork/java/javase/downloads/index.html
  • 21. Installing and Working with JDK(2)• Setting System Environment Variables on Windows: 1. Click Start, Settings, Control Panel. 2. Double-click System. 3. Select the Advanced tab and then click on Environment Variables. 4. Add the full path to the bin directory of your Java installation directory to the end of the existing value of Path. The directory looks something like: C:Program FilesJavajdk1.6.0_35bin 5. Click Set, OK, or Apply.
  • 22. Installing and Working with JDK(3)
  • 23. Installing and Working with JDK(4)• JDK Command Tools: • jar: packaging classfiles and resource files into special ZIP files with ".jar" file extensions • java: running applications • javac: launches the Java compiler to compile one or more source files • javadoc: generates special HTML-based documentation from Javadoc comments
  • 24. Installing and Working with JDK(5)1.Write a first simple program and use command tools: public class Example { // Your program begins with a call to main(). public static void main(String args[]) { System.out.println(″This is a simple Java program.″); } }2.Execute the Complier, javac javac Example.java3.Use the Java application launcher called java java Example4.When the program is run, the following output is displayed: This is a simple Java program.
  • 25. Installing and Working with JDK(6)
  • 26. Integrated Development Environments (IDEs)• NetBeans (free and open source) (http://netbeans.org/)• Eclipse (free and open source) (http://www.eclipse.org/)• IntelliJ IDEA (http://www.jetbrains.com/idea/)
  • 27. Eclipse IDE Installation(1)• Install JDK first, then point your browser to http://www.eclipse.org• Choose Eclipse IDE for Java Developers and download it.
  • 28. Eclipse IDE Installation(2)• You’ll get a eclipse-java-juno-SR1-win32.zip file, and unpack it to a local directory.• To start Eclipse double-click on the file eclipse.exe in the directory where you unpacked Eclipse.
  • 29. Eclipse IDE Installation(3)• The system will prompt you for a workspace. The workspace is the place in which you work. Select an empty directory and press the OK button.
  • 30. Eclipse IDE Installation(4)• Eclipse will start and show the Welcome page. Close the welcome page by pressing the X beside Welcome. After you closed the welcome screen you should see a screen similar to the following:
  • 31. Eclipse user interface overview• Eclipse provides Perspectives, Views and Editors. Views and Editors are grouped into Perspectives.
  • 32. Create a Java Project(1)1. Select from the menu File → New → Java project. Enter com.zyxel.sampleas the project name. Select the Create separate folders for sources and classfiles flag. Press the Finish button to create the project.
  • 33. Create a Java Project(2)2.Create a Java class. Right click on your packageand select New → Class.3.Enter MyFirstClass as the class name andselect the public static void main (String[] args)flag.4.Press the Finish button.5.Write a simple code.6.Run your project in Eclipse.
  • 34. Open Source by Java Implement• Google Android OS• Eclipse, NetBeans IDE• Apache Tomcat, Ant, Hadoop......etc.
  • 35. An Overview of Java Statements(1)• The if statement The if statement is a conditional branch statement. if (a > 3) { // statements } else if { // statements } else { // statements } If there is only one statement in an if or else block, the braces are optional. if (a > 3) a++; else a = 3;
  • 36. An Overview of Java Statements(2)• The while Statement The following code prints integer numbers that are less than three. int i = 0; while (i < 3) { System.out.println(i); i++; }
  • 37. An Overview of Java Statements(3)• The do-while Statement The do-while statement is like the while statement, except that the associated block always gets executed at least once. For example, here is an example of the do-while statement: int i = 0; do { System.out.println(i); i++; } while (i < 3);
  • 38. An Overview of Java Statements(4)• The for Statement The for statement is like the while statement. The following for statement loops five times and each time prints the value of i. for (int i = 0; i < 3; i++) { System.out.println(i); } or int k = 0; for ( ; k < 3; ) { System.out.println(k); k++; }
  • 39. An Overview of Java Statements(5)• The break Statement The break statement is used to break from an enclosing do, while, for, or switch statement. int i = 0; while (true) { System.out.println(i); if (i > 3) { break; } }
  • 40. An Overview of Java Statements(6)• The continue Statement The continue statement is like break but it only stops the execution of the current iteration and causes control to begin with the next iteration. For example, the following code prints the number 0 to 9, except 5. for (int i = 0; i < 10; i++) { if (i == 5) { continue; } System.out.println(i); }
  • 41. An Overview of Java Statements(7)• The switch Statement “The if Statement,” is the switch statement. switch allows you to choose a block of statements to run from a selection of code, based on the return value of an expression. int i = 0; switch (i) { case 1 : System.out.println("One player is playing this game."); break; case 2 : System.out.println("Two players are playing this game."); break; case 3 : System.out.println("Three players are playing this game."); break; default: System.out.println("You did not enter a valid value."); }
  • 42. C and Java Comparison item C Java Structure Structured language Object oriented language Memory address pointer reference Pointers &, *, -> No pointers Allocating memory malloc() new()De-allocating memory free() Automatic garbage collection Statement Goto statement No goto statementVariable declarations At the beginning of a Before you use it method or blockMethod overloading None Yes Method pointers Yes None Preprocessor Yes None

×