Java Programming I B.
Sc CS & I BCA
Core 3 : Java Programming 5 3 2 7 1 4
5 5 0
0
DEPARTMENT OF COMPUTER SCIENCE
ODD SEMESTER
COURSE MATERIAL
SEMESTER - II
I [Link]. ALML & ML & I B.C.A
NOTES OF LESSON
JAVA PROGRAMMING
23A
ACADEMIC YEAR 2025- 2026
NG N
PREPARED BY
Mrs. S. POONGOTHAI AP/CS
[Link] AP/CS,SCAS 1
Java Programming I [Link] CS & I BCA
Course Code Java Programming L T P C
Core/elective/Supportiv Core:3 5 0 - 4
e
Course Objectives
UNIT I 16
Fundamentals of OOP
Fundamentals of Object-Oriented Programming: Object-Oriented Paradigm – Basic Concepts of
Object-Oriented Programming– Benefits of Object-Oriented Programming–Application of
Object-Oriented Programming. Java Evolution: History–Features–How Java differs from C and
C++ – Java and Internet–Java and www–Web Browsers. Overview of Java: simple Java
program–
Structure– Java Tokens–Statements–Java Virtual Machine.
UNIT II 15
Variables & Control Structures
Constants, Variables, Data Types-Operators and Expressions–Decision Making and Branching:
if, if...else, nested if, switch?: Operator- Decision Making and Looping: while, do, for–Jumps in
Loops
-Labeled Loops–Classes, Objects and Methods.
UNIT III Arrays & Classes 14
Arrays, Strings and Vectors–Interfaces: Multiple Inheritance–Packages: Putting Classes together–
Multithreaded Programming.
UNIT IV Error Handling & Graphics 13
Managing Errors and Exceptions–Applet Programming–Graphics Programming.
UNIT V I/O Streams 17
Managing Input/Output Files in Java: Concepts of Streams-Stream Classes–Byte Stream classes–
Character stream classes–Using streams–I/O Classes–File Class–I/O exceptions–Creation of
Files –Reading/Writing characters, Byte-Handling Primitive Data Types–Random Access Files.
Total Lecture 75
Hours
Text Book(s)
1 Programming with Java–A [Link],3rd Edition,TMH.
UNIT I 16
Fundamentals of OOP
Fundamentals of Object-Oriented Programming: Object-Oriented Paradigm – Basic Concepts of
Object-Oriented Programming– Benefits of Object-Oriented Programming–Application of
Object-Oriented Programming. Java Evolution: History–Features–How Java differs from C and
C++ – Java and Internet–Java and www–Web Browsers. Overview of Java: simple Java
program–
Structure– Java Tokens–Statements–Java Virtual Machine.
Fundamentals of Object-Oriented Programming: Object-Oriented Paradigm
[Link] AP/CS,SCAS 2
Java Programming I [Link] CS & I BCA
The object-oriented (OO) paradigm took its shape from the initial concept of a new
programming approach, while the interest in design and analysis methods came
much later. OO analysis and design paradigm is the logical result of the wide
adoption of OO programming languages.
The first object oriented language was Simula (Simulation of real systems) that was
developed in 1960 by researchers at the Norwegian Computing Center.
In 1970, Alan Kay and his research group at Xerox PARC created a personal
computer named Dynabook and the first pure object-oriented programming language
(OOPL) - Smalltalk, for programming
the Dynabook.
In the 1980s, Grady Booch published
a paper titled Object Oriented Design
that mainly presented a design for the
programming language, Ada. In the
ensuing editions, he extended his
ideas to a complete objectoriented
design method.
In the 1990s, Coad incorporated
behavioral ideas to object-oriented methods.
The other significant innovations were Object Modeling Techniques (OMT) by
James Rum Baugh and Object-Oriented Software Engineering (OOSE) by Ivar
Jacobson.
Basic Concepts of Object-Oriented Programming
Before Object-Oriented Programming (OOPs), most programs used a procedural
approach, where the focus was on writing step-by-step functions. This made it harder
to manage and reuse code in large applications.
To overcome these limitations, Object-Oriented Programming was introduced. Java
is built around OOPs, which helps in organizing code using classes and objects.
Key Features of OOP in Java:
Structures code into logical units (classes and objects)
Keeps related data and methods together (encapsulation)
Makes code modular, reusable and scalable
Prevents unauthorized access to data
Follows the DRY (Don’t Repeat Yourself) principle
1. Class
A Class is a user-defined blueprint or prototype from which objects are created. It
represents the set of properties or methods that are common to all objects of one
type. Using classes, you can create multiple objects with the same behavior instead
of writing their code multiple times. In general, class declarations can include these
components in order:
[Link] AP/CS,SCAS 3
Java Programming I [Link] CS & I BCA
Modifiers: A class can be public or have default access (Refer to this for details).
Class name: The class name should begin with the initial letter capitalized by
convention.
Body: The class body is surrounded by braces, { }.
2. Object
An Object is a basic unit of Object-Oriented Programming that represents real-life
entities. A typical Java program creates many objects, which as you know, interact
by invoking methods. The objects are what perform your code, they are the part of
your code visible to the viewer/user. An object mainly consists of:
State: It is represented by the attributes of an object. It also reflects the properties of
an object.
Behavior: It is represented by the methods of an object. It also reflects the response
of an object to other objects.
Identity: It is a unique name given to an object that enables it to interact with other
objects.
Method: A method is a collection of statements that perform some specific task and
return the result to the caller.
Example:
public class Employee {
// Instance variables (non-static)
private String name;
private float salary;
// Constructor
public Employee(String name, float salary) {
[Link] = name;
[Link] = salary;
}
// getters method
public String getName() { return name; }
public float getSalary() { return salary; }
// setters method
public void setName(String name) { [Link] = name; }
public void setSalary(float salary) { [Link] = salary; }
// Instance method
public void displayDetails() {
[Link]("Employee: " + name);
[Link]("Salary: " + salary);
}
public static void main(String[] args) {
Employee emp = new Employee("Geek", 10000.0f);
[Link]();
}
}
[Link] AP/CS,SCAS 4
Java Programming I [Link] CS & I BCA
Output
Employee: Geek
Salary: 10000.0
Note: For more information, please refer to the article - Classes and Object.
3. Abstraction
Abstraction in Java is the process of hiding the implementation details and only
showing the essential details or features to the user. It allows to focus on what an
object does rather than how it does it. The unnecessary details are not displayed to
the user.
Note: In Java, abstraction is achieved by interfaces and abstract classes. We can
achieve 100% abstraction using interfaces.
Example:
Encapsulation is defined
as the process of wrapping data and the methods into a single unit, typically a class.
It is the mechanism that binds together the code and the data. It manipulates. Another
way to think about encapsulation is that it is a protective shield that prevents the data
from being accessed by the code outside this shield.
Technically, in encapsulation, the variables or the data in a class is hidden from any
other class and can be accessed only through any member function of the class in
which they are declared.
In encapsulation, the data in a class is hidden from other classes, which is similar to
what data-hiding does. So, the terms "encapsulation" and "data-hiding" are used
interchangeably.
Encapsulation can be achieved by declaring all the variables in a class as private and
writing public methods in the class to set and get the values of the variables.
[Link] AP/CS,SCAS 5
Java Programming I [Link] CS & I BCA
Types of Polymorphism
Polymorphism in Java is mainly of 2 types as mentioned below:
Method Overloading
Method Overriding
Method Overloading and Method Overriding
1. Method Overloading: Also, known as compile-time polymorphism, is the concept
of Polymorphism where more than one method share the same name with different
signature(Parameters) in a class. The return type of these methods can or cannot be
same.
2. Method Overriding: Also, known as run-time polymorphism, is the concept of
Polymorphism where method in the child class has the same name, return-type and
parameters as in parent class. The child class provides the implementation in the
method already written.
5. Inheritance
Inheritance is an important pillar of OOP (Object Oriented Programming). It is the
mechanism in Java by which one class is allowed to inherit the features (fields and methods)
of another class. We are achieving inheritance by using extends keyword. Inheritance is also
known as "is-a" relationship.
Example: Dog, Cat, Cow can be Derived Class of Animal Base Class.
6. Dynamic Binding
Binding is a mechanism creating link between method call and method actual
implementation. As per the polymorphism concept in Java, object can have many
different forms. Object forms can be resolved at compile time and run time.
Dynamic binding refers to the process in which linking between method call and
method implementation is resolved at run time (or, a process of calling an overridden
method at run time). Dynamic binding is also known as run-time polymorphism or
late binding. Dynamic binding uses objects to resolve binding.
[Link] AP/CS,SCAS 6
Java Programming I [Link] CS & I BCA
7. Message Passing in terms of computers is communication between processes. It is
a form of communication used in object-oriented programming as well as parallel
programming. Message passing in Java is like sending an object i.e. message from
one thread to another thread. It is used when threads do not have shared memory and
are unable to share monitors or semaphores or any other shared variables to
communicate
Benefits of Object-Oriented Programming
We can build the programs from standard working modules that communicate with
one another, rather than having to start writing the code from scratch which leads to
saving of development time and higher productivity,
OOP language allows to break the program into the bit-sized problems that can be
solved easily (one object at a time).
The new technology promises greater programmer productivity, better quality of
software and lesser maintenance cost.
OOP systems can be easily upgraded from small to large systems.
It is possible that multiple instances of objects co-exist without any interference,
It is very easy to partition the work in a project based on objects.
It is possible to map the objects in problem domain to those in the program.
The principle of data hiding helps the programmer to build secure programs which
cannot be invaded by the code in other parts of the program.
By using inheritance, we can eliminate redundant code and extend the use of existing
classes.
Message passing techniques is used for communication between objects which
makes the interface descriptions with external systems much simpler.
The data-centered design approach enables us to capture more details of model in an
implementable form.
Application of Object-Oriented Programming.
The length of the programmes developed using OOP language is much larger than
the procedural approach. Since the programme becomes larger in size, it requires
more time to be executed that leads to slower execution of the programme.
We can not apply OOP everywhere as it is not a universal language. It is applied only
when it is required. It is not suitable for all types of problems.
Programmers need to have brilliant designing skill and programming skill along with
proper planning because using OOP is little bit tricky.
OOPs take time to get used to it. The thought process involved in object-oriented
programming may not be natural for some people.
Everything is treated as object in OOP so before applying it we need to have
excellent thinking in terms of objects.
Real time Systems
Simulation and modelling
Object Oriented Databse
Hypertext, hypermedia and Expertext
AI and Expert systems
[Link] AP/CS,SCAS 7
Java Programming I [Link] CS & I BCA
CIM /CAD/systems
Decision support and office automation
Neural networks
Java Evolution: History
Java programming language was originally developed by Sun Microsystems which
was initiated by James Gosling and released in 1995 as core component of Sun
Microsystems' Java platform (Java 1.0 [J2SE]). History of even naming of the Java is
very interesting. It went under many names.
Java Name History
GreenTalk
James Gosling was leading a team named as 'Green' team. Target of this team was to
create a new language which can work on multiple electronic devices seemlessly.
Initially C++ was the original choice to develop the project. James Gosling wanted to
enhance C++ to achieve the target but due to high memory usage, that idea was
rejected and team started with a new language initially named as GreenTalk. The file
extension used as .gt. Later this language was termed as Oak and finally to Java.
Oak
James Gosling renamed language to Oak. There was an Oak tree in front of his
office. James Gosling used this name as Oak represents solidarity and Oak tree is the
national tree of multiple countries like USA, France, Romania etc. But Oak
technologies already had Oak as a trademark and James team had to brainstrom
another title for the language.
Finally Java
Team put multiple names like DNA, Silk, Ruby and Java. Java was finalized by the
team. James Gosling tabled Java title based on type of espresso coffee bean. Java is
an island in Indonesia where new coffee was discovered termed as Java coffee. As
per James Gosling, Java was among the top choice along with Silk. Finally Java was
selected as it was quite unique and represented the essence of being
dynamic,revolutionary and fun to say.
Sun released the first public implementation as Java 1.0 in 1995. It promised Write
Once, Run Anywhere (WORA), providing no-cost run-times on popular platforms.
On 13 November, 2006, Sun released much of Java as free and open source software
under the terms of the GNU General Public License (GPL).
On 8 May, 2007, Sun finished the process, making all of Java's core code free and
open-source, aside from a small portion of code to which Sun did not hold the
copyright.
The latest release of the Java Standard Edition is Java SE 21. With the advancement
of Java and its widespread popularity, multiple configurations were built to suit
various types of platforms. For example: J2EE for Enterprise Applications, J2ME for
Mobile Applications.
Java Versions History
[Link] AP/CS,SCAS 8
Java Programming I [Link] CS & I BCA
[Link]. Version Date Description
1 JDK Beta 1995 Initial Draft version
2 JDK 1.0 23 Jan 1996 A stable variant JDK 1.0.2 was termed as JDK 1
3 JDK 1.1 19 Feb 1997 Major features like JavaBeans, RMI, JDBC, inner
classes were added in this release.
4 JDK 1.2 8 Dec 1998 Swing, JIT Compiler, Java Modules, Collections
were introduced to JAVA and this release was a great success.
5 JDK 1.3 8 May 2000 HotSpot JVM, JNDI, JPDA, JavaSound and support
for Synthetic proxy classes were added.
6 JDK 1.4 6 Feb 2002 Image I/O API to create/read JPEG/PNG image
were added. Integrated XML parser and XSLT processor (JAXP) and Preferences
API were other important updates.
7 JDK 1.5 or J2SE 5 30 Sep 2004 Various new features were added to the
language like foreach, var-args, generics etc.
8 JAVA SE 6 11 Dec 2006 1. notation was dropped to SE and upgrades done to
JAXB 2.0, JSR 269 support and JDBC 4.0 support added.
9 JAVA SE 7 7 Jul 2011 Support for dynamic languages added to JVM.
Another enhancements included string in switch case, compressed 64 bit pointers etc.
10 JAVA SE 8 18 Mar 2014 Support for functional programming added. Lambda
expressions, streams, default methods, new date-time APIs introduced.
11 JAVA SE 9 21 Sep 2017 Module system introduced which can be applied to
JVM platform.
12 JAVA SE 10 20 Mar 2018 Unicode language-tag extensions added. Root
certificates, threadlocal handshakes, support for heap allocation on alternate memory
devices etc were introduced.
13 JAVA SE 11 5 Sep 2018 Dynamic class-file constants, Epsilon a no-op
garbage collector, local-variable support in lambda parameters, Low-overhead heap
profiling support added.
14 JAVA SE 12 19 Mar 2019 Experimental Garbage Collector,Shenandoah: A
Low-Pause-Time Garbage Collector, Microbenchmark Suite, JVM Constants API
added.
15 JAVA SE 13 17 Sep 2019 Feature added - Text Blocks (Multiline strings),
Enhanced Thread-local handshakes.
16 JAVA SE 14 17 Mar 2020 Feature added - Records, a new class type for
modelling, Pattern Matching for instanceof, Intuitive NullPointerException handling.
17 JAVA SE 15 15 Sep 2020 Feature added - Sealed Classes, Hidden Classes,
Foreign Function and Memory API (Incubator).
18 JAVA SE 16 16 Mar 2021 Feature added as preview - Records, Pattern
Matching for switch, Unix Domain Socket Channel (Incubator) etc.
19 JAVA SE 17 14 Sep 2021 Feature added as finalized - Sealed Classes, Pattern
Matching for instanceof, Strong encapsulation of JDK internals by default. New
macOS rendering pipeline etc.
20 JAVA SE 18 22 Mar 2022 Feature added - UTF-8 by Default, Code Snippets in
Java API Documentation, Vector API (Third incubator), Foreign Function, Memory
API (Second Incubator) etc.
[Link] AP/CS,SCAS 9
Java Programming I [Link] CS & I BCA
21 JAVA SE 19 20 Sep 2022 Feature added - Record pattern, Vector API (Fourth
incubator), Structured Concurrency (Incubator) etc.
22 JAVA SE 20 21 Mar 2023 Feature added - Scoped Values (Incubator), Record
Patterns (Second Preview), Pattern Matching for switch (Fourth Preview),Foreign
Function & Memory API (Second Preview) etc.
22 JAVA SE 21 19 Sep 2023 Feature added - String Templates (Preview),
Sequenced Collections, Generational ZGC, Record Patterns, Pattern Matching for
switch etc.
23 Java SE 22 19 Mar 2024 Feature added - Region Pinning for G1 garbage
collector, foreign functions and memory APIs , multi-file source code programs
support, string templates, vector apis (seventh incubator), unnamed variables,
patterns, stream gatherers (first preview) etc.
24 Java SE 23 17 Sep 2024 Feature added - Primitive types in patterns, class file
APIs, vector APIs (Eighth incubator), stream gatherers (second preview), ZDC,
generation mode by default etc.
Java Features
1. Compiled and interpreted
Java compiler translates source code into byte code instructions. Byte code is not
machine instructions and therefore, in the second stage, java interpreter generates
machine code that can be directly executed by the machine that is running the java
program.
2. Platform independent and portable
Java programs can be easily moved from one computer to another, anywhere and
anytime. Changes and upgrades in OS, processors and system resources will not
force any changes in java programs.
Java ensures portability in two ways:
i. Java compiler generates byte code instructions that can be implemented on any
machine.
ii. The size of the primitive data types are machine independent.
3. Object oriented
Java is a true object-oriented language. Everything in java is an object. All program
code and data reside within objects and classes. Java comes with an extensive set of
classes, arranged in packages that we can use in our programs by inheritance.
4. Robust and secure
Java is a robust language. It provides many safeguards to ensure reliable code. It has
strict compile time and runtime checking for data types. It is designed as a garbage-
collected language relieving the programmers virtually all memory management
problems.
5. Distributed
Java has the ability to share both data and programs. Java applications can open and
access remote objects on internet as easily as they can do in a local system. This
enables multiple programmers at multiple remote locations to collaborate and work
6. Simple, small and familiar
Java is a small and simple language. Java does not use pointers, preprocessor, header
files, goto statement and many others. It also eliminates operator overloading and
multiple inheritance. Familiarity is another striking feature of java. To make the
language look familiar to the existing programmers, it was modeled on C and C++
language.
[Link] AP/CS,SCAS 10
Java Programming I [Link] CS & I BCA
7. Multithreaded and interactive
Multithreaded means handling multiple tasks simultaneously. Java supports
multithreaded programs. This means that we need not wait for the application to
finish one task before beginning other.
8. High performance
Java performance is impressive for an interpreted language, mainly due to the use of
intermediate byte code. Java architecture is also designed to reduce overheads during
runtime. The incorporation of multithreading enhances the overall execution speed of
java programs.
9. Dynamic and extensible
Java is a dynamic language. Java is capable of dynamically linking in new class
libraries, methods, and objects. Java programs support functions written in other
languages such as C and C++.These functions are known as native methods. Native
methods are linked dynamically at runtime.
10. Ease of development
Java 2 Standard Edition (J2SE) 5.0 supports features, such as Generics, enhanced for
loop, auto boxing, type safe enums, varargs, static import and annotation. These
features reduce the work of the programmer by shifting the responsibility of creating
the reusable code to the compiler.
11. Scalability and performance
J2SE 5.0 assures a significant increase in scalability and performance by improving
the startup time and reducing the amount of memory used in Java 2 runtime
environment. Memory utilization is reduced by sharing data in the shared archive
among multiple JVM (Java Virtual Machine) processes.
[Link] and manageability
Java supports a number of APIs, such as JVM monitoring and management platform
extension, logging, monitoring and management interface and Java Management
Extension (JMX) to monitor and manage java applications.
[Link] client
J2SE 5.0 provides enhanced features to meet the requirements and challenges of the
java desktop users. This feature is mainly used for developing graphics applications
that require OpenGL hardware acceleration.
[Link] features
J2SE 5.0 supports the features such has:
Core XML support:
J2SE 5.0 adds a powerful XML feature to the java platform.
Supplementary character support:
Java adds the 32-bit supplementary character support as part of the Unicode 4.0
support. The supplementary characters are encoded with UTF-16 values to generate a
different character called, surrogate code point.
JDBC Row Set:
Java supports JDBC row set to send data in a tabular format between the remote
components of a distributed enterprise application.
How Java differs from C and C++
Java and C
Overlapping of C, C++ and Java
[Link] AP/CS,SCAS 11
Java Programming I [Link] CS & I BCA
Java is a lot like C but the major difference between Java and C is that Java is an
Object - Oriented language and has mechanism to define classes and objects. In an
effort to build a simple and safe language, the Java team did not include some of the
C features in Java.
Java does not support the following C concepts they are, Keywords are sizeof,
typedef, void instance of, break and continue, Datatypes are struct and union,
Modifiers are auto, extern,
register, signed and unsigned, Preprocessor and cannot use #define, #include and
#ifdef statements.
Java and C++
Java is a true object-oriented language while C++ is basically C with object-oriented
extension. Java does not support the following C++ concepts they are, operator
overloading, template classes, Multiple Inheritance, Global variables and Pointers.
JAVA and Internet
Java is strongly associated with the internet because of the first application program
is written in Java was hot Java, a Web browser to run applets on the internet. Internet
users can use Java to create applet programs & run then locally using a Java-enabled
browser such as hot Java. Java applets have made the internet a true extension of the
storage system of the local computer.
JAVA and World Wide Web (WWW)
World Wide Web is a collection of information stored on internet computers. WWW
is an information retrieval system designed to be used in the internet’s distributed
environment. WWW contains web pages that provide both information and controls.
Web pages contain HTML tags that enable us to find retrieve, manipulate and
display documents World Wide. Before Java, the WWW was limited to the display
of still images & texts. With the help of Java WWW is capable of supporting
animation graphics, games and wide rage special effects.
User’s Computer Remote Computer
Web Browsers
The internet is a vast sea of information represented in many formats and stored on
many computers. A large portion of the internet is organized as the WWW which
uses hypertext. Web browsers are used to navigate the information found on the net.
They allow us to retrieve the information spread across the Internet and display it
using the Hypertext Markup Language (HTML). Examples of Web browsers are,
Hot Java
Netscape Navigator
Internet Explorer
Overview of Java: simple Java program Structure
SIMPLE JAVA PROGRAM
[Link] AP/CS,SCAS 12
Java Programming I [Link] CS & I BCA
class Example
{
public static void main (String args[])
{
[Link](“This is a simple java program”);
}
}
Class Declaration
The first line class Example declares a class. The Java is a true object-oriented
language and everything must be placed inside a class. class is a keyword and declares
that a new class definition follows. Example is a Java identifier that specifies the name
of the class to be defined.
Opening Brace
Every class definition in Java begins with an opening brace “{“and ends with a
matching closing brace “}”.
The Main Line
public static void main (String args[ ])
Public The keyword public is an access specifier that declares the main method as
unprotected and therefore making it accessible to all other classes.
Static The keyword static declares this method as one that belongs to the entire class and
not a part of any objects of the class.
Void The type modifier void states that the main method does not return any value.
Main() This is the starting point for the interpreter to begin the execution of the program.
String It declares a parameter named args, which contains an array of objects of the class
args[ ] type String.
JAVA PROGRAM STRUCTURE
Documentation section
Package statement
Import statement
Suggested Optional
Interface statements
Optional Optional Optional
Essential
Class definitions
Main method class
{
Main method definition
}
[Link] AP/CS,SCAS 13
Java Programming I [Link] CS & I BCA
General structure of a java program
Documentation section
It comprises a set of comment lines giving the name of the program, the author
and other details which the programmer would like to refer to at a later stage.
E.g.:
// this is a sample program
/*this is a java program */
/**….*/ Documentation Comment.
Package statement:
The first statement allowed in a java file is a package statement. This statement
declares a package name and informs the compiler that the classes defined here belong to
this package.
E.g.: package student;
Import statement:
The next thing after a package statement may be a number of import statements.
This is similar to the #include statement in C.
E.g.: import [Link];
Interface Statements:
It is like a class but includes a group of method declarations. It is used in
implementing multiple inheritances.
Class definitions:
A java program may contain multiple class definitions. Classes are the primary
and essential elements of a java program. These classes are used to map the objects of
real-world problems.
JAVA TOKENS
A java program is basically a collection of classes. A class is defined by a set of
declaration statements and methods containing executable statements. Smallest
individual units in a program are known as tokens. The compiler recognizes them for
building up expressions and statements. Java language includes five types of tokens.
They are:
Reserved Keywords
Identifiers
Literals
Operators
Separators
Keywords
Keywords are an essential part of a language definition. They implement specific
features of the language. Java language has reserved 50 words as keywords. Since
keywords have specific meaning in Java, we cannot use them as names for variables,
classes, methods and so on. All keywords are to be written in lower-case letters.
Keywords are,
abstr assert boole break switch
act an
byte case catch char synchronize
d
clas const conti default this
s nue
do double else enum throw
exte final finall float throws
nds y
[Link] AP/CS,SCAS 14
Java Programming I [Link] CS & I BCA
for goto if implemen transient
ts
impo instanceo int interface try
rt f
long native new package void
priva protected publi return volatile
te c
short static strictf super while
p
Identifiers
Identifiers are programmer designed tokens. They are used for naming
classes, methods, variables, objects, labels, packages and interfaces in a program. Java
identifiers follow the following
rules:
They can have alphabets, digits and the underscore and dollar sign characters.
They must not begin with a digit.
Uppercase and lowercase letters are distinct.
They can be of any length.
Literals
Literals in Java are a sequence of characters (digits, letters and other
characters) that represent constant values to be stored in variables. Java language
specifies five major types of literals. They are:
i) Integer literals iv) String literals
ii) Floating point literals v) Boolean literals
iii) Character literals
JAVA STATEMENTS
The statements in Java are like sentences in natural languages. A statement is an
executable combination of tokens ending with a semicolon (;) mark. Statements are
usually executed in sequence in the order in which they appear. However, it is possible
to control the flow of execution, if necessary, using special statements. Java implements
several types of statements:
[Link] AP/CS,SCAS 15
Java Programming I [Link] CS & I BCA
JAVA VIRTUAL MACHINE (JVM)
Java compiler produces an intermediate code known as bytecode for a machine
that does not exist. This machine is called the java virtual machine and it exists only
inside the computer memory.
Java Java Virtual
program compiler Machine
Source code Process of compilation Byte
code
he above figure illustrates the process of compiling a java program into
bytecode which is also referred to as virtual machine code. The virtual machine code is
not machine specific. The machine specific code is generated by the java interpreter by
acting as an intermediary between the virtual machine and the real machine as shown in
below figure.
Byte Java Machine
Code Interpreter Code
Virtual machine Real machine
Process of converting byte code into machine code
[Link] AP/CS,SCAS 16