Book Image

Java Programming for Beginners

By : SkillSprints Inc., Mark Lassoff
Book Image

Java Programming for Beginners

By: SkillSprints Inc., Mark Lassoff

Overview of this book

Java is an object-oriented programming language, and is one of the most widely accepted languages because of its design and programming features, particularly in its promise that you can write a program once and run it anywhere. Java Programming for Beginners is an excellent introduction to the world of Java programming, taking you through the basics of Java syntax and the complexities of object-oriented programming. You'll gain a full understanding of Java SE programming and will be able to write Java programs with graphical user interfaces that run on PC, Mac, or Linux machines. This book is full of informative and entertaining content, challenging exercises, and dozens of code examples you can run and learn from. By reading this book, you’ll move from understanding the data types in Java, through loops and conditionals, and on to functions, classes, and file handling. The book finishes with a look at GUI development and training on how to work with XML. The book takes an efficient route through the Java landscape, covering all of the core topics that a Java developer needs. Whether you’re an absolute beginner to programming, or a seasoned programmer approaching an object-oriented language for the first time, Java Programming for Beginners delivers the focused training you need to become a Java developer.
Table of Contents (12 chapters)

What this book covers

Chapter 1, Getting Started with Java, teaches you what Java is and shows its features. We will see the vastness of Java's application by looking at various fields it is used in. We will walk through the steps to install the Java Development Kit. We will then set up a development environment called NetBeans for writing Java programs, and execute these programs. We'll also see how to use NetBeans and write our first Java program in it. You'll also learn to use NetBeans to detect errors and rectify them.

Chapter 2, Understanding Typed Variables, shows what variables are and how they are important for creating better programs. We'll look at some of the primitive data types of Java, int, long, float, char, and double, in detail. You'll also learn about the String class and two of its manipulation methods.

Chapter 3, Branching, basically portrays how to work with conditional if...else statements, running through complex conditionals using functions such as contains, complex, and boolean. We will go through the intricacies of switch, case, and break with the help of programs; we'll also deep dive into using loop functionality with while, do...while, and for loops.

Chapter 4, Data Structures, discusses arrays and presents an example that prints the English alphabet using an array. Then, we'll take a look at multidimensional arrays and write a program that creates a two-dimensional chess board. We'll walk through what ArrayList is and how it enhances the functionality of arrays. We'll write a program using ArrayList with functionality that would have been quite difficult to implement using an array. Finally, you'll learn about Maps and implement an example to understand them better.

Chapter 5, Functions, helps you to start with some of the basic Java functions, such as methods, and then move on to understanding you advanced Java functions. As you become a more experienced programmer, you'll begin to internalize concepts like these and you won't have to really think about them explicitly when you're writing day-to-day code. For now though, there are some logical shortcuts that we can use to keep from getting too tripped up.

Chapter 6, Modeling with Object-Oriented Java, teaches how to create classes and objects in Java. We will also walk through creating custom classes, member variables, and member functions. We will also look into a very special member assigned to our custom classes, the constructor, and types of constructor.

Chapter 7, More Object-Oriented Java, reveals some intricacies of object-oriented programming, precisely, those using the concept of Inheritance, by creating something called as superclass and subclass, and establishing an is-a relationship between them. You'll learn how to use key aspects such as overriding subclass and super class, data structures, and the Protected method. We also get to know how an abstract method works, in detail.

Chapter 8, Useful Java Classes, presents the Calendar class, which is used to work with dates and times. You will learn about the String class in detail. We'll also see what exceptions are and how to handle them to make our programs more robust. Then, we will walk through the Object class and some of its methods. Finally, we will take a look at primitive classes in Java.

Chapter 9, File Input and Output, walks you through the concept of writing and reading data files, where we'll see the usage of the FileWriter and FileReader classes and learn to free up resources using the close () method. You'll also learn to catch an exception and handle it. Then, we'll see how to use the BufferedWriter and BufferedReader classes to wrap the FileWriter and FileReader classes, respectively. Lastly, we will talk about one more aspect of I/O, the Serializable class. We will analyze what serialization is and its use with respect to serializing and deserializing objects.

Chapter 10, Basic GUI Development, shows the basic functions of the GUI in NetBeans. We will learn how to create an application window with the jFrame class by setting its size, adding labels to it, and closing our application. Then we'll talk about the working of palette and components available in it. Lastly, we'll learn about triggering events by adding a button and adding functionality to it.

Chapter 11, XML, explains the Java code to read an XML file into a Document object. You'll also learn how to parse XML data using Java. Finally, you'll learn how to write and modify XML data in Java.