About the Author
Paul Deitel, CEO, CTO, and cofounder of Deitel® & Associates, Inc., is coauthor of many of the world’s leading programming books, including the best-selling college textbook Java How to Program, Seventh Edition (Prentice Hall, 2007). Through Deitel® & Associates, Inc., he has delivered Java and other programming language courses to developers at dozens of the world’s leading organizations, including IBM, Sun Microsystems, Cisco, Fidelity, NASA, and many more.
Excerpt. © Reprinted by permission. All rights reserved.
Welcome to the Java Fundamentals LiveLessons. This two-part sequence presents object-oriented programming in Java using Java Standard Edition (Java SE) 6. After studying the fundamental topics presented here, you’ll have the foundation you need to learn more about Java programming on the Java Micro Edition (Java ME), Java Standard Edition (Java SE) and Java Enterprise Edition (Java EE) platforms.
What You Will Learn
- Features of Java Standard Edition (Java SE) 6.
- To build, compile and run applications with the Java Development Kit (JDK), as well as the popular Eclipse and Netbeans integrated development environments (IDEs).
- How the Java virtual machine (JVM) makes Java applications portable.
- To use the classes and interfaces in the Java Applications Programming Interface (API) and to use the Java online documentation to locate the features you need in the Java API.
- To use formatted input and output capabilities.
- Arithmetic, increment, decrement, assignment, relational, equality and logical operators.
- Control statements.
- Primitive types and their corresponding Java API classes.
- Methods, method overloading and methods with variable-length argument lists.
- Arrays and strings, and how they are manipulated as Java objects.
- Object-oriented programming concepts including classes, objects, encapsulation, interfaces, inheritance, polymorphism, abstract classes and abstract methods.
- To use and create your own static methods and static variables.
- To package your own classes to create reusable class libraries.
- The fundamentals of event-driven graphical user interface (GUI) programming and Swing GUI components including windows, buttons, labels, comboboxes, text fields and panels.
- To use exception handling to make your programs more robust.
- The classes, interfaces and algorithms of the Java Collections Framework (Java’s data structures and algorithms for manipulating them).
Who Should Use These LiveLessons?
The Java Fundamentals LiveLessons are intended for students and professionals who are already familiar with programming fundamentals in a high-level programming language such as C, C++, C# or Visual Basic. Object-oriented programming experience is not required—this is a key focus of these LiveLessons. Java Fundamentals: Part 1 introduces object-oriented programming fundamentals in Java. Java Fundamentals: Part 2 continues with in-depth discussions of object-oriented programming and introduces GUIs, exception handling and the JavaCollections Framework.
In the Java Fundamentals LiveLessons, author Paul Deitel concentrates on the principles of good software engineering and stresses program clarity, teaching by example. Paul is a professional trainer who presents leading-edge courses to government, industry, the military and academia.
Live-Code Approach. These LiveLessons are loaded with “live-code” examples—that is, each new concept is presented in the context of a complete working Java application. In addition to discussing the new concepts in each application, I execute the application so you can see the concepts “in action.” This style exemplifies the way we teach and write about programming at Deitel & Associates; we call this the “live-code” approach.
Object-Oriented Throughout. After learning some Java fundamentals in Lesson 1 of Java Fundamentals: Part 1, you’ll create your first customized classes and objects in Lesson 2. Presenting objects and classes early gets you “thinking about objects” immediately and mastering these concepts more thoroughly. We then use these concepts throughout both LiveLessons.
Online Documentation. Throughout both LiveLessons we show you how to use Java’s online documentation. This will help you avoid “reinventing the wheel” by locating features that are already defined in the Java API and that you need in your applications. It will also help you learn the relationships among many key classes and interfaces in the Java API. Learning these relationships is essential to taking full advantage of the Java API’s capabilities.
How These LiveLessons Are Organized
These LiveLessons are based on portions of Paul’s best-selling computer science textbook and professional book Java How to Program, 7/e (www.deitel.com/books/jhtp7/) and his Dive-Into® Series corporate training courses (www.deitel.com/training/), which he presents to organizations worldwide. Feel free to email Paul at firstname.lastname@example.org.
Java Fundamentals: Part 1 (40 examples)
- Lesson 1, Introduction to Java Applications, introduces Java application programming. You’ll learn formatted input and output capabilities, and how to compile and run Java applications using an IDE and using the JDK command-line tools. You’ll also begin using the packages of reusable classes in the Java class libraries.
- Lesson 2, Introduction to Classes and Objects, introduces object-oriented programming principles and constructs, and begins our case study on developing a GradeBook class that instructors can use to maintain student test scores. This case study is enhanced over the next several lessons, culminating with the versions presented in Lesson 6, Arrays. The last example in this lesson uses a bank account class to introduce data validation concepts. In this lesson, you’ll learn what classes, objects, methods and instance variables are; how to declare a class and use it to create an object; how to declare methods in a class to implement the class’s behaviors; how to declare instance variables in a class to implement the class’s attributes; how to call an object’s methods to make them perform their tasks; the differences between instance variables of a class and local variables of a method; to use a constructor to ensure that an object’s data is initialized when the object is created; and the differences between primitive and reference types.
- Lesson 3, Control Statements: Part 1, continues enhancing the GradeBook case study with additional functionality. You’ll learn Java’s if, if...else and while control statements, and the increment and decrement operators.
- Lesson 4, Control Statements: Part 2, introduces Java’s for and do...while repetition statements, and the switch multiple-selection statement. A portion of this lesson expands the GradeBook class presented in Lessons 2-3 by using a switch statement to count the number of A, B, C, D, and F grade equivalents in a set of numeric grades entered by the user.
- Lesson 5, Methods: A Deeper Look, discusses other details of method definitions. You’ll also learn about static methods and fields of a class; Java’s eight primitive types and the implicit type promotion rules between them; some common packages in Java; random number generation; how to create and use named constants; the scope of identifiers; and what method overloading is and how to create overloaded methods.
- Lesson 6, Arrays, introduces Java’s implementation arrays. You’ll learn how to declare, initialize and manipulate arrays; to iterate through arrays with the enhanced for statement; to pass arrays to methods; to declare and manipulate multidimensional arrays; to create methods with variable-length argument lists; and to read a program’s command-line arguments. We’ll also enhance the GradeBook case study using arrays to maintain a set of grades in memory and analyze student grades from multiple exams in a semester.
- Lesson 7, Classes and Objects: A Deeper Look, takes a deeper look at building classes, controlling access to class members and creating constructors. The examples teach encapsulation and data hiding; composition; how to use keyword this to refer to an object’s members; how to create static variables and methods; how to import static class members; how to use the enum type to create sets of named constants that can be initialized with arguments; and how to organize classes into your own packages for reusability.
Java Fundamentals: Part 2 (29 examples)
- Lesson 1, Object-Oriented Programming: Inheritance, discusses the object-oriented programming (OOP) concept of inheritance—a form of software reuse in which a new class absorbs an existing class’s members and embellishes them with new or modified capabilities. You’ll learn how inheritance promotes software reusability; the notions of superclasses and subclasses; to use keyword extends to create a class that inherits from another class; to use access modifier protected to give subclass methods access to superclass members; to access superclass members with keyword