1 / 45

برنامه نویسی پیشرفته

برنامه نویسی پیشرفته. مدرس: مهدی عمادی. مقدمه. Java یک زبان برنامه نویسی مستقل از سکوی اجرا است در سال 1991 توسط شرکت Sun Microsystems پیشنهاد شد C یک زبان برنامه نویسی با امکانات مناسب برای دسترسی به سطوح پایین سیستمها و مدیریت مستقیم سخت افزار

chulbert
Download Presentation

برنامه نویسی پیشرفته

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. برنامه نویسی پیشرفته مدرس: مهدی عمادی

  2. مقدمه • Java یک زبان برنامه نویسی مستقل از سکوی اجرا است • در سال 1991 توسط شرکت Sun Microsystems پیشنهاد شد • C یک زبان برنامه نویسی با امکانات مناسب برای دسترسی به سطوح پایین سیستمها و مدیریت مستقیم سخت افزار • Java زبانی مناسب برای برنامه های بزرگ و پیچیده به خصوص تحت شبکه و اینترنت

  3. کتاب برنامه نویسی • JAVA how to program, Seventh Edition, Deitel & Deitel, 2007 • Code Complete, Second Edition, Steve McConnell, Microsoft Press, 2004.

  4. استفاده به عنوان: • کلاینت برنامه های وب (Applet) 5 درصد • برنامه عادی (Desktop Application) 45 درصد • سرور (servlets/JSP/EJB) 50 درصد

  5. Java • Source Code Java Bytecode JIT Compiler or Interpreter Compiler (javac) Execution Java Bytecode Java is Cross-Platform? • برنامه java در یک کامپیوتر با داشتن یک کامپایلر تولید می شود • بایت کد تولید شده یک فایل است که با انتقال به هر سخت افزار و هر سیستم عاملی که ماشین مجازی جاوا را دارد اجرا خواهد بود Compile Time زمان کامپایل Run Time زمان اجرا

  6. Instructions in Assembly and Machine Language

  7. High-Level Assembly-Machine Code

  8. Evolution of Programming Languages • High-level languagesmake programming easier • Closer to spoken languages • Examples • Basic • FORTRAN • COBOL • C/C++ • Java

  9. Object-Oriented Programming • برنامه نویسی شی گرا یک ایده کامل برای پیاده سازی برنامه های کامپیوتری است • جاوا یک زبان کامل برای ایده برنامه نویسی شی گرا می باشد

  10. Java is Simple? • Truth: Java greatly simplifies several language features • Java has automatic memory management • Does Windows and takes out the garbage • No dangling pointers. No memory leaks. • A problem for real-time programs • Java simplifies pointer handling • No explicit reference/dereference operations • Everything is a pointer (like Lisp) • No makefiles • No header files • C++ syntax streamlined

  11. Java is Powerful? • Myth: Java will increase programmer productivity for all applications by XXX%. • Myth: Java will kill C++ • Myth: All software should be written in Java • Unix utilities: C • Small/medium Windows-only programs: Visual Basic • String parsing: Perl • High-performance, single-platform OO systems: C++ • Air traffic control, aircraft flight software: Ada • Knowledge-based systems: Lisp/CLOS/Prolog

  12. Basic Hello World Application • “Application” is Java lingo for a stand-alone Java program • Note that the class name and the filename must match • A file can contain multiple classes, but only one can be declared public, and that one’s name must match the filename • File HelloWorld.java: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, world."); } }

  13. Basic Hello World Application (Continued) • Compiling: javac HelloWorld.java • Running: java HelloWorld • Output: Hello, world.

  14. Command Line Arguments • File ShowArgs.java: public class ShowArgs { public static void main(String[] args) { for(int i=0; i<args.length; i++) { System.out.println("Arg " + i + " is " + args[i]); } } }

  15. Command Line Arguments, Results • Compiling and Running: > javac ShowArgs.java > java ShowArgs fee fie foe fum Arg 0 is fee Arg 1 is fie Arg 2 is foe Arg 3 is fum

  16. Basic Hello WWW Applet • File HelloWWW.java: import java.applet.Applet; import java.awt.*; public class HelloWWW extends Applet { public void init() { setBackground(Color.gray); setForeground(Color.white); setFont(new Font("SansSerif", Font.BOLD, 30)); } public void paint(Graphics g) { g.drawString("Hello, World Wide Web.", 5, 35); //5=left, 35=bottom } }

  17. Basic Hello WWW Applet (Continued) • File HelloWWW.html: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>HelloWWW: Simple Applet Test.</TITLE> </HEAD> <BODY> <H1>HelloWWW: Simple Applet Test.</H1> <APPLET CODE="HelloWWW.class" WIDTH=400 HEIGHT=40> <B>Error! You must use a Java enabled browser.</B> </APPLET> </BODY> </HTML>

  18. Basic Hello WWW Applet (Continued) • Compiling: javac HelloWWW.java • Running: Load HelloWWW.html in a Java-enabled browser

  19. Customizing Applets with PARAM import java.applet.Applet; import java.awt.*; public class Message extends Applet { private int fontSize; private String message; public void init() { setBackground(Color.black); setForeground(Color.white); fontSize = getSize().height - 10; setFont(new Font("SansSerif", Font.BOLD, fontSize)); // Read heading message from PARAM entry in HTML. message = getParameter("MESSAGE"); } public void paint(Graphics g) { if (message != null) g.drawString(message, 5, fontSize+5); } }

  20. Customizing Applets with PARAM, cont. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE>The Message Applet</TITLE> </HEAD> <BODY BGCOLOR="WHITE"> <H1>The <CODE>Message</CODE> Applet</H1> <P> <APPLET CODE="Message.class" WIDTH=325 HEIGHT=25> <PARAM NAME="MESSAGE" VALUE="Tiny"> <B>Sorry, these examples require Java</B> </APPLET> <P> <APPLET CODE="Message.class" WIDTH=325 HEIGHT=50> <PARAM NAME="MESSAGE" VALUE="Small"> <B>Sorry, these examples require Java</B> </APPLET> ... </BODY> </HTML>

  21. Customizing Applets with PARAM, Result

  22. Requirements for the Course • Browse-to-download: Java SE JDK 6 latest update for Windows Platform http://java.sun.com/ make sure to Accept License Agreement • Install JDK (use defaults) • Browse-to-and-download: NetBeans IDE 6.5 IDE with Java SE update ? Bundle http://www.netbeans.org/make sure to Accept License Agreement • install NetBeans (use defaults) • IntelliJ IDEA 6.0 • Eclipse - IBM Rational Developer - Jdeveloper - Jbuilder - etc. • NOTEPAD !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  23. Evolution of Programming Languages • Compiler: a program that translates a program written in a high-level language into the equivalent machine language • In the case of Java, this machine language is the bytecode • Java Virtual Machine (JVM): hypothetical computer developed to make Java programs machine independent

  24. Problem-Analysis-Coding-Execution Cycle

  25. First Cup of Java • A Step by step example on how to • Create • Compile • Run a java program • Plus the works • What is a Programming Language • What is Object Orientation

  26. First Java Program • Does and Don'ts • Java Environment • A Simple Program that Displays Hello World • Create the Program • Compile the Program • Load and Run the Program

  27. First Java Program The Do not(s) • Do Not Use the Desktop or “My Documents” as a folder for your java programs • Always Use the Letter Drive as your Root (A, C, D, etc.) • Java Does not Like Spaces in File Names or Folder Names Java is case Sensitive • the string hello.Java is not the same as Hello.java

  28. First Java Program Start a DOS Commands windowStart  Run  cmd

  29. First Java ProgramCommand Prompt Window

  30. First Java ProgramCreate the Appropriate folders

  31. Which Java Environment are you runningjavacis not recoginzed: it is not in my path

  32. Search your drive for the latest JDKHardwire the path to point to the bin folder

  33. Hardwire the path to point to the bin folder

  34. java and javac are both recognizable

  35. Where is my First Java ProgramRemember: java is case sensetive

  36. Where is my First Java Programedit and save to the Homeworks folder

  37. Where is my First Java ProgramUse the dir command: 228 Bytes

  38. My First Java ProgramComments • Java is case sensitive • File name extension is .java (Lower case) • Class Name in publicclassHelloWorldShould exactly match the first part of the filename HelloWorld.java • A runnable Java Program is a Java class with a method called:public static void main(String[] args){//Control Flow Code}

  39. Compiling My First Java Programjavac Helloworld.javaHelloworld.class is created

  40. Compiling My First Java ProgramWhere did HelloWorld.class come from

  41. Running My First Java Programjava Helloworld

  42. Try thisHelloWorld.java programCreate, compile and run // // My First Java Program //our Info // // import javax.swing.*; public class HelloWorld{ public static void main(String[] args){ try{ String s = JOptionPane.showInputDialog("Please Enter your Name"); System.out.println("Hello " + s); System.out.print(" Welcome to CIS at WTAMU"); } catch(Exception e){ } } }

  43. Summary

  44. My J2SE Environment Install Environment

  45. Java 2 Standard Edition Components http://java.sun.com/javase/6/docs/

More Related