SlideShare a Scribd company logo
Java chapter  1 basic introduction Unit-1.pptx
Overview of Java
 A general-purpose Object-Oriented language
 Developed by Sun Microsystems, later acquired by
Oracle Corporation
 Java can be used to develop
 Stand alone applications
 Web applications.
 applications for hand-held devices such as Palm
and cell phones
History of Java
 Developed by a team led by James Gosling at Sun
Microsystems in 1991 for use in embedded chips .
 Originally called Oak.
 In 1995 redesigned for developing Internet
applications and renamed as Java
 HotJava - The first Java-enabled Web browser (1995)
 JDK Evolutions
Java Standards
Computer languages have strict rules of usage. Java standards
are defined by
• The Java language specification and
• Java API
The Java language specification is a technical definition of the
language that includes the syntax and semantics of the Java
programming language.
The Application Program Interface (API) contains predefined
classes and interfaces for developing Java programs.
Java language specification is stable, but the API is still
Editions of Java
 Java Standard Edition (SE)
used to develop client-side standalone applications or
applets.
 Java Enterprise Edition (EE)
used to develop server-side applications such as Java
servlets and Java ServerPages.
 Java Micro Edition (ME).
used to develop applications for mobile devices such as cell
phones.
Java Card: A technology that allows small Java-based
applications to be run securely on smart cards and similar
small-memory devices.
Java Development Kit (JDK)
JDK consists of a set of separate programs, each invoked from
a command line, for developing and testing Java programs.
There are many versions of Java SE.
JDK 1.02 (1995)
JDK 1.1 (1996)
Java 2 SDK v 1.2 (JDK 1.2, 1998)
Java 2 SDK v 1.3 (JDK 1.3, 2000)
Java 2 SDK v 1.4 (JDK 1.4, 2002)
and so on…
The latest is JDK1.8
We will be using JDK1.7
Integrated Development Environment (IDE)
 Besides JDK, a Java development tool—software that
provides an integrated development environment (IDE) for
rapidly developing Java programs can be used.
 Editing, compiling, building, debugging, and online help
are integrated in one graphical user interface.
• Borland Jbuilder
• Microsoft Visual J++
• Net Beans
• Eclipse
• BlueJ
We will be using plain text editor (preferably Notepad)
Characteristics of Java (Best Practices)
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
Java is partially modeled on C++, but
greatly simplified and improved
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
Java is inherently object-oriented. Object-
oriented programming provides great
flexibility, modularity, clarity, and
reusability through encapsulation,
inheritance, and polymorphism
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
Distributed computing involves several
computers working together on a
network. Java is designed to make
distributed computing easy.
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
You need an interpreter to run Java
programs. The programs are compiled
into the Java Virtual Machine code called
bytecode. The bytecode is machine-
independent and can run on any machine
that has a Java interpreter, which is part of
the Java Virtual Machine (JVM).
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
Java compilers can detect many problems
that would first show up at execution time
in other languages.
Java has eliminated certain types of error-
prone programming constructs found in
other languages.
Java has a runtime exception-handling
feature to provide programming support
for robustness.
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
Java implements several security
mechanisms to protect your system
against harm caused by stray programs.
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
Write once, run anywhere
With a Java Virtual Machine (JVM), you can
write one program that will run on any
platform.
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
Because Java is architecture neutral, Java
programs are portable. They can be run
on any platform without being
recompiled.
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
Java’s performance Because Java is
architecture neutral, Java programs are
portable. They can be run on any platform
without being recompiled.
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
Multithread programming is smoothly
integrated in Java, whereas in other
languages you have to call procedures
specific to the operating system to enable
multithreading.
Characteristics of Java
• Java Is Simple
• Java Is Object-Oriented
• Java Is Distributed
• Java Is Interpreted
• Java Is Robust
• Java Is Secure
• Java Is Architecture-Neutral
• Java Is Portable
• Java's Performance
• Java Is Multithreaded
• Java Is Dynamic
Java was designed to adapt to an evolving
environment. New code can be loaded on
the fly without recompilation. There is no
need for developers to create, and for
users to install, major new software
versions. New features can be
incorporated transparently as needed.
Sample Java Program
package sample;
import java.lang.*; // Optional
public class Welcome
{
public static void main(String[] args)
{
System.out.println("Welcome to Java!");
}
}
Creating, Compiling and Executing Java Program
• Use any text editor or IDE to create and edit a Java source-
code file
• The source file must end with the extension .java and must
have exactly the same name as the public class name
Welcome.java
• Compile the .java file into java byte code file (Java bytecode
is the instruction set of the Java virtual machine)
javac Welcome.java
If there are no syntax errors, the compiler generates a
bytecode file
with .class extension
Creating, Compiling and Executing Java Program
Java Runtime Environment (JRE) and Java Virtual Machine
(JVM)
JDK
The JDK includes the JRE plus command-line development
tools such as compilers and debuggers that are necessary or
useful for developing applets and applications
JRE
The JRE provides the libraries, Java virtual machine, and
other components necessary for you to run applets and
applications written in the Java programming language
JVM
The Java virtual machine is an abstract computing machine
that has an instruction set and manipulates memory at run
time. The Java virtual machine is ported to different
platforms to provide hardware- and operating system-
independence.
Java Runtime Environment (JRE) and Java Virtual Machine
(JVM)
Java Development Kit
(JDK)
Java Language
Development Tools and APIs
java, javac, Javadoc
Java Runtime Environment (JRE)
User Interface Toolkits - AWT,
Swing
Libraries
Java Virtual Machine (JVM)
Deployment Technology
ECLIPSE IDE
• ECLIPSE is an integrated development environment used in computer programming.
• It contains a base workspace and an extensible plug-in system for customizing the
environment.
26
WORKBENCH TERMINOLOGY
Tool bar
Perspective
and
Fast View
bar
Resource
Navigator
view
Stacked
views
Properties
view
Tasks
view
Outline
view
Bookmarks
view
Menu bar
Message
area
Editor
Status
area
Text
editor
27
JAVA PERSPECTIVE
• JAVA-CENTRIC VIEW OF FILES IN JAVA PROJECTS
• JAVA ELEMENTS MEANINGFUL FOR JAVA PROGRAMMERS
Java
project
package
class
field
method
Java
editor
28
JAVA PERSPECTIVE
• SEARCH FOR JAVA ELEMENTS
• DECLARATIONS OR REFERENCES
• INCLUDING LIBRARIES AND OTHER PROJECTS
Hits
flagged
in margin
of editor
All search
results
LEARNING INTELLISENSE
• Intellisense is a general term for various code editing features including: code
completion, parameter info, quick info, and member lists.
• Intellisense features are sometimes called by other names such as "code completion",
"content assist", and "code hinting."
INTRODUCTION TO OOPS CONCEPTS
• ORIENTED PROGRAMMING IS A PARADIGM THAT PROVIDES MANY CONCEPTS, SUCH
AS INHERITANCE, DATA BINDING, POLYMORPHISM, ETC.
• SIMULA IS CONSIDERED THE FIRST OBJECT-ORIENTED PROGRAMMING LANGUAGE.
• SMALLTALK IS CONSIDERED THE FIRST TRULY OBJECT-ORIENTED PROGRAMMING
LANGUAGE.
• THE POPULAR OBJECT-ORIENTED LANGUAGES ARE JAVA, C#, PHP, PYTHON, C++, ETC.
OOPS CONCEPTS
• OBJECT
• CLASS
• METHOD
• ATTRIBUTE
BASIC TERMINOLOGY
OBJECT
• - USUALLY A PERSON, PLACE OR THING (A NOUN)
METHOD
• - AN ACTION PERFORMED BY AN OBJECT (A VERB)
ATTRIBUTE
• - DESCRIPTION OF OBJECTS IN A CLASS
CLASS
• - A CATEGORY OF SIMILAR OBJECTS (SUCH AS AUTOMOBILES)
• - DOES NOT HOLD ANY VALUES OF THE OBJECT’S ATTRIBUTES
32
33
DESIGN PRINCIPLES OF OOP
Four main design principles of Object-oriented Programming(OOP):
Encapsulation
Abstraction
Polymorphism
Inheritance
OBJECT
• Any entity that has state and behavior is known as an object. For example, A chair, pen, table,
keyboard, bike, etc. It can be physical or logical.
• An object can be defined as an instance of a class. An object contains an address and takes up
some space in memory.
CLASS
• Collection of objects is called class. It is a logical entity.
• A class can also be defined as a blueprint from which you can create an
individual object. Class doesn't consume any space.
Role of Java in the IT Industry
1. WEB DEVELOPMENT
Server Side Technologies: SPRING FRAMEWORK, SPRING BOOT, GRAILS
Java Application Servers: TOMCAT
2. ANDROID APPLICATION:
ANDROID STUDIO, ECLIPSE, AVD MANAGER, INTELLIJ IDEA
3. BIG DATA
HADOOP, SPARK, CASSANDRA, SPRING BOOT, ELASTICSEARCH
4. DEVOPS
JENKINS, VISUAL STUDIO IDE, DOCKER AND KUBERNETES
5. DESKTOPAPPLICATIONS
SWING, AWT, JAVAFX
VARIABLES
37
• The name of some location of memory used to hold a data value
• Different types of data require different amounts of memory. The compiler’s job is to reserve
sufficient memory
• Variables need to be declared once
• Variables are assigned values, and these values may be changed later
• Each variable has a type, and operations can only be performed between compatible types
• Example
int width = 3;
int height = 4;
int area = width * height;
width = 6;
area = width * height;
4
3
height
area
width
3
4
12
24
6
12
width
height
area
VARIABLE NAMES
38
• Valid variable names: these rules apply to all java names, or identifiers, including
methods and class names
• Starts with: a letter (a-z or A-Z), dollar sign ($), or underscore (_)
• Followed by: zero or more letters, dollar signs, underscores, or digits (0-9).
• Uppercase and lowercase are different (total ≠ Total ≠ TOTAL)
• Cannot be any of the reserved names. These are special names (keywords) reserved
for the compiler. Examples:
class, float, int, if, then, else, do, public, private, void, …
GOOD VARIABLE NAMES
39
• Choosing good names not all valid variable names are good variable names
• Some guidelines:
• Do not use `$’ (it is reserved for special system names.)
• Avoid names that are identical other than differences in case (total, Total, and TOTAL).
• Use meaningful names, but avoid excessive length
• crITm  too short
• theCurrentItembeingProcessed  too long
• currentItem just right
• Camel case capitalization style
• In Java we use camel case
• Variables and methods start with lower case
dataList2 myFavoriteMartian showMeTheMoney
• Classes start with uppercase
String JOptionPane MyfavoriteClass
VALID/INVALID IDENTIFIERS
40
VALID:
$$_
R2D2
INT OKAY. “INT” IS RESERVED, BUT CASE IS DIFFERENT
HERE
_dogma_95_
riteOnThru
SchultzieVonWienerschnitzeliii
INVALID:
30DayAbs Starts With A Digit
2 Starts with a digit
pork&beans `&’ IS ILLEGAL
private reserved name
C-3PO `-’ IS ILLEGAL
Java chapter  1 basic introduction Unit-1.pptx
PRIMITIVE DATA TYPES
42
• Java’s basic data types:
• Integer types:
• Byte 1 byte range: -128 to +127
• Short 2 bytes range: roughly -32 thousand to +32 thousand
• Int 4 bytes range: roughly -2 billion to +2 billion
• Long 8 bytes range: huge!
• Floating-point types (for real numbers):
• Float 4 bytes roughly 7 digits of precision
• Double 8 bytes roughly 15 digits of precision
• Other types:
• Boolean 1 byte {true, false} (used in logic expressions and conditions)
• Char 2 bytes A single (unicode) character
• String is not a primitive data type (they are objects)
43
NUMERIC CONSTANTS (LITERALS)
• Specifying constants: (also called literals) for primitive data types.
Integer types:
Byte
Short optional sign and digits (0-9): 12 -1 +234 0 1234567
Int
Long same as above, but followed by ‘L’ or ‘l’: -1394382953L
Floating-point types:
Double two allowable forms:
Decimal notation: 3.14159 -234.421 0.0042 -43.0
Scientific notation: (use E or e for base 10 exponent)
3.145e5 = 3.145 x 105 = 314500.0
1834.23e-6 = 1834.23 x 10-6 = 0.00183423
Float same as double, but followed by ‘f’ or ‘F’: 3.14159f -43.2f
Note: By default, integer constants are int, unless ‘L’/‘l’ is used to indicate
they are long. Floating constants are double, unless ‘F’/‘f’ is used to
indicate they are float.
Avoid this lowercase L. It looks
too much like the digit ‘1’
44
CHARACTER AND STRING CONSTANTS
• Char constants: single character enclosed in single quotes (‘…’) including:
• Letters and digits: ‘A’, ‘B’, ‘C’, …, ‘a’, ‘b’, ‘c’, …, ‘0’, ‘1’, …, ‘9’
• Punctuation symbols: ‘*’, ‘#’, ‘@’, ‘$’ (except single quote and backslash ‘’)
• Escape sequences: (see below)
• String constants: zero or more characters enclosed in double quotes (“…”)
• (same as above, but may not include a double quote or backslash)
• Escape sequences: allows us to include single/double quotes and other special characters:
” Double quote n new-line character (start a new line)
’ Single quote t tab character
 Backslash
• Examples: char x = ’’’  (x contains a single quote)
””Hi there!””  ”Hi there!”
”C:WINDOWS”  C:WINDOWS
system.Out.Println( ”Line 1nLine 2” ) prints
Line 1
Line 2
DATA TYPES AND VARIABLES
45
• Java  strongly-type language
• Strong Type Checking  Java checks that all expressions involve compatible types
• int x, y; // x and y are integer variables
• double d; // d is a double variable
• String s; // s is a string variable
• boolean b; // b is a boolean variable
• char c; // c is a character variable
• x = 7; // legal (assigns the value 7 to x)
• b = true; // legal (assigns the value true to b)
• c = ‘#’; // legal (assigns character # to c)
• s = “cat” + “bert”; // legal (assigns the value “catbert” to s)
• d = x – 3; // legal (assigns the integer value 7 – 3 = 4 to double d)
• b = 5; // illegal! (cannot assign int to boolean)
• y = x + b; // illegal! (cannot add int and boolean)
• c = x; // illegal! (Cannot assign int to char)
NUMERIC OPERATORS
46
• Arithmetic Operators:
• Unary negation: -x
• Multiplication/division: x * y x/y
• Division between integer types truncates to integer: 23/4  5
• X % y returns the remainder of x divided by y: 23%4  3
• Division with real types yields a real result: 23.0/4.0  5.75
• Addition/subtraction: x+y x-y
• Comparison Operators:
• Equality/inequality: x == y x != y
• Less than/greater than: x < y x > y
• Less than or equal/greater than or equal: x <= y x >= y
• These comparison operators return a boolean value: true or false.
COMMON STRING OPERATORS
47
• String Concatenation: The ‘+’ Operator Concatenates (Joins) Two Strings.
• “Von” + “Wienerschnitzel”  “Vonwienerschnitzel”
• When a string is concatenated with another type, the other type is first evaluated and converted into its string
representation
(8*4) + “Degrees”  “32degrees” (1 + 2) + “5”  “35”
• String Comparison: Strings should not be compared using the above operators (==, <=, <, etc). Let s and t be strings.
• s.equals(t)  returns true if s equals t
• s.length()  returns length
• s.compareTo(t)  compares strings lexicographically (dictionary order)
• result < 0 if s is less than t
• result == 0 if s is equal to t
• result > 0 if s is greater than t
Note: Concatenation
does
not add any space
JAVA OPERATORS
• Operators are used to perform operations on variables and values.
int x = 100 + 50; //output=150
ARITHMETIC OPERATORS
Operator Name Description Example
+ Addition Adds together two values x + y
- Subtraction Subtracts one value from
another
x - y
* Multiplication Multiplies two values x * y
/ Division Divides one value by another x / y
% Modulus Returns the division
remainder
x % y
++ Increment Increases the value of a
variable by 1
++x
-- Decrement Decreases the value of a
variable by 1
--x
ASSIGNMENT OPERATORS
Operator Example Same As
= x = 5 x = 5
+= x += 3 x = x + 3
-= x -= 3 x = x - 3
*= x *= 3 x = x * 3
/= x /= 3 x = x / 3
%= x %= 3 x = x % 3
&= x &= 3 x = x & 3
|= x |= 3 x = x | 3
^= x ^= 3 x = x ^ 3
>>= x >>= 3 x = x >> 3
<<= x <<= 3 x = x << 3
COMPARISON OPERATORS
Operator Name Example
== Equal to x == y
!= Not equal x != y
> Greater than x > y
< Less than x < y
>= Greater than or equal to x >= y
<= Less than or equal to x <= y
LOGICAL OPERATORS
Operator Name Description Example
&& Logical and Returns true if both statements are true x < 5 && x < 10
|| Logical or Returns true if one of the statements is true x < 5 || x < 4
! Logical not Reverse the result, returns false if the result is
true
!(x < 5 && x < 10)
TERNARY OPERATOR
condition ? if true : if false
The above statement means that if the condition evaluates to true, then execute the
statements after the ‘?’ else execute the statements after the ‘:’.
BITWISE OPERATORS
• &: Bitwise AND operator: returns bit by bit AND of input values.
• |: Bitwise OR operator: returns bit by bit or of input values.
• ^: Bitwise XOR operator: returns bit-by-bit xor of input values.
• ~: Bitwise Complement operator: this is a unary operator which returns the
one’s complement representation of the input value, i.e., With all bits inverted.
SHIFT OPERATORS
• <<: Left shift operator: shifts the bits of the number to the left and fills 0 on voids left
as a result. Similar effect as multiplying the number with some power of two.
• >>: Signed right shift operator: shifts the bits of the number to the right and fills 0 on
voids left as a result. The leftmost bit depends on the sign of the initial number. Similar
effect to dividing the number with some power of two.
• >>>: Unsigned right shift operator: shifts the bits of the number to the right and fills
0 on voids left as a result. The leftmost bit is set to 0.
JAVA OPERATOR PRECEDENCE AND
ASSOCIATIVITY
Precedence Operator Type Associativity
15 ()
[]
·
Parentheses
Array subscript
Member selection
Left to Right
14 ++
--
Unary post-increment
Unary post-decrement
Right to left
13 ++
--
+
-
!
~
(type)
Unary pre-increment
Unary pre-decrement
Unary plus
Unary minus
Unary logical negation
Unary bitwise complement
Unary type cast
Right to left
12 *
/
%
Multiplication
Division
Modulus
Left to right
11 +
-
Addition
Subtraction
Left to right
JAVA OPERATOR PRECEDENCE AND
ASSOCIATIVITY
Precedence Operator Type Associativity
10 <<
>>
>>>
Bitwise left shift
Bitwise right shift with sign extension
Bitwise right shift with zero extension
Left to right
9 <
<=
>
>=
instanceof
Relational less than
Relational less than or equal
Relational greater than
Relational greater than or equal
Type comparison (objects only)
Left to right
8 ==
!=
Relational is equal to
Relational is not equal to
Left to right
JAVA OPERATOR PRECEDENCE AND
ASSOCIATIVITY
Precedence Operator Type Associativity
7 & Bitwise AND Left to right
6 ^ Bitwise exclusive OR Left to right
5 | Bitwise inclusive OR Left to right
4 && Logical AND Left to right
3 || Logical OR Left to right
2 ? : Ternary conditional Right to left
1 =
+=
-=
*=
/=
%=
Assignment
Addition assignment
Subtraction assignment
Multiplication assignment
Division assignment
Modulus assignment
Right to left
TYPE CASTING
• Type casting is when you assign a value of one primitive data type to another type.
• In Java, there are two types of casting:
• Widening Casting (automatically) - converting a smaller type to a larger type size
Byte -> short -> char -> int -> long -> float -> double
• Narrowing Casting (manually) - converting a larger type to a smaller size type
Double -> float -> long -> int -> char -> short -> byte
WIDENING CASTING
• Widening casting is done automatically when passing a smaller size type to a larger size type:
Example:
public class Main {
public static void main(String[] args) {
int myInt = 9;
double myDouble = myInt; // Automatic casting: int to double
System.out.println(myInt); // Outputs 9
System.out.println(myDouble); // Outputs 9.0
}
}
OUTPUT:
9
9.0
NARROWING CASTING
• Narrowing casting must be done manually by placing the type in parentheses in front of the value.
Example:
public class Main {
public static void main(String[] args) {
double myDouble = 9.78d;
int myInt = (int) myDouble; // Manual casting: double to int
System.out.println(myDouble); // Outputs 9.78
System.out.println(myInt); // Outputs 9
}
}
OUTPUT:
9.78
9
NAMING CONVENTION
• CamelCase in Java naming conventions
• Java follows camel-case syntax for naming the class, interface, method, and variable.
• If the name is combined with two words, the second word will start with uppercase letter
always such as actionPerformed(), firstName, ActionEvent, ActionListener, etc.
NAMING CONVENTION
Identifiers Type Naming Rules Examples
Class It should start with the uppercase letter.
It should be a noun such as Color, Button, System, Thread,
etc.
Use appropriate words, instead of acronyms.
public class Employee
{
//code snippet
}
Interface It should start with the uppercase letter.
It should be an adjective such as Runnable, Remote,
ActionListener.
Use appropriate words, instead of acronyms.
interface Printable
{
//code snippet
}
Method It should start with lowercase letter.
It should be a verb such as main(), print(), println().
If the name contains multiple words, start it with a lowercase
letter followed by an uppercase letter such as
actionPerformed().
class Employee
{
// method
void draw()
{
//code snippet
}
}
NAMING CONVENTION
Identifiers Type Naming Rules Examples
Variable It should start with a lowercase letter such as id, name.
It should not start with the special characters like &
(ampersand), $ (dollar), _ (underscore).
If the name contains multiple words, start it with the lowercase
letter followed by an uppercase letter such as firstName,
lastName.
Avoid using one-character variables such as x, y, z.
class Employee
{
// variable
int id;
//code snippet
}
Package It should be a lowercase letter such as java, lang.
If the name contains multiple words, it should be separated by
dots (.) such as java.util, java.lang.
//package
package com.javatpoint;
class Employee
{
//code snippet
}
Constant It should be in uppercase letters such as RED, YELLOW.
If the name contains multiple words, it should be separated by
an underscore(_) such as MAX_PRIORITY.
It may contain digits but not as the first letter.
class Employee
{
//constant
static final int MIN_AGE = 18;
//code snippet
JAVA CODING STANDARDS AND BEST
PRACTICES
• Efficient string concatenation:- For making a long string by adding different small strings always use append
method of java.Lang.Stringbuffer and never use ordinary ‘+’ operator for adding up strings.
• Optimal use of garbage collector: - For easing out the work of java garbage collector always set all
referenced variables used to ‘null’ Explicitly thus de-referencing the object which is no more required by the
application and allowing. Garbage collector to swap away that variable thus realizing memory.
• Writing oracle stored procedures optimally:- Avoid using ‘IN’ and ‘NOT IN’ clause and rather try to use
‘OR’ operator for increasing the response time for the oracle stored procedures.
• Using variables in any code optimally:- Try to make minimum number of variables in JSP/java class and
try to use already made variables in different algorithms shared in same JSP/java class by setting already populated
variable to ‘null’ and then again populating that variable with new value and then reusing them.
JAVA CODING STANDARDS AND BEST
PRACTICES
• Try to write minimum java code in JSPS:- big patches of java code in JSP should be avoided and
is should be rather shifted to some wrapper/helper/bean class which should be used together with
every JSP.
• Try to reduce the number of hits to database:- number of hits to the database should be reduced
to minimum by getting data in a well arranged pattern in minimum number of hits by making the
best use of joins in the database query itself rather than getting dispersed data in more number of
hits.
• Caching of EJB references:- to avoid costly lookup every time any remote object is required, its
better to cache the home reference and reusing it.
JAVA CODING STANDARDS AND BEST
PRACTICES
• Heavy objects should not be stored in session of JSPS:- storing heavy objects in the session can
lead to slowing of the running of the JSP page so such case should be avoided.
• Always use JDBC connection pooling:- always use javax.Sql.Datasource which is obtained
through a JNDI naming lookup. Avoid the overhead of acquiring a javax.Sql.Datasource for each SQL
access.
• Release HTTPSESSIONS when finished:- abandoned httpsessions can be quite high.Httpsession
objects live inside the engine until the application explicitly and programmatically releases it using the
API, javax.Servlet.Http.Httpsession.Invalidate (); quite often, programmatic invalidation is part of an
application logout function.
• Release JDBC resources when done:- failing to close and release jdbc connections can cause other
users to experience long waits for connections.
JAVA CODING STANDARDS AND BEST
PRACTICES
• Minimize use of system.Out.Println:- because it seems harmless, this commonly used application development
legacy is overlooked for the performance problem it really is.
• Minimum use of java.Util.Vector:- since most of the commonly used methods in vector class are synchronized
which makes any method call or any variable heavy as compared to those which are not synchronized so it’s a
better practice to use any other collection sibling whose methods are not synchronized for eg. Java.Util.Arraylist.
• Synchronization has a cost:- putting synchronized all over the place does not ensure thread safety.
• Using JS files and other include files in jar:- when we are developing web based large number of include file.
All includes file must be put in jar and accessed which is very fast.
JAVA COMMENTS
• Single-line comments
Single-line comments start with two forward slashes (//).
• Multi-line comments
Multi-line comments start with /* and ends with */.
IDENTIFIERS
Ad

More Related Content

Similar to Java chapter 1 basic introduction Unit-1.pptx (20)

Introduction to java
Introduction to java Introduction to java
Introduction to java
Java Lover
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Krunali Gandhi
 
1. Java Project Guidance for engineering
1. Java Project Guidance for engineering1. Java Project Guidance for engineering
1. Java Project Guidance for engineering
vyshukodumuri
 
Introduction to Core Java feature and its characteristics
Introduction to Core Java feature and its characteristicsIntroduction to Core Java feature and its characteristics
Introduction to Core Java feature and its characteristics
rashmishekhar81
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
Saba Ameer
 
Java Programming
Java ProgrammingJava Programming
Java Programming
Elizabeth alexander
 
Ch2
Ch2Ch2
Ch2
Uğurcan Uzer
 
java intro.pptx
java intro.pptxjava intro.pptx
java intro.pptx
MangaiyarkarasiDurai
 
Java ppt1
Java ppt1Java ppt1
Java ppt1
nikhilsh66131
 
Learn Java Part 1
Learn Java Part 1Learn Java Part 1
Learn Java Part 1
Gurpreet singh
 
What is-java
What is-javaWhat is-java
What is-java
Shahid Rasheed
 
Lecture-01 _Java Introduction CS 441 Fast
Lecture-01 _Java Introduction CS 441 FastLecture-01 _Java Introduction CS 441 Fast
Lecture-01 _Java Introduction CS 441 Fast
UzairSaeed18
 
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptxJAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
JAVA PROGRAM CONSTRUCTS OR LANGUAGE BASICS.pptx
AALIM MUHAMMED SALEGH COLLEGE OF ENGINEERING
 
Unit1 JAVA.pptx
Unit1 JAVA.pptxUnit1 JAVA.pptx
Unit1 JAVA.pptx
RahulAnand111531
 
Java (1)
Java (1)Java (1)
Java (1)
Samraiz Tejani
 
INTRODUCTION_O1.pptx
INTRODUCTION_O1.pptxINTRODUCTION_O1.pptx
INTRODUCTION_O1.pptx
sukhpreetsingh295239
 
Java
JavaJava
Java
sasi saseenthiran
 
1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptx1 Module 1 Introduction.pptx
1 Module 1 Introduction.pptx
BhargaviDalal3
 
2 22CA026_Advance Java Programming_Data types and Operators.pptx
2 22CA026_Advance Java Programming_Data types and Operators.pptx2 22CA026_Advance Java Programming_Data types and Operators.pptx
2 22CA026_Advance Java Programming_Data types and Operators.pptx
dolphiverma80
 
1.Intro--Why Java.pptx
1.Intro--Why Java.pptx1.Intro--Why Java.pptx
1.Intro--Why Java.pptx
YounasKhan542109
 

Recently uploaded (20)

Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Introduction to Additive Manufacturing(3D printing)
Introduction to Additive Manufacturing(3D printing)Introduction to Additive Manufacturing(3D printing)
Introduction to Additive Manufacturing(3D printing)
vijimech408
 
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic AlgorithmDesign Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Design Optimization of Reinforced Concrete Waffle Slab Using Genetic Algorithm
Journal of Soft Computing in Civil Engineering
 
Deepfake Phishing: A New Frontier in Cyber Threats
Deepfake Phishing: A New Frontier in Cyber ThreatsDeepfake Phishing: A New Frontier in Cyber Threats
Deepfake Phishing: A New Frontier in Cyber Threats
RaviKumar256934
 
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
ssuserd9338b
 
VISHAL KUMAR SINGH Latest Resume with updated details
VISHAL KUMAR SINGH Latest Resume with updated detailsVISHAL KUMAR SINGH Latest Resume with updated details
VISHAL KUMAR SINGH Latest Resume with updated details
Vishal Kumar Singh
 
Urban Transport Infrastructure September 2023
Urban Transport Infrastructure September 2023Urban Transport Infrastructure September 2023
Urban Transport Infrastructure September 2023
Rajesh Prasad
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
AI Chatbots & Software Development Teams
AI Chatbots & Software Development TeamsAI Chatbots & Software Development Teams
AI Chatbots & Software Development Teams
Joe Krall
 
Python Functions, Modules and Packages
Python Functions, Modules and PackagesPython Functions, Modules and Packages
Python Functions, Modules and Packages
Dr. A. B. Shinde
 
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Using the Artificial Neural Network to Predict the Axial Strength and Strain ...
Journal of Soft Computing in Civil Engineering
 
Domain1_Security_Principles --(My_Notes)
Domain1_Security_Principles --(My_Notes)Domain1_Security_Principles --(My_Notes)
Domain1_Security_Principles --(My_Notes)
efs14135
 
698642933-DdocfordownloadEEP-FAKE-PPT.pptx
698642933-DdocfordownloadEEP-FAKE-PPT.pptx698642933-DdocfordownloadEEP-FAKE-PPT.pptx
698642933-DdocfordownloadEEP-FAKE-PPT.pptx
speedcomcyber25
 
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation RateModeling the Influence of Environmental Factors on Concrete Evaporation Rate
Modeling the Influence of Environmental Factors on Concrete Evaporation Rate
Journal of Soft Computing in Civil Engineering
 
PYTHON--QUIZ-1_20250422_002514_0000.pptx
PYTHON--QUIZ-1_20250422_002514_0000.pptxPYTHON--QUIZ-1_20250422_002514_0000.pptx
PYTHON--QUIZ-1_20250422_002514_0000.pptx
rmvigram
 
ldr darkness sensor circuit.pptx for engineers
ldr darkness sensor circuit.pptx for engineersldr darkness sensor circuit.pptx for engineers
ldr darkness sensor circuit.pptx for engineers
PravalikaChidurala
 
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
SanjeetMishra29
 
vtc2018fall_otfs_tutorial_presentation_1.pdf
vtc2018fall_otfs_tutorial_presentation_1.pdfvtc2018fall_otfs_tutorial_presentation_1.pdf
vtc2018fall_otfs_tutorial_presentation_1.pdf
RaghavaGD1
 
Frontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend EngineersFrontend Architecture Diagram/Guide For Frontend Engineers
Frontend Architecture Diagram/Guide For Frontend Engineers
Michael Hertzberg
 
Introduction to Additive Manufacturing(3D printing)
Introduction to Additive Manufacturing(3D printing)Introduction to Additive Manufacturing(3D printing)
Introduction to Additive Manufacturing(3D printing)
vijimech408
 
Deepfake Phishing: A New Frontier in Cyber Threats
Deepfake Phishing: A New Frontier in Cyber ThreatsDeepfake Phishing: A New Frontier in Cyber Threats
Deepfake Phishing: A New Frontier in Cyber Threats
RaviKumar256934
 
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
IPC-7711D-7721D_ EN 2023 TOC Rework, Modification and Repair of Electronic As...
ssuserd9338b
 
VISHAL KUMAR SINGH Latest Resume with updated details
VISHAL KUMAR SINGH Latest Resume with updated detailsVISHAL KUMAR SINGH Latest Resume with updated details
VISHAL KUMAR SINGH Latest Resume with updated details
Vishal Kumar Singh
 
Urban Transport Infrastructure September 2023
Urban Transport Infrastructure September 2023Urban Transport Infrastructure September 2023
Urban Transport Infrastructure September 2023
Rajesh Prasad
 
Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025Transport modelling at SBB, presentation at EPFL in 2025
Transport modelling at SBB, presentation at EPFL in 2025
Antonin Danalet
 
Automatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and BeyondAutomatic Quality Assessment for Speech and Beyond
Automatic Quality Assessment for Speech and Beyond
NU_I_TODALAB
 
Personal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.pptPersonal Protective Efsgfgsffquipment.ppt
Personal Protective Efsgfgsffquipment.ppt
ganjangbegu579
 
AI Chatbots & Software Development Teams
AI Chatbots & Software Development TeamsAI Chatbots & Software Development Teams
AI Chatbots & Software Development Teams
Joe Krall
 
Python Functions, Modules and Packages
Python Functions, Modules and PackagesPython Functions, Modules and Packages
Python Functions, Modules and Packages
Dr. A. B. Shinde
 
Domain1_Security_Principles --(My_Notes)
Domain1_Security_Principles --(My_Notes)Domain1_Security_Principles --(My_Notes)
Domain1_Security_Principles --(My_Notes)
efs14135
 
698642933-DdocfordownloadEEP-FAKE-PPT.pptx
698642933-DdocfordownloadEEP-FAKE-PPT.pptx698642933-DdocfordownloadEEP-FAKE-PPT.pptx
698642933-DdocfordownloadEEP-FAKE-PPT.pptx
speedcomcyber25
 
PYTHON--QUIZ-1_20250422_002514_0000.pptx
PYTHON--QUIZ-1_20250422_002514_0000.pptxPYTHON--QUIZ-1_20250422_002514_0000.pptx
PYTHON--QUIZ-1_20250422_002514_0000.pptx
rmvigram
 
ldr darkness sensor circuit.pptx for engineers
ldr darkness sensor circuit.pptx for engineersldr darkness sensor circuit.pptx for engineers
ldr darkness sensor circuit.pptx for engineers
PravalikaChidurala
 
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
🚀 TDX Bengaluru 2025 Unwrapped: Key Highlights, Innovations & Trailblazer Tak...
SanjeetMishra29
 
vtc2018fall_otfs_tutorial_presentation_1.pdf
vtc2018fall_otfs_tutorial_presentation_1.pdfvtc2018fall_otfs_tutorial_presentation_1.pdf
vtc2018fall_otfs_tutorial_presentation_1.pdf
RaghavaGD1
 
Ad

Java chapter 1 basic introduction Unit-1.pptx

  • 2. Overview of Java  A general-purpose Object-Oriented language  Developed by Sun Microsystems, later acquired by Oracle Corporation  Java can be used to develop  Stand alone applications  Web applications.  applications for hand-held devices such as Palm and cell phones
  • 3. History of Java  Developed by a team led by James Gosling at Sun Microsystems in 1991 for use in embedded chips .  Originally called Oak.  In 1995 redesigned for developing Internet applications and renamed as Java  HotJava - The first Java-enabled Web browser (1995)  JDK Evolutions
  • 4. Java Standards Computer languages have strict rules of usage. Java standards are defined by • The Java language specification and • Java API The Java language specification is a technical definition of the language that includes the syntax and semantics of the Java programming language. The Application Program Interface (API) contains predefined classes and interfaces for developing Java programs. Java language specification is stable, but the API is still
  • 5. Editions of Java  Java Standard Edition (SE) used to develop client-side standalone applications or applets.  Java Enterprise Edition (EE) used to develop server-side applications such as Java servlets and Java ServerPages.  Java Micro Edition (ME). used to develop applications for mobile devices such as cell phones. Java Card: A technology that allows small Java-based applications to be run securely on smart cards and similar small-memory devices.
  • 6. Java Development Kit (JDK) JDK consists of a set of separate programs, each invoked from a command line, for developing and testing Java programs. There are many versions of Java SE. JDK 1.02 (1995) JDK 1.1 (1996) Java 2 SDK v 1.2 (JDK 1.2, 1998) Java 2 SDK v 1.3 (JDK 1.3, 2000) Java 2 SDK v 1.4 (JDK 1.4, 2002) and so on… The latest is JDK1.8 We will be using JDK1.7
  • 7. Integrated Development Environment (IDE)  Besides JDK, a Java development tool—software that provides an integrated development environment (IDE) for rapidly developing Java programs can be used.  Editing, compiling, building, debugging, and online help are integrated in one graphical user interface. • Borland Jbuilder • Microsoft Visual J++ • Net Beans • Eclipse • BlueJ We will be using plain text editor (preferably Notepad)
  • 8. Characteristics of Java (Best Practices) • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic
  • 9. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Java is partially modeled on C++, but greatly simplified and improved
  • 10. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Java is inherently object-oriented. Object- oriented programming provides great flexibility, modularity, clarity, and reusability through encapsulation, inheritance, and polymorphism
  • 11. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Distributed computing involves several computers working together on a network. Java is designed to make distributed computing easy.
  • 12. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic You need an interpreter to run Java programs. The programs are compiled into the Java Virtual Machine code called bytecode. The bytecode is machine- independent and can run on any machine that has a Java interpreter, which is part of the Java Virtual Machine (JVM).
  • 13. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Java compilers can detect many problems that would first show up at execution time in other languages. Java has eliminated certain types of error- prone programming constructs found in other languages. Java has a runtime exception-handling feature to provide programming support for robustness.
  • 14. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Java implements several security mechanisms to protect your system against harm caused by stray programs.
  • 15. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Write once, run anywhere With a Java Virtual Machine (JVM), you can write one program that will run on any platform.
  • 16. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled.
  • 17. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Java’s performance Because Java is architecture neutral, Java programs are portable. They can be run on any platform without being recompiled.
  • 18. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Multithread programming is smoothly integrated in Java, whereas in other languages you have to call procedures specific to the operating system to enable multithreading.
  • 19. Characteristics of Java • Java Is Simple • Java Is Object-Oriented • Java Is Distributed • Java Is Interpreted • Java Is Robust • Java Is Secure • Java Is Architecture-Neutral • Java Is Portable • Java's Performance • Java Is Multithreaded • Java Is Dynamic Java was designed to adapt to an evolving environment. New code can be loaded on the fly without recompilation. There is no need for developers to create, and for users to install, major new software versions. New features can be incorporated transparently as needed.
  • 20. Sample Java Program package sample; import java.lang.*; // Optional public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } }
  • 21. Creating, Compiling and Executing Java Program • Use any text editor or IDE to create and edit a Java source- code file • The source file must end with the extension .java and must have exactly the same name as the public class name Welcome.java • Compile the .java file into java byte code file (Java bytecode is the instruction set of the Java virtual machine) javac Welcome.java If there are no syntax errors, the compiler generates a bytecode file with .class extension
  • 22. Creating, Compiling and Executing Java Program
  • 23. Java Runtime Environment (JRE) and Java Virtual Machine (JVM) JDK The JDK includes the JRE plus command-line development tools such as compilers and debuggers that are necessary or useful for developing applets and applications JRE The JRE provides the libraries, Java virtual machine, and other components necessary for you to run applets and applications written in the Java programming language JVM The Java virtual machine is an abstract computing machine that has an instruction set and manipulates memory at run time. The Java virtual machine is ported to different platforms to provide hardware- and operating system- independence.
  • 24. Java Runtime Environment (JRE) and Java Virtual Machine (JVM) Java Development Kit (JDK) Java Language Development Tools and APIs java, javac, Javadoc Java Runtime Environment (JRE) User Interface Toolkits - AWT, Swing Libraries Java Virtual Machine (JVM) Deployment Technology
  • 25. ECLIPSE IDE • ECLIPSE is an integrated development environment used in computer programming. • It contains a base workspace and an extensible plug-in system for customizing the environment.
  • 26. 26 WORKBENCH TERMINOLOGY Tool bar Perspective and Fast View bar Resource Navigator view Stacked views Properties view Tasks view Outline view Bookmarks view Menu bar Message area Editor Status area Text editor
  • 27. 27 JAVA PERSPECTIVE • JAVA-CENTRIC VIEW OF FILES IN JAVA PROJECTS • JAVA ELEMENTS MEANINGFUL FOR JAVA PROGRAMMERS Java project package class field method Java editor
  • 28. 28 JAVA PERSPECTIVE • SEARCH FOR JAVA ELEMENTS • DECLARATIONS OR REFERENCES • INCLUDING LIBRARIES AND OTHER PROJECTS Hits flagged in margin of editor All search results
  • 29. LEARNING INTELLISENSE • Intellisense is a general term for various code editing features including: code completion, parameter info, quick info, and member lists. • Intellisense features are sometimes called by other names such as "code completion", "content assist", and "code hinting."
  • 30. INTRODUCTION TO OOPS CONCEPTS • ORIENTED PROGRAMMING IS A PARADIGM THAT PROVIDES MANY CONCEPTS, SUCH AS INHERITANCE, DATA BINDING, POLYMORPHISM, ETC. • SIMULA IS CONSIDERED THE FIRST OBJECT-ORIENTED PROGRAMMING LANGUAGE. • SMALLTALK IS CONSIDERED THE FIRST TRULY OBJECT-ORIENTED PROGRAMMING LANGUAGE. • THE POPULAR OBJECT-ORIENTED LANGUAGES ARE JAVA, C#, PHP, PYTHON, C++, ETC.
  • 31. OOPS CONCEPTS • OBJECT • CLASS • METHOD • ATTRIBUTE
  • 32. BASIC TERMINOLOGY OBJECT • - USUALLY A PERSON, PLACE OR THING (A NOUN) METHOD • - AN ACTION PERFORMED BY AN OBJECT (A VERB) ATTRIBUTE • - DESCRIPTION OF OBJECTS IN A CLASS CLASS • - A CATEGORY OF SIMILAR OBJECTS (SUCH AS AUTOMOBILES) • - DOES NOT HOLD ANY VALUES OF THE OBJECT’S ATTRIBUTES 32
  • 33. 33 DESIGN PRINCIPLES OF OOP Four main design principles of Object-oriented Programming(OOP): Encapsulation Abstraction Polymorphism Inheritance
  • 34. OBJECT • Any entity that has state and behavior is known as an object. For example, A chair, pen, table, keyboard, bike, etc. It can be physical or logical. • An object can be defined as an instance of a class. An object contains an address and takes up some space in memory.
  • 35. CLASS • Collection of objects is called class. It is a logical entity. • A class can also be defined as a blueprint from which you can create an individual object. Class doesn't consume any space.
  • 36. Role of Java in the IT Industry 1. WEB DEVELOPMENT Server Side Technologies: SPRING FRAMEWORK, SPRING BOOT, GRAILS Java Application Servers: TOMCAT 2. ANDROID APPLICATION: ANDROID STUDIO, ECLIPSE, AVD MANAGER, INTELLIJ IDEA 3. BIG DATA HADOOP, SPARK, CASSANDRA, SPRING BOOT, ELASTICSEARCH 4. DEVOPS JENKINS, VISUAL STUDIO IDE, DOCKER AND KUBERNETES 5. DESKTOPAPPLICATIONS SWING, AWT, JAVAFX
  • 37. VARIABLES 37 • The name of some location of memory used to hold a data value • Different types of data require different amounts of memory. The compiler’s job is to reserve sufficient memory • Variables need to be declared once • Variables are assigned values, and these values may be changed later • Each variable has a type, and operations can only be performed between compatible types • Example int width = 3; int height = 4; int area = width * height; width = 6; area = width * height; 4 3 height area width 3 4 12 24 6 12 width height area
  • 38. VARIABLE NAMES 38 • Valid variable names: these rules apply to all java names, or identifiers, including methods and class names • Starts with: a letter (a-z or A-Z), dollar sign ($), or underscore (_) • Followed by: zero or more letters, dollar signs, underscores, or digits (0-9). • Uppercase and lowercase are different (total ≠ Total ≠ TOTAL) • Cannot be any of the reserved names. These are special names (keywords) reserved for the compiler. Examples: class, float, int, if, then, else, do, public, private, void, …
  • 39. GOOD VARIABLE NAMES 39 • Choosing good names not all valid variable names are good variable names • Some guidelines: • Do not use `$’ (it is reserved for special system names.) • Avoid names that are identical other than differences in case (total, Total, and TOTAL). • Use meaningful names, but avoid excessive length • crITm  too short • theCurrentItembeingProcessed  too long • currentItem just right • Camel case capitalization style • In Java we use camel case • Variables and methods start with lower case dataList2 myFavoriteMartian showMeTheMoney • Classes start with uppercase String JOptionPane MyfavoriteClass
  • 40. VALID/INVALID IDENTIFIERS 40 VALID: $$_ R2D2 INT OKAY. “INT” IS RESERVED, BUT CASE IS DIFFERENT HERE _dogma_95_ riteOnThru SchultzieVonWienerschnitzeliii INVALID: 30DayAbs Starts With A Digit 2 Starts with a digit pork&beans `&’ IS ILLEGAL private reserved name C-3PO `-’ IS ILLEGAL
  • 42. PRIMITIVE DATA TYPES 42 • Java’s basic data types: • Integer types: • Byte 1 byte range: -128 to +127 • Short 2 bytes range: roughly -32 thousand to +32 thousand • Int 4 bytes range: roughly -2 billion to +2 billion • Long 8 bytes range: huge! • Floating-point types (for real numbers): • Float 4 bytes roughly 7 digits of precision • Double 8 bytes roughly 15 digits of precision • Other types: • Boolean 1 byte {true, false} (used in logic expressions and conditions) • Char 2 bytes A single (unicode) character • String is not a primitive data type (they are objects)
  • 43. 43 NUMERIC CONSTANTS (LITERALS) • Specifying constants: (also called literals) for primitive data types. Integer types: Byte Short optional sign and digits (0-9): 12 -1 +234 0 1234567 Int Long same as above, but followed by ‘L’ or ‘l’: -1394382953L Floating-point types: Double two allowable forms: Decimal notation: 3.14159 -234.421 0.0042 -43.0 Scientific notation: (use E or e for base 10 exponent) 3.145e5 = 3.145 x 105 = 314500.0 1834.23e-6 = 1834.23 x 10-6 = 0.00183423 Float same as double, but followed by ‘f’ or ‘F’: 3.14159f -43.2f Note: By default, integer constants are int, unless ‘L’/‘l’ is used to indicate they are long. Floating constants are double, unless ‘F’/‘f’ is used to indicate they are float. Avoid this lowercase L. It looks too much like the digit ‘1’
  • 44. 44 CHARACTER AND STRING CONSTANTS • Char constants: single character enclosed in single quotes (‘…’) including: • Letters and digits: ‘A’, ‘B’, ‘C’, …, ‘a’, ‘b’, ‘c’, …, ‘0’, ‘1’, …, ‘9’ • Punctuation symbols: ‘*’, ‘#’, ‘@’, ‘$’ (except single quote and backslash ‘’) • Escape sequences: (see below) • String constants: zero or more characters enclosed in double quotes (“…”) • (same as above, but may not include a double quote or backslash) • Escape sequences: allows us to include single/double quotes and other special characters: ” Double quote n new-line character (start a new line) ’ Single quote t tab character Backslash • Examples: char x = ’’’  (x contains a single quote) ””Hi there!””  ”Hi there!” ”C:WINDOWS”  C:WINDOWS system.Out.Println( ”Line 1nLine 2” ) prints Line 1 Line 2
  • 45. DATA TYPES AND VARIABLES 45 • Java  strongly-type language • Strong Type Checking  Java checks that all expressions involve compatible types • int x, y; // x and y are integer variables • double d; // d is a double variable • String s; // s is a string variable • boolean b; // b is a boolean variable • char c; // c is a character variable • x = 7; // legal (assigns the value 7 to x) • b = true; // legal (assigns the value true to b) • c = ‘#’; // legal (assigns character # to c) • s = “cat” + “bert”; // legal (assigns the value “catbert” to s) • d = x – 3; // legal (assigns the integer value 7 – 3 = 4 to double d) • b = 5; // illegal! (cannot assign int to boolean) • y = x + b; // illegal! (cannot add int and boolean) • c = x; // illegal! (Cannot assign int to char)
  • 46. NUMERIC OPERATORS 46 • Arithmetic Operators: • Unary negation: -x • Multiplication/division: x * y x/y • Division between integer types truncates to integer: 23/4  5 • X % y returns the remainder of x divided by y: 23%4  3 • Division with real types yields a real result: 23.0/4.0  5.75 • Addition/subtraction: x+y x-y • Comparison Operators: • Equality/inequality: x == y x != y • Less than/greater than: x < y x > y • Less than or equal/greater than or equal: x <= y x >= y • These comparison operators return a boolean value: true or false.
  • 47. COMMON STRING OPERATORS 47 • String Concatenation: The ‘+’ Operator Concatenates (Joins) Two Strings. • “Von” + “Wienerschnitzel”  “Vonwienerschnitzel” • When a string is concatenated with another type, the other type is first evaluated and converted into its string representation (8*4) + “Degrees”  “32degrees” (1 + 2) + “5”  “35” • String Comparison: Strings should not be compared using the above operators (==, <=, <, etc). Let s and t be strings. • s.equals(t)  returns true if s equals t • s.length()  returns length • s.compareTo(t)  compares strings lexicographically (dictionary order) • result < 0 if s is less than t • result == 0 if s is equal to t • result > 0 if s is greater than t Note: Concatenation does not add any space
  • 48. JAVA OPERATORS • Operators are used to perform operations on variables and values. int x = 100 + 50; //output=150
  • 49. ARITHMETIC OPERATORS Operator Name Description Example + Addition Adds together two values x + y - Subtraction Subtracts one value from another x - y * Multiplication Multiplies two values x * y / Division Divides one value by another x / y % Modulus Returns the division remainder x % y ++ Increment Increases the value of a variable by 1 ++x -- Decrement Decreases the value of a variable by 1 --x
  • 50. ASSIGNMENT OPERATORS Operator Example Same As = x = 5 x = 5 += x += 3 x = x + 3 -= x -= 3 x = x - 3 *= x *= 3 x = x * 3 /= x /= 3 x = x / 3 %= x %= 3 x = x % 3 &= x &= 3 x = x & 3 |= x |= 3 x = x | 3 ^= x ^= 3 x = x ^ 3 >>= x >>= 3 x = x >> 3 <<= x <<= 3 x = x << 3
  • 51. COMPARISON OPERATORS Operator Name Example == Equal to x == y != Not equal x != y > Greater than x > y < Less than x < y >= Greater than or equal to x >= y <= Less than or equal to x <= y
  • 52. LOGICAL OPERATORS Operator Name Description Example && Logical and Returns true if both statements are true x < 5 && x < 10 || Logical or Returns true if one of the statements is true x < 5 || x < 4 ! Logical not Reverse the result, returns false if the result is true !(x < 5 && x < 10)
  • 53. TERNARY OPERATOR condition ? if true : if false The above statement means that if the condition evaluates to true, then execute the statements after the ‘?’ else execute the statements after the ‘:’.
  • 54. BITWISE OPERATORS • &: Bitwise AND operator: returns bit by bit AND of input values. • |: Bitwise OR operator: returns bit by bit or of input values. • ^: Bitwise XOR operator: returns bit-by-bit xor of input values. • ~: Bitwise Complement operator: this is a unary operator which returns the one’s complement representation of the input value, i.e., With all bits inverted.
  • 55. SHIFT OPERATORS • <<: Left shift operator: shifts the bits of the number to the left and fills 0 on voids left as a result. Similar effect as multiplying the number with some power of two. • >>: Signed right shift operator: shifts the bits of the number to the right and fills 0 on voids left as a result. The leftmost bit depends on the sign of the initial number. Similar effect to dividing the number with some power of two. • >>>: Unsigned right shift operator: shifts the bits of the number to the right and fills 0 on voids left as a result. The leftmost bit is set to 0.
  • 56. JAVA OPERATOR PRECEDENCE AND ASSOCIATIVITY Precedence Operator Type Associativity 15 () [] · Parentheses Array subscript Member selection Left to Right 14 ++ -- Unary post-increment Unary post-decrement Right to left 13 ++ -- + - ! ~ (type) Unary pre-increment Unary pre-decrement Unary plus Unary minus Unary logical negation Unary bitwise complement Unary type cast Right to left 12 * / % Multiplication Division Modulus Left to right 11 + - Addition Subtraction Left to right
  • 57. JAVA OPERATOR PRECEDENCE AND ASSOCIATIVITY Precedence Operator Type Associativity 10 << >> >>> Bitwise left shift Bitwise right shift with sign extension Bitwise right shift with zero extension Left to right 9 < <= > >= instanceof Relational less than Relational less than or equal Relational greater than Relational greater than or equal Type comparison (objects only) Left to right 8 == != Relational is equal to Relational is not equal to Left to right
  • 58. JAVA OPERATOR PRECEDENCE AND ASSOCIATIVITY Precedence Operator Type Associativity 7 & Bitwise AND Left to right 6 ^ Bitwise exclusive OR Left to right 5 | Bitwise inclusive OR Left to right 4 && Logical AND Left to right 3 || Logical OR Left to right 2 ? : Ternary conditional Right to left 1 = += -= *= /= %= Assignment Addition assignment Subtraction assignment Multiplication assignment Division assignment Modulus assignment Right to left
  • 59. TYPE CASTING • Type casting is when you assign a value of one primitive data type to another type. • In Java, there are two types of casting: • Widening Casting (automatically) - converting a smaller type to a larger type size Byte -> short -> char -> int -> long -> float -> double • Narrowing Casting (manually) - converting a larger type to a smaller size type Double -> float -> long -> int -> char -> short -> byte
  • 60. WIDENING CASTING • Widening casting is done automatically when passing a smaller size type to a larger size type: Example: public class Main { public static void main(String[] args) { int myInt = 9; double myDouble = myInt; // Automatic casting: int to double System.out.println(myInt); // Outputs 9 System.out.println(myDouble); // Outputs 9.0 } } OUTPUT: 9 9.0
  • 61. NARROWING CASTING • Narrowing casting must be done manually by placing the type in parentheses in front of the value. Example: public class Main { public static void main(String[] args) { double myDouble = 9.78d; int myInt = (int) myDouble; // Manual casting: double to int System.out.println(myDouble); // Outputs 9.78 System.out.println(myInt); // Outputs 9 } } OUTPUT: 9.78 9
  • 62. NAMING CONVENTION • CamelCase in Java naming conventions • Java follows camel-case syntax for naming the class, interface, method, and variable. • If the name is combined with two words, the second word will start with uppercase letter always such as actionPerformed(), firstName, ActionEvent, ActionListener, etc.
  • 63. NAMING CONVENTION Identifiers Type Naming Rules Examples Class It should start with the uppercase letter. It should be a noun such as Color, Button, System, Thread, etc. Use appropriate words, instead of acronyms. public class Employee { //code snippet } Interface It should start with the uppercase letter. It should be an adjective such as Runnable, Remote, ActionListener. Use appropriate words, instead of acronyms. interface Printable { //code snippet } Method It should start with lowercase letter. It should be a verb such as main(), print(), println(). If the name contains multiple words, start it with a lowercase letter followed by an uppercase letter such as actionPerformed(). class Employee { // method void draw() { //code snippet } }
  • 64. NAMING CONVENTION Identifiers Type Naming Rules Examples Variable It should start with a lowercase letter such as id, name. It should not start with the special characters like & (ampersand), $ (dollar), _ (underscore). If the name contains multiple words, start it with the lowercase letter followed by an uppercase letter such as firstName, lastName. Avoid using one-character variables such as x, y, z. class Employee { // variable int id; //code snippet } Package It should be a lowercase letter such as java, lang. If the name contains multiple words, it should be separated by dots (.) such as java.util, java.lang. //package package com.javatpoint; class Employee { //code snippet } Constant It should be in uppercase letters such as RED, YELLOW. If the name contains multiple words, it should be separated by an underscore(_) such as MAX_PRIORITY. It may contain digits but not as the first letter. class Employee { //constant static final int MIN_AGE = 18; //code snippet
  • 65. JAVA CODING STANDARDS AND BEST PRACTICES • Efficient string concatenation:- For making a long string by adding different small strings always use append method of java.Lang.Stringbuffer and never use ordinary ‘+’ operator for adding up strings. • Optimal use of garbage collector: - For easing out the work of java garbage collector always set all referenced variables used to ‘null’ Explicitly thus de-referencing the object which is no more required by the application and allowing. Garbage collector to swap away that variable thus realizing memory. • Writing oracle stored procedures optimally:- Avoid using ‘IN’ and ‘NOT IN’ clause and rather try to use ‘OR’ operator for increasing the response time for the oracle stored procedures. • Using variables in any code optimally:- Try to make minimum number of variables in JSP/java class and try to use already made variables in different algorithms shared in same JSP/java class by setting already populated variable to ‘null’ and then again populating that variable with new value and then reusing them.
  • 66. JAVA CODING STANDARDS AND BEST PRACTICES • Try to write minimum java code in JSPS:- big patches of java code in JSP should be avoided and is should be rather shifted to some wrapper/helper/bean class which should be used together with every JSP. • Try to reduce the number of hits to database:- number of hits to the database should be reduced to minimum by getting data in a well arranged pattern in minimum number of hits by making the best use of joins in the database query itself rather than getting dispersed data in more number of hits. • Caching of EJB references:- to avoid costly lookup every time any remote object is required, its better to cache the home reference and reusing it.
  • 67. JAVA CODING STANDARDS AND BEST PRACTICES • Heavy objects should not be stored in session of JSPS:- storing heavy objects in the session can lead to slowing of the running of the JSP page so such case should be avoided. • Always use JDBC connection pooling:- always use javax.Sql.Datasource which is obtained through a JNDI naming lookup. Avoid the overhead of acquiring a javax.Sql.Datasource for each SQL access. • Release HTTPSESSIONS when finished:- abandoned httpsessions can be quite high.Httpsession objects live inside the engine until the application explicitly and programmatically releases it using the API, javax.Servlet.Http.Httpsession.Invalidate (); quite often, programmatic invalidation is part of an application logout function. • Release JDBC resources when done:- failing to close and release jdbc connections can cause other users to experience long waits for connections.
  • 68. JAVA CODING STANDARDS AND BEST PRACTICES • Minimize use of system.Out.Println:- because it seems harmless, this commonly used application development legacy is overlooked for the performance problem it really is. • Minimum use of java.Util.Vector:- since most of the commonly used methods in vector class are synchronized which makes any method call or any variable heavy as compared to those which are not synchronized so it’s a better practice to use any other collection sibling whose methods are not synchronized for eg. Java.Util.Arraylist. • Synchronization has a cost:- putting synchronized all over the place does not ensure thread safety. • Using JS files and other include files in jar:- when we are developing web based large number of include file. All includes file must be put in jar and accessed which is very fast.
  • 69. JAVA COMMENTS • Single-line comments Single-line comments start with two forward slashes (//). • Multi-line comments Multi-line comments start with /* and ends with */.
  翻译: