Introduction To Java: Prepared by EBIN PM, AP, IESCE 1
Introduction To Java: Prepared by EBIN PM, AP, IESCE 1
com/c/EDULINEFORCSE
STUDENTS
MODULE 1
CHAPTER 2
INTRODUCTION TO JAVA
JAVA
• Java is a powerful general-purpose , Object Oriented programming
language developed by Sun Micro System of USA in 1991.
• Development team members are James Gosling, Patrick Naughton,
Chris Warth, Ed Frank, and Mike Sheridan
• First name of Java is “Oak,” but was renamed “Java” in 1995.
• Java derives much of its character from C and C++.
• Java Changed the Internet by simplifying web programming
• Java innovated a new type of networked program called the applet
Prepared By EBIN PM, AP, IESCE 2
FEATURES OF JAVA
( Java Buzzwords)
BYTE CODE
• Java byte code is the instruction set for the Java Virtual Machine
• It is the machine code in the form of a .class file.
• Byte code is a machine independent code
• It is not completely a compiled code but it is an intermediate
code somewhere in the middle which is later interpreted and
executed by JVM.
• Byte code is a machine code for JVM.
• Byte code implementation makes Java a platform- Independent
language.
JAVA COMPILER
• Java is compiled language. But it is very different from traditional
compiling in the way that after compilation source code is
converted to byte code.
•Javac is the most popular Java compiler
• Java has a virtual machine called JVM which then converts byte
code to target code of machine on which it is run.
• JVM performs like an interpreter. It doesn’t do it alone, though. It
has its own compiler to convert the byte code to machine code.
This compiler is called Just In Time or JIT compiler.
JAVA APPLET
• An applet is a special kind of Java program that is designed to be
transmitted over the Internet and automatically executed by a
Java-compatible web browser
• It runs inside the web browser and works at client side
• Applets are used to make the web site more dynamic and
entertaining
• Applets are not stand-alone programs. Instead, they run within
either a web browser or an applet viewer. JDK provides a
standard applet viewer tool called applet viewer.
• In general, execution of an applet does not begin at main()
method.
JAVA BUZZWORDS
Simple
• It’s simple and easy to learn if you already know the basic
concepts of Object Oriented Programming.
• C++ programmer can move to JAVA with very little effort to learn.
• Java syntax is based on C++
• Java has removed many complicated and rarely-used features, for
example, explicit pointers, operator overloading, etc.
Object oriented
• Java is 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 can be used in our programs through inheritance.
Distributed
• Java is designed for distributed environment of the Internet. Its
used for creating applications on networks
• Java enables multiple programmers at multiple remote locations
to collaborate and work together on a single project.
Prepared By EBIN PM, AP, IESCE 17
Robust
• It provides many features that make the program execute reliably
in variety of environments.
• Java is a strictly typed language. It checks code both at compile
time and runtime.
• Java takes care of all memory management problems with
garbage-collection.
• Java, with the help of exception handling captures all types of
serious errors and eliminates any risk of crashing the system.
Secure
• Java provides a “firewall” between a networked application and
your computer.
• When a Java Compatible Web browser is used, downloading can
be done safely without fear of viral infection or malicious intent.
• Java achieves this protection by confining a Java program to the
java execution environment and not allowing it to access other
parts of the computer.
Architecture Neutral
• Java language and Java Virtual Machine helped in achieving the
goal of “write once; run anywhere, any time, forever.”
• Changes and upgrades in operating systems, processors and
system resources will not force any changes in Java Programs.
Prepared By EBIN PM, AP, IESCE 20
Portable
• Java is portable because it facilitates you to carry the Java byte
code to any platform. It doesn't require any implementation.
• Java Provides a way to download programs dynamically to all the
various types of platforms connected to the Internet.
High Performance
• Java performance is high because of the use of byte code.
• The byte code can be easily translated into native machine code.
Multithreaded
• Multithreaded Programs handled multiple tasks simultaneously,
which was helpful in creating interactive, networked programs.
• Java run-time system comes with tools that support multiprocess
synchronization used to construct smoothly interactive systems
Dynamic
• Java is capable of linking in new class libraries, methods, and
objects.
• It supports functions from native languages (the functions written
in other languages such as C and C++).
• It supports dynamic loading of classes. It means classes are
loaded on demand
Prepared By EBIN PM, AP, IESCE 22
Documentation Section
• You can write a comment in this section. It helps to understand
the code. These are optional
• It is used to improve the readability of the program.
• The compiler ignores these comments during the time of
execution
• There are three types of comments that Java supports
Single line Comment //This is single line comment
Multi-line Comment /* this is multiline comment.
and support multiple lines*/
Documentation Comment /** this is documentation cmnt*/
Prepared By EBIN PM, AP, IESCE 24
Package Statement
• We can create a package with any name. A package is a group of
classes that are defined by a name.
• That is, if you want to declare many classes within one element,
then you can declare it within a package
• It is an optional part of the program, i.e., if you do not want to
declare any package, then there will be no problem with it, and
you will not get any errors.
• Package is declared as: package package_name;
Eg: package mypackage;
Import Statement
• If you want to use a class of another package, then you can do
this by importing it directly into your program.
• Many predefined classes are stored in packages in Java
• We can import a specific class or classes in an import statement.
Examples:
import java.util.Date; //imports the date class
Interface Statement
• This section is used to specify an interface in Java
• Interfaces are like a class that includes a group of method
declarations
• It's an optional section and can be used when programmers want
to implement multiple inheritances within a program.
Class Definition
• A Java program may contain several class definitions.
• Classes are the main and essential elements of any Java program.
• A class is a collection of variables and methods
String[] args
It is an array where each element is a string, which is named as args.
If you run the Java code through a console, you can pass the input
parameter. The main() takes it as an input.
System.out.println();
• This statement is used to print text on the screen as output
• system is a predefined class, and out is an object of the PrintWriter
class defined in the system
• The method println prints the text on the screen with a new line.
• We can also use print() method instead of println() method. All
Java statement ends with a semicolon.
Prepared By EBIN PM, AP, IESCE 31
Keywords
• A keyword is a reserved word. You cannot use it as a variable
name, constant name etc.
• The meaning of the keywords has already been described to the
java compiler. These meaning cannot be changed.
• Thus, the keywords cannot be used as variable names because
that would try to change the existing meaning of the keyword,
which is not allowed.
• Java language has reserved 50 words as keywords
Identifiers
• Identifiers are the names of variables, methods, classes, packages and
interfaces
• Identifier must follow some rules.
All identifiers must start with either a letter( a to z or A to Z ) or currency
character($) or an underscore.
They must not begin with a digit
After the first character, an identifier can have any combination of
characters.
A Java keywords cannot be used as an identifier.
Identifiers in Java are case sensitive, foo and Foo are two different
identifiers.
They can be any length Eg: int a; char name;
Prepared By EBIN PM, AP, IESCE 40
Constants or Literals
• Constants are fixed values of a particular type of data,which cannot
be modified in a program.
• Java language specifies five major type of literals.
String
• In java, string is basically an object that represents sequence of char
values.
• An array of characters works same as java string.
Eg: char[] ch = {'a','t','n','y','l','a'};
String s = "atnyla";
Special symbol
Operators
• An operator is a symbol that takes one or more arguments and
operates on them to produce a result.
• Unary Operator
• Arithmetic Operator
• shift Operator
• Relational Operator
• Bitwise Operator
• Logical Operator
• Ternary Operator
• Assignment Operator
Whitespace
• Java is a free-form language. This means that you do not need to
follow any special indentation rules
• White space in Java is used to separate tokens in the source file. It
is also used to improve readability of the source code.
Eg: int i = 0;
• White spaces are required in some places. For example between
the int keyword and the variable name.
• In java whitespace is a space, tab, or newline