This document provides an overview of Java/J2EE programming training that covers:
- Introduction to the Java platform, including Java virtual machine, compiling Java code, and types of Java applications
- Defining classes and objects in Java, where a class acts as a blueprint and an object is an instance of a class
- Legal naming conventions for identifiers in Java and declaring primitive data types
- Access modifiers like public, private, and protected that control access to classes and class members
2. Page 1Classification: Restricted
Agenda
• Introduction to java platform
• Java virtual machine
• First java program
• Class declaration
• Object
• Legal identifiers
• Declaring primitives and primitive ranges
• Java Keywords
• Access modifiers
3. Page 2Classification: Restricted
Introduction to java platform
• Java is a high level, robust, secured and object-oriented programming
language.
• Any hardware or software environment in which a program runs, is known
as a platform. Since Java has its own runtime environment (JRE) and API, it
is called platform.
• Java is a programming language created by James Gosling from Sun
Microsystems (Sun) in 1991. The target of Java is to write a program once
and then run this program on multiple operating systems.
• The first publicly available version of Java (Java 1.0) was released in 1995.
Sun Microsystems was acquired by the Oracle Corporation in 2010.
• Over time new enhanced versions of Java have been released. The current
version of Java is Java 1.8 which is also known as Java 8.
5. Page 4Classification: Restricted
Introduction to java platform
• The java program saved as .java file
• Using the java compiler the code is converted into an intermediate code
called the bytecode. The output is a .class file.
• This code is not understood by any platform, but only a virtual platform
called the Java Virtual Machine
• This Virtual Machine resides in the RAM of your operating system. When
the Virtual Machine is fed with this bytecode, it identifies the platform it is
working on and converts the bytecode into the native machine code
• Code once compiled can run not only on all PC platforms but also mobiles
or other electronic gadgets supporting java. Hence, java is a language as
well as a platform (JVM)
6. Page 5Classification: Restricted
Introduction to Java
• There are mainly 4 types of applications that can be created using java
programming:
• Standalone Application
• Web Application
• Enterprise Application
• Mobile Application
7. Page 6Classification: Restricted
Java virtual machine
• JVM stands for Java Virtual Machine. It is the engine that drives the Java
Code. It converts Java bytecode into machines language.
• In other programming language, the compiler produces code for a
particular system. But Java compiler produces code for a Virtual Machine.
• In JVM, Java code is compiled into bytecode. This bytecode gets
interpreted on different machines
• JVM is responsible for allocating a memory space.
9. Page 8Classification: Restricted
Class declaration
• A class is an entity that determines how an object will behave and what
the object will contain. In other words, it is a blueprint or a set of
instruction to build a specific type of object.
10. Page 9Classification: Restricted
Class declaration
• There can be only one public class per source code file.
• If the class is part of a package, the package statement must be the first line
in the source code file, before any import statements that may be present.
• If there are import statements, they must go between the package
statement (if there is one) and the class declaration.
• import and package statements apply to all classes within a source code
file. In other words, there's no way to declare multiple classes in a file and
have them in different packages, or use different imports.
• A file can have more than one nonpublic class.
• Files with no public classes can have a name that does not match any of the
classes in the file.
12. Page 11Classification: Restricted
Object
• Real-world objects share two characteristics: They all have state and behavior.
Dogs have state (name, color, breed, hungry) and behavior (barking, fetching,
wagging tail).
• Software objects are conceptually similar to real-world objects: they too
consist of state and related behavior. An object stores its state
in fields (variables in some programming languages) and exposes its behavior
through methods (functions in some programming languages).
• An object is nothing but a self-contained component which consists of
methods and properties to make a particular type of data useful. Object
determines the behavior of the class. When you send a message to an object,
you are asking the object to invoke or execute one of its methods.
• An object is a specimen of a class. Software objects are often used to model
real-world objects you find in everyday life.
13. Page 12Classification: Restricted
Legal identifiers
• Identifiers must start with a letter, a currency character ($), or a
connecting character such as the underscore ( _ ). Identifiers cannot
start with a number!
• After the first character, identifiers can contain any combination of
letters, currency characters, connecting characters, or numbers.
• In practice, there is no limit to the number of characters an identifier
can contain.
• Identifiers in Java are case-sensitive; foo and FOO are two different
identifier.
• Exercise:-
• int :b;
• int -d;
• int e#; I
• nt .f;
• int 7g;
16. Page 15Classification: Restricted
Access modifiers
Modifiers fall into two categories:
Access modifiers: public, protected, private.
Non-access modifiers (including strictfp, final, and abstract).
Class Access
One class (class A) has access to another class (class B), it means class A can
do one of three things:
Create an instance of class B.
Extend class B (in other words, become a subclass of class B).
Access certain methods and variables within class B, depending on the access
control of those methods and variables.
17. Page 16Classification: Restricted
Access modifiers
Class access can have following access modifiers :-
• Default Access
• Public Access
Class access can have following non access modifiers :-
• Final Classes
• Abstract Classes
• Strictfp Classes
19. Page 18Classification: Restricted
Access modifiers
Class member can have following non access modifiers :-
• Final Methods
• Abstract Methods
• Synchronized Methods
• Native Methods
• Strictfp methods