Book Image

Java Programming for Beginners

By : Mark Lassoff
Book Image

Java Programming for Beginners

By: 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)

Complex conditionals

To begin with, let's write a very simple Java program. We'll start by importing java.util so that we can get some user input via a Scanner object, and we'll link this Scanner object with the input string so we can use it in the console window.

Once we've done this, we're going to need to get some input from the user and store it, so let's create a new string and assign its value to whatever the user gives us. To keep things interesting, let's give ourselves two more String variables to work with. We'll call them sOne and sTwo; we'll assign the value of our first string variable to abc and the value of our second string variable to just z:

package complexconditionals; 
import java.util.*; 
public class ComplexConditionals { 
    public static void main(String[] args) { 
      Scanner reader = new Scanner...