Object Oriented Programming (Java) PDF
Document Details
FEU Alabang, FEU Diliman, FEU Tech
2018
Tags
Summary
This document is a presentation about object-oriented programming in Java, covering topics like history, features, different Java versions, the JVM, NetBeans IDE installation, and quick start guide for creating Java programs. It was created in 2018, for an undergraduate course.
Full Transcript
Object Oriented Programming (Java) Module 1 Introduction to Java Technology Remember the History of Java Technology Understand the different features that Java offers Remember the different Java Editions Understand the use of JVM and J2SDK in creating Java applicat...
Object Oriented Programming (Java) Module 1 Introduction to Java Technology Remember the History of Java Technology Understand the different features that Java offers Remember the different Java Editions Understand the use of JVM and J2SDK in creating Java applications Know the History and features of Netbeans IDE Understand how to navigate through the Netbeans IDE History and Features of Java 1.1 Object Oriented Programming Java language, originally called the ‘Oak’, was developed by James Gosling at Sun Microsystems, which is now a subsidiary of Oracle Corporation, and released in 1995 as a core component of Sun Microsystems' Java platform. It has derived much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Introduction to Java Technology Java is a general-purpose, concurrent, class-based, object- oriented language that is specifically designed to have as few implementation dependencies as possible. The Java source code files (files with.java extension) are compiled into a format called bytecode (files with.class extension), which can be executed by a Java interpreter. Introduction to Java Technology It was intended for use in Sun’s project research to work on a programming software to control electronic devices. It was modified to take advantage of the World Wide Web. The WebRunner, later named as HotJava, was the very first web browser created in Java. In 1995, the Netscape Navigator internet browser was also developed to support Java. Introduction to Java Technology 1. Simple, object-oriented, and familiar 2. Robust and secure 3. Architecture neutral and portable 4. High performance 5. Interpreted, threaded, and dynamic Introduction to Java Technology Java Program class HelloWorld{ Compiler public static void main(String args[ ]){ System.out.println(“Hello World”); } } Interpreter Interpreter HelloWorld.java Interpreter Hello World Hello World Hello World Win32 MacOS Solaris Introduction to Java Technology Java Editions: J2SE: Java 2 Standard Edition J2EE: Java 2 Enterprise Edition J2ME: Java 2 Micro Edition Introduction to Java Technology The Java Virtual Machine (JVM) Java is a portable language that could run on any platform. The language was able to do this by generating intermediate code for a hypothetical computer called a virtual machine. Introduction to Java Technology The Java Virtual Machine (JVM) The Java Virtual Machine (JVM) is a program that runs on all computers. The JVM creates a software simulation of a CPU and memory and handles all communication between the Java program and the underlying operating system and hardware. Introduction to Java Technology myProgram.java _________________ Interpreter _____________ _______________ My Program myProgram.class Compiler _________________ _____________ _______________ The Java source code (.java file) is normally compiled to produce the bytecode file (.class file) which is normally interpreted by the Java virtual machine (JVM). Introduction to Java Technology The JVM and Application Architecture source code “javac” byte code Introduction to Java Technology The JVM and Application Architecture byte code Java Virtual Machine machine code Introduction to Java Technology How JVM Works JVM for Windows OS Windows Byte code.class File (Java Application) “Write once, run anywhere JVM for Linux OS technology.” Linux Introduction to Java Technology The J2SDK (JDK) Java 2 Software Development Kit contains java – the loader for Java applications javac – the compiler javadoc – the documentation generator other tools Introduction to Java Technology Steps in Creating a Java Application 1. Create the source code. 2. Compile the source code. 3. Run the program. Introduction to Java Technology Steps 1 : Creating the source code Create the source code using any text editor. Save the file with a “.java” extension. Example: HelloJava.java Introduction to Java Technology Steps 2 : Compiling the source code Compile the source code to create the byte code using javac tool from the J2SDK. Open an MS-DOS console, browse for the directory where you saved the source code. Introduction to Java Technology Steps 2 : Compiling the source code Type the command javac HelloJava.java and press ENTER. Verify that the HelloJava.class has been created. Introduction to Java Technology Steps 3 : Running the Program To execute the program, type the command: java HelloJava and press ENTER. Introduction to Java Technology Exploring Netbeans IDE 1.2 Introduction to Java Technology Introduction to IDE An Integrated Development Environment is a computer software to help computer programmers develop software. The Leaders: - NetBeans - Microsoft Visual Studio - Eclipse Introduction to Java Technology Introduction to IDE What does an IDE consist of: - Source code Editor. - Compiler and/or interpreter. - Build- automation tools. Optional Tools: - Debugger. - Version control system. - Various tools to simplify the construction of a GUI. Introduction to Java Technology Introduction to IDE Tools For Object Oriented Design: - Object inspector. - Class Browser. - Class hierarchy diagram. Introduction to Java Technology Why Do We Need An IDE? IDE abstracts the configuration necessary to piece together various utilities in one unit, which could ease the learning of a language, and increases developer productivity. Most IDEs today have GUI modeling utilities that simplify the development of UIs, which is critical for commercial software today. Introduction to Java Technology The History Of NetBeans It all started as a student project called Xelfi The Goal was to write a Delphi- like Java IDE in Java for the first time. The original plan was to develop network-enabled JavaBeans components, hens the name. but coming out of the spec for enterprise changed the plans. Sun decided it needs a more powerful Java development tool, and the rest is history. Introduction to Java Technology About NetBeans A fast fully-featured Integrated Development Environment (IDE) with support for Java. Compliant applications for accelerating development across all major OS platforms. Provides an open source, high performance, modular, extensible, multi-platform Java IDE for GUI, mobile tools, Web, and Desktop applications. Written in java and therefore runs on every operating system that supports Java VM. Introduction to Java Technology NetBeans Features Environment: easily configured user interface and a modular architecture extensible with additional plugins. Project System: support for multiple source roots, easy management of libraries, easily ported to other environments, all based on Apache Ant. Web Development: Web Application project type, Supports the J2EE 1.3 and 1.4 standards with web application build support based on Apache Ant. Introduction to Java Technology NetBeans Features Enterprise Java Beans (EJB) Development: easy to create and deploy and import java beans. Web Services Development: wizards for creating web services and web services clients, providing the basic (java/wsdl) code needed, and easy to use testing tools of existing web services. Java 2 Platform, Micro Edition (J2ME) MIDP development: visual design editor with end-to-end support for enterprise applications. Introduction to Java Technology NetBeans Features Code Editor: Syntax highlighting for Java, XML, HTML, CSS, JSP and IDL, full support of new JDK 1.5 features, live parsing/error marking, popup javadoc, code completion, and fast class importing. Refactoring: renaming, changing and moving of various objects, field encapsulation and usage finding. Award Winning Debugger: Language independent debugger core, variable modification and watches, various breakpoints and “Fix and Continue” mechanism. Introduction to Java Technology NetBeans Features GUI Builder: fully WYSIWYG designer with "Test Form" feature, extensible Component Palette pre-installed Swing and AWT components, showing a components tree and properties, automatic code generation and full JavaBeans support. Version control Support: supports command lined vcs, supplying merging and diff tools and containing a built- in CVS client. XML: XML, DTD and CSS Text Editor and XML Productivity Tools Wizards to help user generate codes. Introduction to Java Technology NetBeans Extras NetBeans Profiler: provides information about the runtime behavior of applications. Allows developers to monitor the thread state, CPU performance, and memory usage of their applications. makes it easy to track down performance problems and memory leaks. NetBeans Platform: provides the services common to almost all large desktop applications such as: window, menu, settings management and storage, file access and more. Introduction to Java Technology NetBeans Extras NetBeans Mobility Pack: used to write, test, and debug applications for the Java Micro Edition platform (J2ME) technology-enabled mobile devices. It integrates support for the Mobile Information Device Profile (MIDP) 2.0, the Connected, Limited Device Configuration (CLDC) 1.1. The mobility pack allows for the unique “On-Phone” debugging mode. Introduction to Java Technology NetBeans Matisse The biggest improvement from the previous version and the feature with the biggest impact is the new GUI- Builder, Matisse. Introduction to Java Technology NetBeans Matisse The Goal: to take the best features from OSX and VS designers and allow the same possibilities for Java Programmers. In order to reach that goal there was a need to develop a new layout manager to support all the needed functionalities. Introduction to Java Technology NetBeans Matisse Matisse provides a simple and intuitive layout of GUIs without having to understand the complexities of Swing layout managers. As you drag and drop components into a form, the IDE automatically suggests alignment, spacing, and resizing constraints. By simply right clicking a UI Object you can add an event handler with a method waiting to be implemented without knowing too much about the surrounding of this object. (watch example clip in the site) Introduction to Java Technology NetBeans Matisse - Advantages For the first time, there’s an intelligent way to build GUI for Java (unlike eclipse), that can actually compete with the Visual Studio Gui builder. Supports internationalization, and industrial look-and-feel rules, which is very important for large scale application meant to be spread world wide. Builds also GUI web applications, HTML, JSP, etc Introduction to Java Technology NetBeans Matisse - Disadvantages No built-in support for Drag-n-Drop or double-click events. Matisse’s code is protected so customizing is not very easy and not always possible. Not all applications are easily built. For instance, an MDI Project is not that trivial to build Introduction to Java Technology How To Get Started? How to install A Quick start Guide Importing existing applications Advanced Introduction to Java Technology Installation Installing JDK: in order to install NetBeans you need to first install JDK. You can easily find an installation in Sun’s web site. NetBeans installation: you can find the installations kits for all the versions in the NetBeans home page. Installation steps: you can watch a movie describing the installation step by step in the. Introduction to Java Technology Quick Start Guide 1. Starting up a project 2. Creating and editing java source code 3. Compiling and running a project 4. Testing and debugging a project Introduction to Java Technology Starting Up A Project Creating a new project: in the file menu choose “new project” and look at the possibilities. Introduction to Java Technology Starting Up A Project When creating a new project, NetBeans already includes all the needed packages for compiling and testing. It also outlines the sources by the right logical directories and creates the files that are mandatory. For instance, if you create a new java application you must implement a main class and so it’s automatically created. Introduction to Java Technology Editing and Refactoring When editing a code you can see the difference between the old version and the new version when using the Code Completion tool. You can use “Find Usage” tool when working on a project to predict the changes you will need to make. You can use refactoring to easily change places of things without going through all the code to change it. Introduction to Java Technology Building and Running No makefile or manual creation of an Ant file needed (by default). A simple instruction saying which class to run and what to build will suffice. Netbeans will create the Ant file automatically. While Building you can also generate the javadoc very easily. Introduction to Java Technology Testing JUnit Tests: you simply choose the class you want to test and in the tools menu choose “create JUnit Test”. After filling the arguments NetBeans automatically creates a test class inheriting from TestCase with the default methods to implement and puts everything under the Test package. Introduction to Java Technology Debugging NetBeans has two modes, run mode and debug mode. The debug mode is very easy to use. You can use the local variables window and watch window to follow the progress of the program. Introduction to Java Technology NetBeans IDE Java Quick Start Tutorial Contents: üSetting Up the Project üAdding Code to the Generated Source File üCompiling and Running the Application Required Software/Resource: üNetBeans IDE version 7.2, 7.3, 7.4, or 8.0 üJava Development Kit (JDK)version 6, 7, or 8 Introduction to Java Technology Setting Up Your First Project To create an IDE project: 1. Start NetBeans IDE. 2. In the IDE, choose File > New Project, as shown in the figure below. Introduction to Java Technology Setting Up Your First Project 3. In the New Project wizard, expand the Java category and select Java Application as shown in the figure below. Then click Next. Introduction to Java Technology Setting Up Your First Project 4. In the Name and Location page of the wizard, do the following: üIn theProject Name field, type HelloWorldApp. üLeave the Use Dedicated Folder for Storing Libraries checkbox unselected. üIn the Create Main Class field, type helloworldapp.HelloWorldApp. Introduction to Java Technology Setting Up Your First Project 5. Click Finish. üThe project is created and opened in the IDE. You should see the following components: üThe Projects window, which contains a tree view of the components of the project, including source files, libraries that your code depends on, and so on. üThe Source Editor window with a file called HelloWorldApp open. üThe Navigator window, which you can use to quickly navigate between elements within the selected class. Introduction to Java Technology Setting Up Your First Project Introduction to Java Technology Adding Code to the Generated Source File Because you have left the Create Main Class checkbox selected in the New Project wizard, the IDE has created a skeleton main class for you. You can add the "Hello World!" message to the skeleton code by replacing the line: Introduction to Java Technology Setting Up the Project Introduction to Java Technology Compiling and Running the Program üBecause of the IDE's Compile on Save feature, you do not have to manually compile your project in order to run it in the IDE. üWhen you save a Java source file, the IDE automatically compiles it. üThe Compile on Save feature can be turned off in the Project Properties window. üRight-click your project, select Properties. In the Properties window, choose the Compiling tab. üThe Compile on Save checkbox is right at the top. Introduction to Java Technology Compiling and Running the Program Note that in the Project Properties window you can configure numerous settings for your project: project libraries, packaging, building, running, etc. To run the program: Choose Run > Run Project. Press F6/Shift+F6. Click the run button from toolbar. Click the play button from output window. The next figure shows what you should now see. Introduction to Java Technology Compiling and Running the Program Introduction to Java Technology Backiel, A. (2015). Beginning Java Programming: The Object-oriented Approach. 1st Edition Fain, Y. (2015). Java programming 24-hour trainer. John Wiley and Sons:Indianapolis, IN Smith, J. (2015). Java programs to accompany Programming logic and design. Cengage Learning:Boston, MA Yener, M (2015). Professional Java EE Design Patterns. John Wiley & Sons, Inc. Gordon, S. (2017). Computer Graphics Programming in opengl with Java. Mercury Learning and Information Butler, A (2017). Java. s.n Lowe, D (2017). Java all-in-one for dummies. John Wiley and Sons Saumont, P (2017). Functional Programming in Java: How Functional Techniques Improve Your Java Programs. 1st Edition Heffelfinger, D. (2017). Java EE 8 Application Development. Packt Puublishing Murach, J. (2017). Murach’s Java Programming. Mike Murach & Associates,Inc. Burd, B. (2017). Beginning programming with Java for dummies. John Wiley & Sons, Inc. Manelli, L. (2017). Developing java web application in a day. s.n. Klausen, P. (2017). Java 5: Files and Java IO software development (e-book) Klausen, P. (2017). Java 3 object-oriented programming software development (e-book) Muller, M (2018). Practical JSF in Java EE 8. Apress