You are on page 1of 3

 A Java program is either a library of static methods or a data type

definition.

 The basis of programming in Java and many other modern languages


consists of five components: primitive data types, statements,
arrays, static methods, and strings.

 Primitive data types define the meaning of terms like integer, real
number, and Boolean value within a computer program.

 Statements allow for defining a computation by creating and


assigning values to variables, controlling execution flow, or causing
side effects.

 Arrays allow for working with multiple values of the same type.

 Static methods allow for encapsulating and reusing code and


developing programs as a set of independent modules.

 Strings are sequences of characters and some operations on them


are built in to Java.

 Running a Java program involves interacting with an operating


system or program development environment.

 To invoke a Java program, it must first be compiled using the javac


command, then run using the java command.

 The next section will cover data abstraction, which extends


encapsulation and reuse to define non-primitive data types and
support object-oriented programming.

 In a Java program, a class is the basic building block and it contains


data members and methods.

 A class can contain constructors, which are used to initialize the state
of an object when it is created.

 A class can also have static members, which are shared across all
instances of the class.
 Java supports object-oriented programming concepts such as
inheritance, polymorphism, and encapsulation.

 Classes can be organized into packages, which provide a way to


organize and manage related classes.

 The Java standard library provides a large number of classes and


interfaces that can be used to perform various tasks, such as
input/output, networking, and data manipulation.

 Java also provides a powerful exception handling mechanism, which


allows programs to handle and recover from errors that occur during
execution.

 Java is platform-independent, which means that Java code can run


on any platform that has a Java Virtual Machine (JVM) installed.

 Java also provides a rich set of annotations, which can be used to


provide additional information about a class or its members.

 Java has four primitive data types: integers, real numbers, Booleans,
and characters.

 These data types have specific sets of values and operations that can
be performed on them.

 Variables in Java are named with identifiers and are associated with
a specific data type.

 Expressions are used to apply operations and specify values for these
types, using identifiers, operator symbols, literals, and other
expressions.

 The goal of an expression is to define a specific data-type value.

 To define a data type, we need to specify the values and set of


operations on those values.

 Java's int, double, boolean, and char data types are similar to basic
data types found in many programming languages.
 The operations for int and double are familiar arithmetic operations,
and for boolean, they are familiar logical operations.

 +, -, *, and / are overloaded, meaning the same symbol specifies


operations in multiple different types depending on context.

 The key property of these primitive operations is that an operation


involving values of a given type has a value of that type.

 This rule highlights the idea that we are often working with
approximate values, as the exact value defined by an expression may
not be a value of the type.

 The table provided is not complete and additional operators and


exceptional situations will be discussed in the Q&A section at the
end of the section.

 Expressions in Java are typically infix, with a literal or expression


followed by an operator and another literal or expression.

 The order in which operators are applied is often significant, and


Java has a set of precedence conventions for operators.

 Type conversion occurs automatically if no information is lost, and a


cast is used to convert a value to a specific type.

 Comparisons between two values of the same type produce a


boolean value, and these operators are known as mixed-type
operators.

 In addition to int and double, Java also has five other primitive data
types: long, short, char, byte, and float.

 These data types are used for specific purposes and are not
discussed in further detail in this book.

You might also like