Schweitzer Fachinformationen
Wenn es um professionelles Wissen geht, ist Schweitzer Fachinformationen wegweisend. Kunden aus Recht und Beratung sowie Unternehmen, öffentliche Verwaltungen und Bibliotheken erhalten komplette Lösungen zum Beschaffen, Verwalten und Nutzen von digitalen und gedruckten Medien.
Doug Lowe is an accomplished technology writer of more than 30 books. He is a tech guru on all things computer programming. His expertise covers networking, Microsoft® Office, programming, and computer building. He is the author of the previous edition of Java All-in-One For Dummies.
Introduction 1
Book 1: Java Basics 5
Chapter 1: Welcome to Java 7
Chapter 2: Installing and Using Java Tools 17
Chapter 3: Working with TextPad 31
Book 2: Programming Basics 37
Chapter 1: Java Programming Basics 39
Chapter 2: Working with Variables and Data Types 59
Chapter 3: Working with Numbers and Expressions 97
Chapter 4: Making Choices 127
Chapter 5: Going Around in Circles (or, Using Loops) 149
Chapter 6: Pulling a Switcheroo 177
Chapter 7: Adding Some Methods to Your Madness 195
Chapter 8: Handling Exceptions 215
Book 3: Object-Oriented Programming 237
Chapter 1: Understanding Object-Oriented Programming 239
Chapter 2: Making Your Own Classes 253
Chapter 3: Working with Statics 273
Chapter 4: Using Subclasses and Inheritance 283
Chapter 5: Using Abstract Classes and Interfaces 305
Chapter 6: Using the Object and Class Classes 327
Chapter 7: Using Inner Classes and Anonymous Classes 355
Chapter 8: Working with Packages and the Java Module System 365
Book 4: Strings and Other Data Types 387
Chapter 1: Working with Strings 389
Chapter 2: Using Regular Expressions 411
Chapter 3: Working with Dates and Times 429
Chapter 4: Using the BigDecimal Class 451
Book 5: Data Structures 471
Chapter 1: Introducing Data Structures 473
Chapter 2: Using Arrays 503
Chapter 3: Using the ArrayList Class 535
Chapter 4: Using the LinkedList Class 549
Chapter 5: Creating Generic Collection Classes 561
Chapter 6: Using Maps and Trees 575
Book 6: Algorithms 595
Chapter 1: Introducing Algorithms 597
Chapter 2: Using Recursion 613
Chapter 3: Sorting 625
Chapter 4: Searching 637
Book 7: Programming Techniques 657
Chapter 1: Programming Threads 659
Chapter 2: Using Functional Programming and Lambda Expressions 689
Chapter 3: Consuming Web Services with HttpClient 705
Book 8: JavaFX 727
Chapter 1: Hello, JavaFX! 729
Chapter 2: Handling Events 751
Chapter 3: Setting the Stage and Scene Layout 769
Chapter 4: Using Layout Panes to Arrange Your Scenes 791
Chapter 5: Getting Input from the User 825
Chapter 6: Choosing from a List 841
Index 869
Chapter 1
IN THIS CHAPTER
Finding out about programming
Scoping out Java
Understanding Java's incomprehensible version numbers
This chapter is a gentle introduction to the world of Java. In the next few pages, you find out what Java is, where it came from, and where it's going. You also discover some of the unique strengths of Java, as well as some of its weaknesses. Also, you see how Java compares with other popular programming languages such as C, C++, and C#.
By the way, I assume in this chapter that you have at least enough background to know what computer programming is all about. That doesn't mean that I assume you're an expert or professional programmer. It just means that I don't take the time to explain such basics as what a computer program is, what a programming language is, and so on. If you have absolutely no programming experience, I suggest that you pick up a copy of Java For Dummies, 7th Edition, or Beginning Programming with Java For Dummies, 5th Edition, both by Barry Burd (Wiley).
Throughout this chapter, you find little snippets of Java program code, plus a few snippets of code written in other languages, including C, C++, and Basic. If you don't have a clue what this code means or does, don't panic. I just want to give you a feel for what Java programming looks like and how it compares with programming in other languages.
All the code listings used in this book are available for download at www.dummies.com/go/javaaiofd7e.
www.dummies.com/go/javaaiofd7e
Java is a programming language in the tradition of C and C++. As a result, if you have any experience with C or C++, you'll often find yourself in familiar territory as you discover the various features of Java. (For more information about the similarities and differences between Java and C or C++, see the section "Java versus Other Languages," later in this chapter.)
Java differs from other programming languages in a couple of significant ways, however. I point out the most important differences in the following sections.
One of the main reasons Java is so popular is its platform independence, which simply means that Java programs can be run on many types of computers.
Before Java, other programming languages promised platform independence by providing compatible compilers for different platforms. (A compiler is the program that translates programs written in a programming language into a form that can actually run on a computer.) The idea was that you could compile different versions of the programs for each platform. Unfortunately, this idea never really worked. The compilers were never identical on each platform; each had its own little nuances. As a result, you had to maintain a different version of your program for each platform you wanted to support.
Java's platform independence isn't based on providing compatible compilers for different platforms. Instead, Java is based on the concept of a virtual machine called the Java Virtual Machine (JVM). Think of the JVM as a hypothetical computer platform - a design for a computer that doesn't exist as actual hardware. Instead, the JVM simulates the operation of a hypothetical computer that is designed to run Java programs.
The Java compiler doesn't translate Java into the machine language of the computer that the program is running on. Instead, the compiler translates Java into the machine language of the JVM, which is called bytecode. Then the JVM runs the bytecode in the JVM.
When you compile a Java program, the runtime environment that simulates the JVM for the targeted computer type (Windows, Linux, macOS, and so on) is included with your compiled Java programs.
That's how Java provides platform independence - and believe it or not, it works pretty well. The programs you write run just as well on a PC running any version of Windows, a Macintosh, a Unix or Linux machine, or any other computer that has a compatible JVM - including smartphones, tablet computers, or IoT devices.
While you lie awake tonight pondering the significance of Java's platform independence, here are a few additional thoughts to ponder:
Platform independence goes only so far. If you have some obscure type of computer system - such as an antique Olivetti Programma 101 - and a JVM runtime environment isn't available for it, you can't run Java programs on it.
I didn't make up the Olivetti Programma 101. It was a desktop computer made in the early 1960s, and it happened to be my introduction to computer programming. (My junior high school math teacher had one in the back of his classroom, and he let me play with it during lunch.) Do a Google search for "Olivetti Programma 101" and you can find several interesting websites about it.
If you're interested, the JVM is completely stack-oriented; it has no registers for storing local data. (I'm not going to explain what that term means, so if it doesn't make sense to you, skip it. It's not important. It's just interesting to nerds who know about stacks, registers, and things of that ilk.)
Java is inherently object-oriented, which means that Java programs are made up from programming elements called objects. Simply put (don't you love it when you read that in a computer book?), an object is a programming entity that represents either some real-world object or an abstract concept.
All objects have two basic characteristics:
start
stop
drive
crash
getTitle
Classes are closely related to objects. A class is the program code you write to create objects. The class describes the data and methods that define the object's state and behavior. When the program executes, classes are used to create objects.
Suppose you're writing a payroll program. This program probably needs objects to represent the company's employees. So the program includes a class (probably named Employee) that defines the data and methods for each Employee object. When your program runs, it uses this class to create an object for each of your company's employees.
Employee
The Java language itself is very simple, but Java comes with a library of classes that provide commonly used utility functions that most Java programs can't do without. This class library, called the Java API (short for application programming interface), is as much a part of Java as the language itself. In fact, the real challenge of finding out how to use Java isn't mastering the language; it's mastering the API. The Java language has only about 50 keywords, but the Java API has several thousand classes, with tens of thousands of methods that you can use in your programs.
The Java API has classes that let you do trigonometry, write data to files, create windows onscreen, and retrieve information from a database, among other things. Many of the classes in the API are general purpose and commonly used. A whole series of classes stores collections of data, for example. But many are obscure, used only in special situations.
Fortunately, you don't have to learn anywhere near all of the Java API. Most programmers are fluent with only a small portion of it: the portion that applies most directly to the types of programs they write. If you find a need to use some class from the API that you aren't yet familiar with, you can look up what the class does in the Java API documentation at https://docs.oracle.com/en/java/javase/19.
https://docs.oracle.com/en/java/javase/19
If you believe the marketing hype put out by Oracle and others, you think that Java is the best thing to happen to computers since the invention of...
Dateiformat: ePUBKopierschutz: Adobe-DRM (Digital Rights Management)
Systemvoraussetzungen:
Das Dateiformat ePUB ist sehr gut für Romane und Sachbücher geeignet – also für „fließenden” Text ohne komplexes Layout. Bei E-Readern oder Smartphones passt sich der Zeilen- und Seitenumbruch automatisch den kleinen Displays an. Mit Adobe-DRM wird hier ein „harter” Kopierschutz verwendet. Wenn die notwendigen Voraussetzungen nicht vorliegen, können Sie das E-Book leider nicht öffnen. Daher müssen Sie bereits vor dem Download Ihre Lese-Hardware vorbereiten.Bitte beachten Sie: Wir empfehlen Ihnen unbedingt nach Installation der Lese-Software diese mit Ihrer persönlichen Adobe-ID zu autorisieren!
Weitere Informationen finden Sie in unserer E-Book Hilfe.