SlideShare una empresa de Scribd logo
1 de 31
Descargar para leer sin conexión
JAVA
Fundamental of
java
Prepared by
Miss. Arati A. Gadgil
2
Java
Java was developed in the early 90s by Sun Microsystems
Java is a high-level language.
There are many features of java. They are also known as
java buzzwords.
Simple
Java omits many rarely used, poorly understood, confusing
features of C++. Say : No Pointer! No dynamic delete.
3
Object Oriented
Object –oriented design is a technology that focuses design
on the data (object) and on the interfaces to it.
Everything is an object, everything will become a class in
Java. Every java program, in top- level view, is classes.
Robust
The single biggest difference between Java and C/C++ is
that Java has “a inner safe pointer-model”, therefore it
eliminates the possibility of overwriting memory and
corrupting data, so programmers feel very safe in coding.
4
Distributed
Basically, Java is for Net-Work application, for WEB
project. Java can open and access “objects” across the Net via
URLs (Uniform Resource Locator)
eg. “http//:gamut.neiu.edu/~ylei/home.html”, with the same
ease as when accessing a local file system
Platform Independent
Java code can be run on multiple platforms e.g. Windows,
Linux, Sun Solaris,Mac/OS etc. Java code is compiled by the
compiler and converted into bytecode.This bytecode is a
platform independent code because it can be run on multiple
platforms i.e. Write Once and Run Anywhere(WORA).
5
Secured
Java is secured because:
No explicit pointer,Programs run inside virtual machine
sandbox also,
•Classloader- adds security by separating the package for the
classes of the local file system from those that are imported
from network sources.
•Bytecode Verifier- checks the code fragments for illegal code
that can violate access right to objects.
•Security Manager- determines what resources a class can
access such as reading and writing to the local disk
6
Architecture-neutral
The compiler generates an architecture-neutral object file
format. The compile code can run on many processors ,given
the presence of the runtime system. The java compiler does
this by generting bytecode instruction which have nothing to
do with a particular computer architecture.
Portable
We may carry the java bytecode to any platform.
High-performance
Java is faster than traditional interpretation since byte code is
"close" to native code still somewhat slower than a compiled
language (e.g., C++)
7
Multi-threaded
A thread is like a separate program, executing concurrently.
We can write Java programs that deal with many tasks at once
by defining multiple threads. The main advantage of multi-
threading is that it shares the same memory. Threads are
important for multi-media, Web applications etc.
Dynamic
In number of ways, java is more dynamic language than C or
C++.It was designed to adapt to an evolving environment.
Libraries can freely add new methods and instance variables
without any effect on their clients. In java finding out runtime
type information is straightforward.
8
Java Virtual Machine
The .class files generated by the compiler are not executable
binaries, Java combines compilation and interpretation.
Instead, they contain “byte-codes” to be executed by the Java
Virtual Machine.
This approach provides platform independence, and greater
security.
The JVM performs following main tasks:
•Loads code
•Verifies code
•Executes code
•Provides runtime environment
9
JRE
JRE is an acronym for Java Runtime Environment. It is used
to provide runtime environment.It is the implementation of
JVM. It physically exists.It contains set of libraries + other
files that JVM uses at runtime.
JDK
JDK is an acronym for Java Development Kit. It physically
exists. It contains JRE + development tools
10
JVM
Java Virtual Machine (JVM) is an abstract computing
machine. Java Runtime Environment (JRE) is an
implementation of the JVM. Java Development Kit (JDK)
contains JRE along with various development tools like Java
libraries, Java source compilers, Java debuggers, bundling and
deployment tools.
11
Relations between JVM JRE JDK
12
JIT
JIT refers to execution engine in few of JVM
implementations, one that is faster but requires more memory,
is a just-in-time compiler. In this scheme, the bytecodes of a
method are compiled to native machine code the first time the
method is invoked.
JIT refers to execution engine in few of JVM
implementations, one that is faster but requires more
memory,is a just-in-time compiler. In this scheme, the
bytecodes of a method are compiled to native machine code
the first time the method is invoked.
13
Java Bytecode
Java bytecode is the instruction set of the Java virtual
machine. Eachbytecode is composed by one, or in some cases
two, bytes that represent the instruction (opcode), along with
zero or more bytes for passing parameters..
Bytecode is nothing but the intermediate representation of
Java source code which is produced by the Java compiler by
compiling that source code. This byte code is an machine
independent code.It is not an completely a compiled code but
it is an intermediate code somewhere in the middle which is
later interpreted and executed by JVM
14
HotSpot, released as the "Java HotSpot Performance Engine"is
a Java virtual machine for desktops and servers, maintained and
distributed by Oracle Corporation. It features techniques such as just-
in-time compilation and adaptive optimization designed to improve
performance.
Sun intended to write a new just-in-time (JIT) compiler for the
newly developed virtual machine.This new compiler would give rise
to the name "HotSpot", which derives from the fact that, as the
software runs Java bytecode, it continually analyzes the program's
performance for "hot spots" which are frequently or repeatedly
executed. These are then targeted for optimization, leading to high-
performance execution with a minimum of overhead for less
performance-critical code
Java HotSpot
15
Sun's JRE features two virtual machines, one called Client and the
other Server. The Client version is tuned for quick loading. It makes use
of interpretation. The Server version loads more slowly, putting more
effort into producing highly optimized JI compilations, that yield higher
performance. Both VMs compile only often-run methods, using a
configurable invocation-count threshold to decide which methods to
compile.
The HotSpot Java virtual machine is written in C++. As stated on the
HotSpot web page, the source contains approximately 250,000 lines of
code.
Hotspot provides:
•A class loader
•A bytecode interpreter
•Client and Server virtual machines, optimized for their respective uses
•Several garbage collectors
•A set of supporting runtime libraries
16
The main() method
public static void main(String args[])
{
...
}
public--- the interpreter can call it.
static ----It is a static method belonging to the class.
void -----It does not return a value.
String----It always has an array of String objects as its formal parameter.
the array contains any arguments passed to the program on the
command line.The source file’s name must match the class name which
main method is in.
17
Source File Declaration Rules
There can be only one public class per source code file.
Comments can appear at the beginning or end of any line in the source
code file; they are independent of any of the positioning rules discussed
here.
If there is a public class in a file, the name of the file must match the
name of the public class.
For example, a class declared as public class Dog { }must be in a source
code file named Dog.java.
If the class is part of a package, the package statement must be the first
line in the source code file, before any import statements that may be
present.
18
If there are import statements, they must go between the package
statement (if there is one) and the class declaration. If there isn't a
package statement, then the import statement(s) must be the first line(s)
in the source code file.
If there are no package or import statements, the class declaration must
be the first line in the source code file.
import and package statements apply to all classes within a source
code file. In other words, there's no way to declare multiple classes in a
file and have them in different packages, or use different imports.
A file can have more than one nonpublic class.
Files with no public classes can have a name that does not match any of
the classes in the file
19
Comments
/* This kind of comment can span multiple lines */
// This kind is to the end of the line
/**
* This kind of comment is a special
* ‘javadoc’ style comment
*/
20
Primitive types
•int 4 bytes
•short 2 bytes
•long 8 bytes
•byte 1 byte
•float 4 bytes
•double 8 bytes
•char Unicode encoding (2 bytes)
•boolean {true,false}
Behaviors is
exactly as in
C++
21
• Constants
37 integer
37.2 float
42F float
0754 integer (octal)
0xfe integer (hexadecimal)
• Comparison operators
== equal
!= not equal
< less than
> greater than
<= less than or equal
>= greater than or equal
22
Variable declaration
type variable-name;
Meaning: variable <variable-name> will be a variable of type <type>
Where type can be:
int //integer
double //real number
Example:
int a, b, c;
double x;
int sum;
23
String is an Object
Constant strings as in C, does not exist
 The function call show(“Hello”) creates a String object, containing
“Hello”, and passes reference to it to show.
 The String object is a constant. It can’t be changed using a reference
to
it.
24
Writing to user (output)
System.out.println(variable-name);
prints the value of variable <variable-name> to the user
System.out.println(“any message “);
prints the message within quotes to the user
System.out.println(“hello” + “world” + a + “plus“ + b);
assuming the value of a is 3 and of b is 7, it prints
helloworld3plus7
Note: System.out.println() always prints on a new line.
25
Example
/*
This program illustrates the System.out.println command.
*/
public class Hello
{
public static void main (String args[])
{
System.out.println(“This is my first Java program!”);
System.out.print(“I like Java.”);
System.out.print(“I think Java is cool.”);
} // end of main
} // end of class
26
Example
/*
Printing ages.
*/
public class MyFirstJavaProgram
{
public static void main (String args[])
{
int myAge, myFriendAge; /* declare two integer
variables */
myAge = 20;
myFriendAge = myAge + 1; //one year older
System.out.println(“Hello, I am “ +myAge + “years old,
and my friend is “ + myFriendAge + “ years old”);
System.out.println(“Goodbye”);
} // end of main
} // end of class
27
Flow control
if/else
do/while
for
switch
If(x==4) {
// act1
} else {
// act2
}
int i=5;
do {
// act1
i--;
} while(i!=0);
int j;
for(int i=0;i<=9;i++)
{
j+=i;
}
char
c=IN.getChar();
switch(c) {
case ‘a’:
case ‘b’:
// act1
break;
default:
// act2
}
28
Big Numbers
If the precision of the basic integer and floating-point types is not
sufficient, you can turn to a couple of handy classes in
the java.math package, called BigInteger and BigDecimal. These are
classes for manipulating numbers with an arbitrarily long sequence of
digits. The BigInteger class implements arbitrary precision integer
arithmetic, and BigDecimal does the same for floating-point numbers.
Use the static valueOf method to turn an ordinary number into a big
number:
BigInteger a = BigInteger.valueOf(100);
BigInteger c = a.add(b); // c = a + b
BigInteger d = c.multiply(b.add(BigInteger.valueOf(2)));
// d = c * (b + 2)
29
Array
•Array is an object
• Array size is fixed
A[] arr; // nothing yet …
arr = new A[4]; // only array of pointers
for(int i=0 ; i < arr.length ; i++)
arr[i] = new Animal();
30
Arrays - Multidimensional
• In C++
Animal arr[2][2]
Is:
• In Java
What is the type of
the object here ?
A[][] arr=
new A[2][2]
Thank You
31

Más contenido relacionado

La actualidad más candente

OOP with Java - Continued
OOP with Java - Continued OOP with Java - Continued
OOP with Java - Continued Hitesh-Java
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Languagejaimefrozr
 
Core java concepts
Core java  conceptsCore java  concepts
Core java conceptsRam132
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework tola99
 
Introduction to java
Introduction to java Introduction to java
Introduction to java Java Lover
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Mr. Akaash
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Java variable types
Java variable typesJava variable types
Java variable typesSoba Arjun
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to javaAjay Sharma
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java Ravi_Kant_Sahu
 

La actualidad más candente (20)

OOP with Java - Continued
OOP with Java - Continued OOP with Java - Continued
OOP with Java - Continued
 
Java Notes
Java Notes Java Notes
Java Notes
 
Introduction to Java Programming Language
Introduction to Java Programming LanguageIntroduction to Java Programming Language
Introduction to Java Programming Language
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Spring Framework
Spring Framework  Spring Framework
Spring Framework
 
Java Basic Oops Concept
Java Basic Oops ConceptJava Basic Oops Concept
Java Basic Oops Concept
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Core java Essentials
Core java EssentialsCore java Essentials
Core java Essentials
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
 
Core java
Core javaCore java
Core java
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Java variable types
Java variable typesJava variable types
Java variable types
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Java platform
Java platformJava platform
Java platform
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Collections framework in java
Collections framework in javaCollections framework in java
Collections framework in java
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Genesis and Overview of Java
Genesis and Overview of Java Genesis and Overview of Java
Genesis and Overview of Java
 

Destacado (16)

Chapter 4 Powerpoint
Chapter 4 PowerpointChapter 4 Powerpoint
Chapter 4 Powerpoint
 
C0 review core java1
C0 review core java1C0 review core java1
C0 review core java1
 
Introduction to the Java(TM) Advanced Imaging API
Introduction to the Java(TM) Advanced Imaging APIIntroduction to the Java(TM) Advanced Imaging API
Introduction to the Java(TM) Advanced Imaging API
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Eo gaddis java_chapter_02_5e
Eo gaddis java_chapter_02_5eEo gaddis java_chapter_02_5e
Eo gaddis java_chapter_02_5e
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
 
Intro to C++ Basic
Intro to C++ BasicIntro to C++ Basic
Intro to C++ Basic
 
Java for beginners
Java for beginnersJava for beginners
Java for beginners
 
Core Java Basics
Core Java BasicsCore Java Basics
Core Java Basics
 
Java Programming - 01 intro to java
Java Programming - 01 intro to javaJava Programming - 01 intro to java
Java Programming - 01 intro to java
 
Basics of Java
Basics of JavaBasics of Java
Basics of Java
 
02 basic java programming and operators
02 basic java programming and operators02 basic java programming and operators
02 basic java programming and operators
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java programming course for beginners
Java programming course for beginnersJava programming course for beginners
Java programming course for beginners
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 

Similar a Java basic

Similar a Java basic (20)

JAVA for Every one
JAVA for Every oneJAVA for Every one
JAVA for Every one
 
Javanotes ww8
Javanotes ww8Javanotes ww8
Javanotes ww8
 
Java notes
Java notesJava notes
Java notes
 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
 
Java chapter 1
Java   chapter 1Java   chapter 1
Java chapter 1
 
Java1
Java1Java1
Java1
 
Java
Java Java
Java
 
Java programming material for beginners by Nithin, VVCE, Mysuru
Java programming material for beginners by Nithin, VVCE, MysuruJava programming material for beginners by Nithin, VVCE, Mysuru
Java programming material for beginners by Nithin, VVCE, Mysuru
 
Java introduction
Java introductionJava introduction
Java introduction
 
What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)What is Java Technology (An introduction with comparision of .net coding)
What is Java Technology (An introduction with comparision of .net coding)
 
Top 10 Important Core Java Interview questions and answers.pdf
Top 10 Important Core Java Interview questions and answers.pdfTop 10 Important Core Java Interview questions and answers.pdf
Top 10 Important Core Java Interview questions and answers.pdf
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 
Java 8 Overview
Java 8 OverviewJava 8 Overview
Java 8 Overview
 
Java Lecture 1
Java Lecture 1Java Lecture 1
Java Lecture 1
 
Presentación rs232 java
Presentación rs232 javaPresentación rs232 java
Presentación rs232 java
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
 
java slides
java slidesjava slides
java slides
 
Java unit 1
Java unit 1Java unit 1
Java unit 1
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
OOPS JAVA.pdf
OOPS JAVA.pdfOOPS JAVA.pdf
OOPS JAVA.pdf
 

Más de Arati Gadgil (16)

Java adapter
Java adapterJava adapter
Java adapter
 
Java swing
Java swingJava swing
Java swing
 
Java applet
Java appletJava applet
Java applet
 
Java layoutmanager
Java layoutmanagerJava layoutmanager
Java layoutmanager
 
Java awt
Java awtJava awt
Java awt
 
Java stream
Java streamJava stream
Java stream
 
Java thread
Java threadJava thread
Java thread
 
Java networking
Java networkingJava networking
Java networking
 
Java jdbc
Java jdbcJava jdbc
Java jdbc
 
Java package
Java packageJava package
Java package
 
Java interface
Java interfaceJava interface
Java interface
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Java eventhandling
Java eventhandlingJava eventhandling
Java eventhandling
 
Java exception
Java exception Java exception
Java exception
 
Java collection
Java collectionJava collection
Java collection
 
Java class
Java classJava class
Java class
 

Último

How to Solve Singleton Error in the Odoo 17
How to Solve Singleton Error in the  Odoo 17How to Solve Singleton Error in the  Odoo 17
How to Solve Singleton Error in the Odoo 17Celine George
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfMohonDas
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17Celine George
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxraviapr7
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.EnglishCEIPdeSigeiro
 
EBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlEBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlDr. Bruce A. Johnson
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfMohonDas
 
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustVani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustSavipriya Raghavendra
 
Optical Fibre and It's Applications.pptx
Optical Fibre and It's Applications.pptxOptical Fibre and It's Applications.pptx
Optical Fibre and It's Applications.pptxPurva Nikam
 
A gentle introduction to Artificial Intelligence
A gentle introduction to Artificial IntelligenceA gentle introduction to Artificial Intelligence
A gentle introduction to Artificial IntelligenceApostolos Syropoulos
 
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptxSOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptxSyedNadeemGillANi
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfYu Kanazawa / Osaka University
 
Department of Health Compounder Question ‍Solution 2022.pdf
Department of Health Compounder Question ‍Solution 2022.pdfDepartment of Health Compounder Question ‍Solution 2022.pdf
Department of Health Compounder Question ‍Solution 2022.pdfMohonDas
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...Nguyen Thanh Tu Collection
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxheathfieldcps1
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxiammrhaywood
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17Celine George
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.raviapr7
 
Over the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxOver the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxraviapr7
 
10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdf10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdfJayanti Pande
 

Último (20)

How to Solve Singleton Error in the Odoo 17
How to Solve Singleton Error in the  Odoo 17How to Solve Singleton Error in the  Odoo 17
How to Solve Singleton Error in the Odoo 17
 
HED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdfHED Office Sohayok Exam Question Solution 2023.pdf
HED Office Sohayok Exam Question Solution 2023.pdf
 
How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17How to Show Error_Warning Messages in Odoo 17
How to Show Error_Warning Messages in Odoo 17
 
Education and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptxEducation and training program in the hospital APR.pptx
Education and training program in the hospital APR.pptx
 
Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.Easter in the USA presentation by Chloe.
Easter in the USA presentation by Chloe.
 
EBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting BlEBUS5423 Data Analytics and Reporting Bl
EBUS5423 Data Analytics and Reporting Bl
 
Diploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdfDiploma in Nursing Admission Test Question Solution 2023.pdf
Diploma in Nursing Admission Test Question Solution 2023.pdf
 
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational TrustVani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
Vani Magazine - Quarterly Magazine of Seshadripuram Educational Trust
 
Optical Fibre and It's Applications.pptx
Optical Fibre and It's Applications.pptxOptical Fibre and It's Applications.pptx
Optical Fibre and It's Applications.pptx
 
A gentle introduction to Artificial Intelligence
A gentle introduction to Artificial IntelligenceA gentle introduction to Artificial Intelligence
A gentle introduction to Artificial Intelligence
 
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptxSOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
SOLIDE WASTE in Cameroon,,,,,,,,,,,,,,,,,,,,,,,,,,,.pptx
 
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdfP4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
P4C x ELT = P4ELT: Its Theoretical Background (Kanazawa, 2024 March).pdf
 
Department of Health Compounder Question ‍Solution 2022.pdf
Department of Health Compounder Question ‍Solution 2022.pdfDepartment of Health Compounder Question ‍Solution 2022.pdf
Department of Health Compounder Question ‍Solution 2022.pdf
 
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
CHUYÊN ĐỀ DẠY THÊM TIẾNG ANH LỚP 11 - GLOBAL SUCCESS - NĂM HỌC 2023-2024 - HK...
 
The basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptxThe basics of sentences session 10pptx.pptx
The basics of sentences session 10pptx.pptx
 
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptxAUDIENCE THEORY -- FANDOM -- JENKINS.pptx
AUDIENCE THEORY -- FANDOM -- JENKINS.pptx
 
How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17How to Add Existing Field in One2Many Tree View in Odoo 17
How to Add Existing Field in One2Many Tree View in Odoo 17
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.
 
Over the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptxOver the counter (OTC)- Sale, rational use.pptx
Over the counter (OTC)- Sale, rational use.pptx
 
10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdf10 Topics For MBA Project Report [HR].pdf
10 Topics For MBA Project Report [HR].pdf
 

Java basic

  • 2. 2 Java Java was developed in the early 90s by Sun Microsystems Java is a high-level language. There are many features of java. They are also known as java buzzwords. Simple Java omits many rarely used, poorly understood, confusing features of C++. Say : No Pointer! No dynamic delete.
  • 3. 3 Object Oriented Object –oriented design is a technology that focuses design on the data (object) and on the interfaces to it. Everything is an object, everything will become a class in Java. Every java program, in top- level view, is classes. Robust The single biggest difference between Java and C/C++ is that Java has “a inner safe pointer-model”, therefore it eliminates the possibility of overwriting memory and corrupting data, so programmers feel very safe in coding.
  • 4. 4 Distributed Basically, Java is for Net-Work application, for WEB project. Java can open and access “objects” across the Net via URLs (Uniform Resource Locator) eg. “http//:gamut.neiu.edu/~ylei/home.html”, with the same ease as when accessing a local file system Platform Independent Java code can be run on multiple platforms e.g. Windows, Linux, Sun Solaris,Mac/OS etc. Java code is compiled by the compiler and converted into bytecode.This bytecode is a platform independent code because it can be run on multiple platforms i.e. Write Once and Run Anywhere(WORA).
  • 5. 5 Secured Java is secured because: No explicit pointer,Programs run inside virtual machine sandbox also, •Classloader- adds security by separating the package for the classes of the local file system from those that are imported from network sources. •Bytecode Verifier- checks the code fragments for illegal code that can violate access right to objects. •Security Manager- determines what resources a class can access such as reading and writing to the local disk
  • 6. 6 Architecture-neutral The compiler generates an architecture-neutral object file format. The compile code can run on many processors ,given the presence of the runtime system. The java compiler does this by generting bytecode instruction which have nothing to do with a particular computer architecture. Portable We may carry the java bytecode to any platform. High-performance Java is faster than traditional interpretation since byte code is "close" to native code still somewhat slower than a compiled language (e.g., C++)
  • 7. 7 Multi-threaded A thread is like a separate program, executing concurrently. We can write Java programs that deal with many tasks at once by defining multiple threads. The main advantage of multi- threading is that it shares the same memory. Threads are important for multi-media, Web applications etc. Dynamic In number of ways, java is more dynamic language than C or C++.It was designed to adapt to an evolving environment. Libraries can freely add new methods and instance variables without any effect on their clients. In java finding out runtime type information is straightforward.
  • 8. 8 Java Virtual Machine The .class files generated by the compiler are not executable binaries, Java combines compilation and interpretation. Instead, they contain “byte-codes” to be executed by the Java Virtual Machine. This approach provides platform independence, and greater security. The JVM performs following main tasks: •Loads code •Verifies code •Executes code •Provides runtime environment
  • 9. 9 JRE JRE is an acronym for Java Runtime Environment. It is used to provide runtime environment.It is the implementation of JVM. It physically exists.It contains set of libraries + other files that JVM uses at runtime. JDK JDK is an acronym for Java Development Kit. It physically exists. It contains JRE + development tools
  • 10. 10 JVM Java Virtual Machine (JVM) is an abstract computing machine. Java Runtime Environment (JRE) is an implementation of the JVM. Java Development Kit (JDK) contains JRE along with various development tools like Java libraries, Java source compilers, Java debuggers, bundling and deployment tools.
  • 12. 12 JIT JIT refers to execution engine in few of JVM implementations, one that is faster but requires more memory, is a just-in-time compiler. In this scheme, the bytecodes of a method are compiled to native machine code the first time the method is invoked. JIT refers to execution engine in few of JVM implementations, one that is faster but requires more memory,is a just-in-time compiler. In this scheme, the bytecodes of a method are compiled to native machine code the first time the method is invoked.
  • 13. 13 Java Bytecode Java bytecode is the instruction set of the Java virtual machine. Eachbytecode is composed by one, or in some cases two, bytes that represent the instruction (opcode), along with zero or more bytes for passing parameters.. Bytecode is nothing but the intermediate representation of Java source code which is produced by the Java compiler by compiling that source code. This byte code is an machine independent code.It is not an completely a compiled code but it is an intermediate code somewhere in the middle which is later interpreted and executed by JVM
  • 14. 14 HotSpot, released as the "Java HotSpot Performance Engine"is a Java virtual machine for desktops and servers, maintained and distributed by Oracle Corporation. It features techniques such as just- in-time compilation and adaptive optimization designed to improve performance. Sun intended to write a new just-in-time (JIT) compiler for the newly developed virtual machine.This new compiler would give rise to the name "HotSpot", which derives from the fact that, as the software runs Java bytecode, it continually analyzes the program's performance for "hot spots" which are frequently or repeatedly executed. These are then targeted for optimization, leading to high- performance execution with a minimum of overhead for less performance-critical code Java HotSpot
  • 15. 15 Sun's JRE features two virtual machines, one called Client and the other Server. The Client version is tuned for quick loading. It makes use of interpretation. The Server version loads more slowly, putting more effort into producing highly optimized JI compilations, that yield higher performance. Both VMs compile only often-run methods, using a configurable invocation-count threshold to decide which methods to compile. The HotSpot Java virtual machine is written in C++. As stated on the HotSpot web page, the source contains approximately 250,000 lines of code. Hotspot provides: •A class loader •A bytecode interpreter •Client and Server virtual machines, optimized for their respective uses •Several garbage collectors •A set of supporting runtime libraries
  • 16. 16 The main() method public static void main(String args[]) { ... } public--- the interpreter can call it. static ----It is a static method belonging to the class. void -----It does not return a value. String----It always has an array of String objects as its formal parameter. the array contains any arguments passed to the program on the command line.The source file’s name must match the class name which main method is in.
  • 17. 17 Source File Declaration Rules There can be only one public class per source code file. Comments can appear at the beginning or end of any line in the source code file; they are independent of any of the positioning rules discussed here. If there is a public class in a file, the name of the file must match the name of the public class. For example, a class declared as public class Dog { }must be in a source code file named Dog.java. If the class is part of a package, the package statement must be the first line in the source code file, before any import statements that may be present.
  • 18. 18 If there are import statements, they must go between the package statement (if there is one) and the class declaration. If there isn't a package statement, then the import statement(s) must be the first line(s) in the source code file. If there are no package or import statements, the class declaration must be the first line in the source code file. import and package statements apply to all classes within a source code file. In other words, there's no way to declare multiple classes in a file and have them in different packages, or use different imports. A file can have more than one nonpublic class. Files with no public classes can have a name that does not match any of the classes in the file
  • 19. 19 Comments /* This kind of comment can span multiple lines */ // This kind is to the end of the line /** * This kind of comment is a special * ‘javadoc’ style comment */
  • 20. 20 Primitive types •int 4 bytes •short 2 bytes •long 8 bytes •byte 1 byte •float 4 bytes •double 8 bytes •char Unicode encoding (2 bytes) •boolean {true,false} Behaviors is exactly as in C++
  • 21. 21 • Constants 37 integer 37.2 float 42F float 0754 integer (octal) 0xfe integer (hexadecimal) • Comparison operators == equal != not equal < less than > greater than <= less than or equal >= greater than or equal
  • 22. 22 Variable declaration type variable-name; Meaning: variable <variable-name> will be a variable of type <type> Where type can be: int //integer double //real number Example: int a, b, c; double x; int sum;
  • 23. 23 String is an Object Constant strings as in C, does not exist  The function call show(“Hello”) creates a String object, containing “Hello”, and passes reference to it to show.  The String object is a constant. It can’t be changed using a reference to it.
  • 24. 24 Writing to user (output) System.out.println(variable-name); prints the value of variable <variable-name> to the user System.out.println(“any message “); prints the message within quotes to the user System.out.println(“hello” + “world” + a + “plus“ + b); assuming the value of a is 3 and of b is 7, it prints helloworld3plus7 Note: System.out.println() always prints on a new line.
  • 25. 25 Example /* This program illustrates the System.out.println command. */ public class Hello { public static void main (String args[]) { System.out.println(“This is my first Java program!”); System.out.print(“I like Java.”); System.out.print(“I think Java is cool.”); } // end of main } // end of class
  • 26. 26 Example /* Printing ages. */ public class MyFirstJavaProgram { public static void main (String args[]) { int myAge, myFriendAge; /* declare two integer variables */ myAge = 20; myFriendAge = myAge + 1; //one year older System.out.println(“Hello, I am “ +myAge + “years old, and my friend is “ + myFriendAge + “ years old”); System.out.println(“Goodbye”); } // end of main } // end of class
  • 27. 27 Flow control if/else do/while for switch If(x==4) { // act1 } else { // act2 } int i=5; do { // act1 i--; } while(i!=0); int j; for(int i=0;i<=9;i++) { j+=i; } char c=IN.getChar(); switch(c) { case ‘a’: case ‘b’: // act1 break; default: // act2 }
  • 28. 28 Big Numbers If the precision of the basic integer and floating-point types is not sufficient, you can turn to a couple of handy classes in the java.math package, called BigInteger and BigDecimal. These are classes for manipulating numbers with an arbitrarily long sequence of digits. The BigInteger class implements arbitrary precision integer arithmetic, and BigDecimal does the same for floating-point numbers. Use the static valueOf method to turn an ordinary number into a big number: BigInteger a = BigInteger.valueOf(100); BigInteger c = a.add(b); // c = a + b BigInteger d = c.multiply(b.add(BigInteger.valueOf(2))); // d = c * (b + 2)
  • 29. 29 Array •Array is an object • Array size is fixed A[] arr; // nothing yet … arr = new A[4]; // only array of pointers for(int i=0 ; i < arr.length ; i++) arr[i] = new Animal();
  • 30. 30 Arrays - Multidimensional • In C++ Animal arr[2][2] Is: • In Java What is the type of the object here ? A[][] arr= new A[2][2]