Java All-in-One For Dummies (eBook)

(Autor)

eBook Download: EPUB
2023 | 7. Auflage
912 Seiten
Wiley (Verlag)
978-1-119-98666-9 (ISBN)

Lese- und Medienproben

Java All-in-One For Dummies -  Doug Lowe
Systemvoraussetzungen
28,99 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

A beginning coder's resource for learning the most popular coding language

With Java All-in-One For Dummies, you get 8 books in one, for the most well-rounded Java knowledge on the market. Updated for Java 19, this book includes all the major changes to the programming language, so you won't fall behind. Start by learning the basics of Java-you can do it, even if you've never written a line of code in your life. Then go in-depth, with all the info you need on object-oriented programming, Java FX, Java web development, and beyond. Grab a hot cup of java and settle in to learn some Java, with friendly For Dummies guidance!

  • Learn the basics of computer programming and get started with the Java language
  • Master strings, arrays, and collections
  • Discover the most recent Java updates and the latest in programming techniques
  • Launch or further your career as a coder with easy-to-follow instruction

This is the go-to Dummies guide for future and current coders who need an all-inclusive guide Java to take their knowledge to the next level.

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.


A beginning coder s resource for learning the most popular coding language With Java All-in-One For Dummies, you get 8 books in one, for the most well-rounded Java knowledge on the market. Updated for Java 19, this book includes all the major changes to the programming language, so you won t fall behind. Start by learning the basics of Java you can do it, even if you ve never written a line of code in your life. Then go in-depth, with all the info you need on object-oriented programming, Java FX, Java web development, and beyond. Grab a hot cup of java and settle in to learn some Java, with friendly For Dummies guidance! Learn the basics of computer programming and get started with the Java language Master strings, arrays, and collections Discover the most recent Java updates and the latest in programming techniques Launch or further your career as a coder with easy-to-follow instructionThis is the go-to Dummies guide for future and current coders who need an all-inclusive guide Java to take their knowledge to the next level.

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

Welcome to Java


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.

What Is Java, and Why Is It So Great?


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.

Platform independence


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.

  • Java’s platform independence isn’t perfect. Although the bytecode runs identically on every computer that has a JVM, some parts of Java use services provided by the underlying operating system. As a result, minor variations sometimes crop up, especially in applications that use graphical interfaces.
  • Because a runtime system that emulates a JVM executes Java bytecode, some people mistakenly compare Java with interpreted languages such as Basic or Perl. Those languages aren’t compiled at all, however. Instead, the interpreter reads and interprets each statement as it is executed. Java is a true compiled language; it’s just compiled to the machine language of JVM rather than to the machine language of an actual computer platform.
  • 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.)

Object orientation


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:

  • Objects have data, also known as state. An object that represents a book, for example, has data such as the book’s title, author, and publisher.
  • Objects also have behavior, which means that they can perform certain tasks. In Java, these tasks are called methods. An object that represents a car might have methods such as start, stop, drive, and crash. Some methods simply allow you to access the object’s data. A book object might have a getTitle method that tells you the book’s title.

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.

The Java API


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.

Important Features of the Java Language


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...

Erscheint lt. Verlag 6.1.2023
Sprache englisch
Themenwelt Informatik Programmiersprachen / -werkzeuge Java
Schlagworte Computer Science • Informatik • JAVA (Programmiersprache) • Object Technologies - Java • Objektorientiertes Programmieren / Java
ISBN-10 1-119-98666-4 / 1119986664
ISBN-13 978-1-119-98666-9 / 9781119986669
Haben Sie eine Frage zum Produkt?
EPUBEPUB (Adobe DRM)
Größe: 3,3 MB

Kopierschutz: Adobe-DRM
Adobe-DRM ist ein Kopierschutz, der das eBook vor Mißbrauch schützen soll. Dabei wird das eBook bereits beim Download auf Ihre persönliche Adobe-ID autorisiert. Lesen können Sie das eBook dann nur auf den Geräten, welche ebenfalls auf Ihre Adobe-ID registriert sind.
Details zum Adobe-DRM

Dateiformat: EPUB (Electronic Publication)
EPUB ist ein offener Standard für eBooks und eignet sich besonders zur Darstellung von Belle­tristik und Sach­büchern. Der Fließ­text wird dynamisch an die Display- und Schrift­größe ange­passt. Auch für mobile Lese­geräte ist EPUB daher gut geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen eine Adobe-ID und die Software Adobe Digital Editions (kostenlos). Von der Benutzung der OverDrive Media Console raten wir Ihnen ab. Erfahrungsgemäß treten hier gehäuft Probleme mit dem Adobe DRM auf.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen eine Adobe-ID sowie eine kostenlose App.
Geräteliste und zusätzliche Hinweise

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
Einführung, Ausbildung, Praxis

von Christian Ullenboom

eBook Download (2023)
Rheinwerk Computing (Verlag)
49,90