Download as odp, pdf, or txt
Download as odp, pdf, or txt
You are on page 1of 5

Chapter One

Intro to Java Programming Language


1.1. Getting Started
● In the Java programming language, programs are built from classes.
● From a class definition, you can create any number of objects that are known as instances of that class.

Think of a class as a factory with blueprints and instructions to build gadgets objects are the gadgets the factory makes.
● A class contains members, the primary kinds being fields and methods.

● Fields are data variables belonging either to the class itself or to objects of the class; they make up the state of the object or

class.
● Methods are collections of statements that operate on the fields to manipulate the state.

● Statements define the behavior of the classes: they can assign values to fields and other variables, evaluate arithmetic

expressions, invoke
● methods, and control the flow of execution.

● Long tradition holds that the first sample program for any language should print "Hello, world":

class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world");
}
}
● Use your favorite text editor to type this program source code into a file.
● Then run the compiler to compile the source of this program into bytecodes, the "machine language" for the Java
virtual machine (more on this later in this chapter).
● Details of editing and compiling source vary from system to systemconsult your system manuals for specific
information.
● On the system we use most oftenthe Java™ 2 Platform, Standard Edition (J2SE™) Development Kit (JDK)
provided free of charge by Sun Microsystemsyou put the source for HelloWorld into a file named HelloWorld.java.
● To compile it you type the command
javac HelloWorld.java
● To run the program you type the command
java HelloWorld
● This executes the main method of HelloWorld. When you run the program, it displays
● Hello, world

You might also like