0% found this document useful (0 votes)
4 views12 pages

Introduction to Java Programming Basics

Chapter 1 introduces the Java programming language, covering its structure, basics, and key concepts such as classes, objects, and methods. It outlines the stages of Java programming, including editing, compiling, loading, verifying, and executing code. The chapter also discusses naming conventions, identifiers, reserved words, and the importance of comments for code readability.

Uploaded by

Halil Özmen
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

Introduction to Java Programming Basics

Chapter 1 introduces the Java programming language, covering its structure, basics, and key concepts such as classes, objects, and methods. It outlines the stages of Java programming, including editing, compiling, loading, verifying, and executing code. The chapter also discusses naming conventions, identifiers, reserved words, and the importance of comments for code readability.

Uploaded by

Halil Özmen
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

JAVA PROGRAMMING

LANGUAGE
Chapter 1 - Introduction to
Java

Java - Chapter 1. Introduction to Java 1


Contents
• Structure of Java
• Basics of Java Programming Language
• Comments
• Identifiers and Reserved Words
• Java Naming Conventions
• White Space and Indentation

Java - Chapter 1. Introduction to Java 2


Structure of Java
• Java programs consists of pieces called classes.
• Objects are instances of classes. From the same class, many
objects can be created. An object-oriented program may contain
many objects from various classes.
• Classes contain attributes and methods.
• Attributes contain data of object.
• Methods perform actions related with objects.
• Java has rich collections of existing classes in the Java Class
Libraries which are also known as the Java API's (Application
Programming Interfaces).

Java - Chapter 1. Introduction to Java 3


Learning Java
• To write Java programs, one has to learn:
a) the Java language itself (the syntax, the
constructs),
b) the classes in the Java Class Libraries,
c) how to to write new classes.

Java - Chapter 1. Introduction to Java 4


Java Programming Stages
• Java programs go through five phases:
1. Edit: create Java program using an editor and store on
disk in a file ending with .java.
2. Compile: bytecodes are created and stored on disk in a
file ending with .class.
3. Load: bytecodes are taken from the disk and stored in
the memory.
4. Verify: check that all bytecodes are valid, and ensure that
the bytecode does not violate Java's security restrictions.
5. Execute: JRE (Java Runtime Engine) reads bytecodes,
translates them into instructions that the computer can
understand and runs these machine instructions.

Java - Chapter 1. Introduction to Java 5


Basics of Java
• The source file must be in the form: [Link].
• The following program is in [Link] file, and
displays outputs "Welcome to Java!" on screen.
// The WelcomeJavaApp class implements an application that
// simply prints "Welcome to Java!" to standard output.
public class WelcomeJavaApp
{
public static void main(String[] args)
{
[Link] ("Welcome to Java!"); // Display the string.
} // end of main
} // end of WelcomeJavaApp class
• Here, the "WelcomeJavaApp" class is an application class.
• Application classes have a "main" method.

Java - Chapter 1. Introduction to Java 6


Comments
• The Java programming language supports three
kinds of comments:
– // comment text
The compiler ignores everything from // to the end of the line.
– /* comment text */
The compiler ignores everything from /* to */.
– /** documentation comment text */
This indicates a documentation comment (doc comment, for
short). The compiler ignores this kind of comment, just like it
ignores comments that use /* and */. The JDK javadoc tool
uses doc comments when preparing automatically generated
documentation.

Java - Chapter 1. Introduction to Java 7


Identifiers
• The various words used when writing programs are called
identifiers.
• In Java, the identifiers can be composed of any combination
of letters, digits, the underscore character ( _ ) and the
dollar sign ($), but it cannot begin with a digit. (It cannot
contain any character not listed above. I.e.: space character,
punctuation and special characters are not allowed.)
• Some valid identifier examples:
c3po, a77_4E, _4aT, $a70b, $, _0, _a, _$, $1, _1_, $X$, _x$, a, A
• Some invalid identifier examples:
a7+e44, _4-aT, 7aa, [Link], ba ba
• Java identifiers are case sensitive. Therefore, total, Total,
ToTal, TOTAL are all different identifiers.

Java - Chapter 1. Introduction to Java 8


Reserved words in Java
• Reserved words are special Java words.
• Reserved words cannot be used as identifiers.
abstract const final int public throw
assert continue finally interface return throws
boolean default float long short transient
break do for native static true
byte double goto new strictfp try
case else if null super void
catch enum implements package switch volatile
char extends import private synchronized while
class false instanceof protected this

Java - Chapter 1. Introduction to Java 9


Java Naming Conventions
• Using standard Java naming conventions make the Java code
easier to read for the author and for other programmers.
• Readability of Java code is important because it means less
time is spent trying to figure out what the code does, leaving
more time to fix or modify it.
• The following Java naming conventions will be followed in our
course:
1. Class names are written in CamelCase, i.e. first character of each word is in upper
case.
E.g.: class Student, class Car, class ClassRoom, etc.
2. If the identifier consists on a single word, or part of a word, all letters are lower case.
E.g.: count, sum, cnt, city, name, student, num1, number, etc.
3. If the identifier consists on two or more words, the first letter of 2nd and subsequent
words are upper case, all other letters are lower case.
E.g.: aveCityPopulation, cityCount, sumTrucks, cntStu, cityName, studentId, etc.
4. If the identifier is a constant identifier, then all letter are in upper case.
final int MAXSTUDENT = 50;
final double PI = 3.141592653589793; // use [Link]
Java - Chapter 1. Introduction to Java 10
White Space and Indentation
• The following Java program that is identical to the above Java
program have poor utilization of white spaces and indentation.
• It becomes quite difficult to "read" and "understand" a program if
the white spaces and indentation are poor.
• Example of a very bad white space and indentation style:
// File: [Link]

class WelcomeJavaApp
{
public static void main(String[] args){
[Link] ("Welcome to Java!");
}
}

Java - Chapter 1. Introduction to Java 11


Summary
1. Java source files have the same name as the class
name with the extension .java.
2. Every running Java program is placed in a class
called "application class".
3. The Java codes of an application class are written in:
public static void main(String[] args)
4. Class names start with capital letter, variable and
object names start with lower case letter.
5. Identifiers are case sensitive. For example abc, Abc
and ABC are all different identifiers.
6. Comments are written after //, or between /* ... */.
Java - Chapter 1. Introduction to Java 12

You might also like