1 / 50

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

برنامه نویسی پیشرفته. معرفی محیط برنامه نویسی eclipse. فهرست. نیازهای Eclipse نصب Eclipse ایجاد فضای کاری و پروژه ایجاد کلاسها کامپایل و اجرای برنامه خطایابی کد نمونه ای از قابلیتها خلاصه. Eclipse چیست؟. کد باز پشتیبانی از (plug-in) های دیگران محیط برنامه نویسی مجتمع

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

  2. فهرست • نیازهای Eclipse • نصب Eclipse • ایجاد فضای کاری و پروژه • ایجاد کلاسها • کامپایل و اجرای برنامه • خطایابی کد • نمونه ای از قابلیتها • خلاصه

  3. Eclipse چیست؟ • کد باز • پشتیبانی از (plug-in) های دیگران • محیط برنامه نویسی مجتمع • شامل ابزارهای کد نویسی، کامپایل، اجرا و خطایابی • پشتیبانی از زبانهای متعدد • پشتسبانی خوب از C, C++ • Python, PHP, Ruby, etc…

  4. پیش نیازهای اجرای eclipse • Eclipse به زبان جاوا نوشته شده است وبه JRE یاJDK برای اجرا نیاز دارد. • JDKتوصیه می شود.

  5. دانلود و نصب Eclipse • Eclipse را می توان از سایت زیر دانلود کرد: • http://www.eclipse.org/downloads/packages/ • نسخه ی “Eclipse IDE for Java Developers” را دانلود کنید. • فایل زیپ دانلود شده را در C:\eclipse\استخراج کنید. • برای اجرا، روی فایل C:\eclipse\eclipse.exeکلیک کنید. • شما باید چیزی شبیه شکل زیر مشاهده کنید:

  6. انتخاب فضای کار • در Eclipse همه ی کدها در فضای کار ذخیره می شوند. • می توان چندین فضای کار داشت. • فضای کار مناسب را انتخاب کرده و دکمه ok را بزنید.

  7. اجزای Eclipse Perspective Switcher We can switch between various perspectives here Menubars Full drop down menus plus quick access to common functions Task List Pane This contains a list of “tasks” to complete Editor Pane This is where we edit our source code Package Explorer Pane This is where our projects/files are listed Outline Pane This contains a hierarchical view of a source file Miscellaneous Pane Various components can appear in this pane – typically this contains a console and a list of compiler problems

  8. ایجاد یک پروژه ی جدید • تمام کدهای Eclipse به یک پروژه نیاز دارند. • برای ایجاد یک پروژه: File  New  Java Project

  9. ایجاد پروژه ی جدید (ادامه ) • اسم پروژه را تایپ و روی Finish کلیک کنید.

  10. ایجاد پروژه ی جدید (ادامه ) • اسم پروژه ی جدید در محل مرورگر بسته های نرم افزاری ظاهر خواهد شد.

  11. دایرکتوری src • Eclipse بصورت خودکار یک دایرکتوری به اسم src برای نگهداری کدهای پروژه ایجاد می کند.

  12. ایجاد کلاس • برای ایجاد کلاس، روی دکمه ی new کلیک کرده و class را انتخاب کنید.

  13. ایجاد کلاس (ادامه) • اینکار باعث ظاهر شدن پنجره ی روبرو می شود. • اطلاعات لازم را وارد کرده و روی دکمه ی Finish کلیک کنید.

  14. کلاس ایجاد شده • همانطور که می بینید اتفاقاتی رخ داده است: Directory structure for package and actual java file created automatically Source is loaded into the editor pane, already stubbed out Source displayed in a hierarchical fashion listing each method name

  15. کامپایل کد • یکی از خواص جالب eclipse کامپایل همزمان کد در هنگام کدنویسی است. Position in file is marked with a red line – 1 click allows you to jump to line with error Packages/Classes with errors are marked with a red X Error underlined with red squiggly line (just like spelling errors in many word processors) Often Eclipse may have suggestions on how to fix the problem – if so, a small light bulb will be displayed next to the line of offending code Methods with errors are marked with a red X The Problems tab will contain a tabular representation of all errors across all files of all open projects

  16. مثالی از خطای کامپایل • اگر روی لامپ کلیک کنیم، eclipse پیشنهاد می دهد کهprintn را به printیا println تغییر دهیم.

  17. اجرای کد • روی class کلیک راست کرده و Run As  Java Applicationرا انتخاب کنید.

  18. اجرای کد (ادامه) • نتیجه ی اجرای کد در محل نشان داده شده ظاهر خواهد شد.

  19. پیکر بندی اجرا • برای اجرای گزینه های پیشرفته، روی class کلیک راست کرده و Run As  Run… را انتخاب کنید.

  20. اجرای کد (ادامه) • در این حالت می توانید موارد زیر را تغییر دهید: : • آرگومانهای JVM • آرگومانهای خط فرمان • تنظیمات Classpath • متغییرهای محیطی • JVM مورد استفاده

  21. اجرای دوباره ی کد • برای اجرای دوباره ی کد در محل نشان داده شده کلیک کنید.

  22. خطایابی (دیباگ) کد • eclipse یک دیباگر خیلی خوب دارد. می توان نقاط توقف اجرای کد را با کلیک روی حاشیه ی سمت چپ ایجاد کرد. نقاط توقف با رنگ آبی نشان داده می شوند.

  23. خطا یابی • یک راه ساده برای ورود به مد خطایابی کلیک راست روی کلاس و انتخاب گزینه ی Debug As  Java Application است.

  24. خطایابی • اولین باری که سعی کنید کد را دیباگ کنید با پنجره ی زیر مواجه می شوید. • Eclipse از شما می پرسد که آیا می خواهید یک منظر مناسب تر برای خطایابی را انتخاب کنید. بله را انتخاب کنید. • Eclipse چندین منظر دارد و منظر پیش فرض منظر جاوا است.

  25. Debug Perspective Note new Debug perspective – click Java to return to normal These buttons allow you to step through the code Variables in scope are listed here along with their current values (by right clicking you can change values of variables as you program is running) List of breakpoints This pane shows the current line of code we broke on Current high level location (class and method) Output console, just like in normal run mode

  26. Sampling of Some Other Features • Import organization • Context assist • Javadoc assist • Getter/Setter generation • Add unimplemented methods • Exception handling • Reminders • Local history

  27. Import Organization • Eclipse can automatically include import statements for any classes you are using, just press Control + Shift + o (letter o)

  28. Import Organization (continued) • If the class is ambiguous (more than one in the API) then it will ask you to select the correct one

  29. Import Organization (continued) • Import statements automatically included and organized • You can organize imports to clean them up at any time

  30. Context Assist • If you are typing and press a “.” character and pause a second, Eclipse will show you a list of all available methods for the class • Prevents having to browse javadocs to see what methods are available • Get context assist at any time by pressing Control + Space

  31. Javadoc Assist • Eclipse can also help generate javadoc comments for you, simply place the cursor before the method and then type “/**” then Enter

  32. Javadoc Assist (continued) • Eclipse will automatically generate a javadoc header for the method all stubbed out with the parameters, return type and exceptions

  33. Getter/Setter Generation • Eclipse can automatically generate getters and setters for member of a class…

  34. Getter/Setter Generation (continued) • To generate getters and setters, right click in the main pane, then select Source  Generate Getters and Setters

  35. Getter/Setter Generation (continued) • Here you can selectively choose members for which to generate getters and setters

  36. Getter/Setter Generation (continued) • Eclipse will then automatically generate the code for the getters and setters

  37. Add Unimplemented Methods • Eclipse can also stub out methods that need to be present as a result of implementing an interface…

  38. Add Unimplemented Methods (continued) • You can use the quick fix light bulb to add the interfaces unimplemented methods to the class

  39. Add Unimplemented Methods (continued) • Again Eclipse will go ahead and stub out the method for us

  40. Exception Handling • Eclipse will also pickup on unhandled exceptions

  41. Exception Handling (continued) • By clicking on the quick fix light bulb, Eclipse can suggest what to do to handle the exception

  42. Exception Handling (continued) • Eclipse can automatically add a “throws declaration” to the method signature

  43. Exception Handling (continued) • Alternately, Eclipse can also wrap the code inside a try/catch block

  44. Tasks • Eclipse allows you to insert reminders into your code and stores them for you to come back and revisit them • Eclipse recognizes the following tags inside comments… • TODO • FIXME • XXX • You can even add your own custom tasks through the preferences menu

  45. Tasks (continued) • To add a table of all reminders in all of your source code you can add the Tasks view by clicking on Window  Show View  Tasks

  46. Tasks (continued) • This neatly displays all tasks in a tabular form

  47. Local History • Eclipse maintains a local history of file revisions which can be accessed by right clicking on the class, then selecting Compare With  Local History…

  48. Local History (continued) • Previous saved revisions are displayed in the History pane, double click a revision to view in the built-in diff viewer

  49. Benefits Code completion Faster code/compile/run cycles (real time) Open source (free) Extensible (plugins) Disadvantages Pretty heavyweight Requires JRE Learning Curve Summary

  50. محتوی درس • آشنایی با برنامه نویسی شی گرا (OOP) و طراحی شی گرا (OOD) • آشنایی با زبان جاوا • آشنایی با محیط برنامه نویسی Eclipse • تاکید بر برنامه نویسی صحیح • وب سایت درس: www.ilam.ac.ir/staffs/mozafar/jv

More Related