SlideShare a Scribd company logo
1 of 56
Download to read offline
Session 1 - Introduction to Java
 What Is Java?
 Java
Java is not just a programming language but it is a complete
platform for object oriented programming.
 JRE
Java standard class libraries which provide Application
Programming Interface and JVM together form JRE (Java Runtime
Environment).
 JDK
JDK (Java development kit) provides all the needed support for
software development in Java.
KernelTraining.com/core-java
Java Virtual Machine (JVM)
Runs the Byte Code.
Makes Java platform independent.
Handles Memory Management.
KernelTraining.com/core-java
How Java works ?
KernelTraining.com/core-java
How Java works ?
 Java compilers convert your code from human readable to
something called “byte code” in the Java world.
 “Byte code” is interpreted by a JVM, which operates much
like a physical CPU to actually execute the compiled code.
 Just-in-time (JIT) compiler is a program that turns Java byte
code into instructions that can be sent directly to the
processor.
KernelTraining.com/core-java
History
James Gosling and Sun Microsystems
Oak
Java, May 20, 1995, Sun World
Hot Java
 The first Java-enabled Web browser
JDK Evolutions
J2SE, J2ME, and J2EE
KernelTraining.com/core-java
Characteristics of Java
 Platform Independent
 Portable
 Object Oriented
 Robust & Secure
 Distributed
 Simple & Small
 Multi Threaded
 Dynamic
 Compile & Interpreted
 High Performance
KernelTraining.com/core-java
JDK Versions
 JDK Alpha and Beta (1995)
 JDK 1.0 (January 23, 1996)
 JDK 1.1 (February 19, 1997)
 J2SE 1.2 (December 8, 1998)
 J2SE 1.3 (May 8, 2000)
 J2SE 1.4 (February 6, 2002)
 J2SE 5.0 (September 30, 2004)
 Java SE 6 (December 11, 2006)
 Java SE 7 (July 28, 2011)
 Java SE 8 (March 18, 2014)
 Java SE 9
 Java SE 10
KernelTraining.com/core-java
JDK Editions
 Java Standard Edition (J2SE)
 J2SE can be used to develop client-side standalone
applications or applets.
 Java Enterprise Edition (J2EE)
 J2EE can be used to develop server-side applications
such as Java servlets and Java Server Pages.
 Java Micro Edition (J2ME).
 J2ME can be used to develop applications for mobile
devices such as cell phones.
KernelTraining.com/core-java
Java IDE Tools
Forte by Sun Microsystems
Borland JBuilder
Microsoft Visual J++
WebGain Café
IBM Visual Age for Java
KernelTraining.com/core-java
Getting Started with Java Programming
A Simple Java Application
Compiling Programs
Executing Applications
KernelTraining.com/core-java
A Simple Application
Example 1.1
//This application program prints Welcome
//to Java!
public class Welcome {
public static void main(String[] args) {
System.out.println("Welcome to Java!");
}
}
RunSource
NOTE: To run the program, install slide files on hard disk.
KernelTraining.com/core-java
Creating and Compiling Programs
On command line
 javac file.java
Source Code
Create/Modify Source Code
Compile Source Code
i.e. javac Welcome.java
Bytecode
Run Byteode
i.e. java Welcome
Result
If compilation errors
If runtime errors or incorrect result
KernelTraining.com/core-java
Example
javac Welcome.java
java Welcome
output:...
KernelTraining.com/core-java
Comments
In Java, comments are preceded by two slashes (//) in
a line,
or enclosed between /* and */ in one or multiple lines.
When the compiler sees //, it ignores all text after // in
the same line.
When it sees /*, it scans for the next */ and ignores any
text between /* and */.
KernelTraining.com/core-java
Java Basic Data Types
KernelTraining.com/core-java
Program demonstrating
DataTypes
 class Second {
 public static void main (String args[ ]) {
 int x - 90;
 short y = 4;
 float z = 10.87f;
 String name = "Sarti";
 System.Out.println( "The integer value is " + x) ;
 System.out.println ("The short value is " + y);
 System.out.println ("The float value is " + z);
 System.out.println ("The string value is " + name);
 }
 }
KernelTraining.com/core-java
 Save this file as Second. java and compile using javac Second.java at
DOS prompt.
 On successful compilation, execute the program using Java Second
 The output is displayed as :
The integer value is 90
The short value is 4
The float value is 10.87
The string value is Sarti
 The lines 3-6 depict the declaration, initialization and naming of
various data types. The values of the declared variables are printed
from lines 7-10. The + operator is used here as a concatenation
operator .
KernelTraining.com/core-java
Operators
 Operators are special symbols used in expressions.
 They include arithmetic operators, assignment
operators, increment and decrement operators,
logical operators, bitwise operators and comparison
operators.
KernelTraining.com/core-java
Arithmetic Operators
Java has five basic arithmetic operators. Each of
these operators takes two operands, one on
either side of the operator. The list of arithmetic
operators is given below:Operator Meaning Example
+ Addition 8+10
- Subtraction 10-8
* Multiplication 20*84
/ Division 10/5
% Modulus 10% 6
KernelTraining.com/core-java
Example illustrates the usage of various arithmetic operators.
 class Three {
 public static void main (String args[ ]) {
 int x = 10;
 int y = 20;
 float z = 25.98f;
 System.out.println ("The value of x + y is " + (x + y));
 System. out. println ("The value of z - y is " + (z - y) );
 System.out.println ("The value of x * y is " + (x * y));
 System.out.println ("The value of z / y is " + (z / y));
 System.out.println ("The value of z % y is " + (z % y));
 }
 }
KernelTraining.com/core-java
 Save this file as Three.java and compile using javac
Three.java at DOS prompt.
 On successful compilation, execute the source code using:
Java Three
 The output appears as shown below:
The value of x + y is 30
The value of z - y is 5.98
The value of x * y is 200
The value of z / y is 1.299
The value of z % y is 5.98
 Notice the usage of the various arithmetic operators from
lines 6-10.
KernelTraining.com/core-java
Assignment Operators
The assignment operators used in C and C++ are also
used in Java. A selection of assignment operators is
given.
Expression Meaning
x += y x = x + y
x -+ y x = x-y
x *= y x = x * y
x /= y x = x /y
x=y x=y
KernelTraining.com/core-java
Example demonstrates the various operator assignments in
action.
 class assign{
 public static void main(String args[ ]) {
 int a=1;
 int b=2;
 int c=3;
 a+=5;
 b*=4;
 c+=a*b;
 c%=6;
 System.out.println ("a=" +a);
 System.out.println("b=" +b);
 System.out.println("c=" +c);
 }
 }
KernelTraining.com/core-java
 Save this file as assign.java and compile using javac
assign.java at DOS prompt.
 On successful compilation, execute the source code
using: Java assign
 The output appears as shown below:
a=6
b=8
c=3
KernelTraining.com/core-java
Incrementing andDecrementing
 To increment or decrement a value by one, the ++ operator and
— operator are used respectively. The increment and the
decrement operators can be prefixed or post fixed. The different
increment and decrement operators can be used as given below:
 ++a (Pre increment operator) -Increment a by 1, then use the
new value of a in the expression in which a resides.
 a++ (Post increment operator) - Use the current value of a in
the expression in which a resides and then increment a by 1.
 - -b (Pre decrement operator) - Decrement b by 1, then use the
new value of b in the expression in which b resides.
 b- -(Post decrement operator) - Use the current value of b in the
expression in which b resides and then decrement b by 1.
KernelTraining.com/core-java
Example demonstrates the usage of the increment and decrement
operators.
 class IncDec {
 public static void main (String args[ ] ) {
 int a =1;
 int b=2;
 int c=++b;
 int d=a++;
 C++;
 System.out.println ("a =" +a);
 System.out.println ("b =" +b);
 System.out.println ("c =" +c);
 System.out.println ("d =" +d) ;
 }
 }
KernelTraining.com/core-java
 Save this file as IncDec.java and compile using javac
IncDec.java at DOS prompt.
 On successful compilation, execute the source code
using : Java IncDec
 The output appears as given below:
a=2
b=3
c=4
d=l
KernelTraining.com/core-java
Comparison Operators
There are several expressions for testing equality
and magnitude. All these expressions return a
Boolean value. Table 1.5 enlists the comparison
operators.Operator Meaning Example
== Equal u==45
! = Not equal u!=75
< Less than u<85
> Greater than u>68
<= Less than or equal to u <= 53
>= Greater than or equal to u >= 64
KernelTraining.com/core-java
Logical Operators
 Logical operators available are AND, OR, XOR and NOT.
 The AND operator (& or &&) returns true only if both sides in
an expression are true. If any one side fails, the operator returns
false. For example, consider the following statement
 gender ==1 && age >=65
 This condition is true if and only if both the simple conditions
are true. In the && operator, if the left side of the expression
returns false, the whole expression returns false and the right
side is totally neglected. The & operator evaluates both sides
irrespective of outcome.
KernelTraining.com/core-java
 The I or II is used for OR combination. This returns true if any of
the expressions is true. Only if all the conditions are false, the
expression is false.Consider the following statement
semesterAverage>=90 | | finalExam >=90
 The above condition is true if either of the two conditions is true.
The II evaluates the left expression first and if it returns true,
never evaluates the right side expression. A single I evaluates
both the expressions regardless of the outcome.
 The XOR operator indicated by ^, returns true only if its operands
are different. If both its operands are similar (true-true, false-
false), it returns false.
 The ! operator is used for NOT. The value of NOT is negation of
the expression.
KernelTraining.com/core-java
Bitwise Operators
The bitwise operators are inherited from C and
C++. They are used to perform operations on
individual bits in integers. A list of the bitwise
operators available is given
Operator Meaning
& Bitwise AND
I Bitwise OR
^ Bitwise XOR
<< Left Shift
>> Right Shift
>>>> Zero fill right shift
~ Bitwise Complement
<<= Left Shift assignment
>>= Right Shift assignment
>>>= Zero fill right shift assignment
x&=y AND assignment
x l=y OR assignment
x ^= y XOR assignment
KernelTraining.com/core-java
The following example demonstrates the usage of bitwise operators.
 class BitOp {
 public static void main (String args [ ]) {
 int a=1;
 int b=2;
 int c=3;
 a=a|4;
 b>>=1;
 c<<=1;
 a=a^c;
 System.out.println ("a=" +a);
 System. out.println ("b=" +b);
 System.out.println ("c=" +c);
 }
 }
KernelTraining.com/core-java
 Save this file as BitOp.java and compile using javac BitOp.java at DOS
prompt.
 On successful compilation, execute the source code using : Java BitOp
 The output appears as shown.
a=3
b=1
c=6
KernelTraining.com/core-java
Programming Constructs
 Programming constructs in Java are the if construct and ternary
operator, switch statement, the while, do while and for loops.
 The If Construct
 The if else construct executes different bits of code based on
successful completion of a condition, that returns only boolean
values. If the execution is unsuccessful, the sets of instructions
under else are executed.
if (condition)
body of loop;
else
body of loop;
KernelTraining.com/core-java
The following example illustrates usage of the if else construct and logical operators.
 class Four{
 public static void main (String args[ ]) {
 int month = 4;
 String season;
 if (month==12 || month = =1 || month = =2) {
 seasons="Winter";
 }
 else if (month = =3 || month = =4 || month = =5){
 season="Spring";
 }
 else if (month = =6 | | month = =7 | | month = =8){
 season="Summer";
 }
 else if (month = =9 | | month = =10 | | month = =11) {
 season="Autunm";
 }
KernelTraining.com/core-java
 else{
 season="Invalid month";
 }
 System.out-println ("April is in " + season + ".");
 }
 }
 Save this as Four.java and compile using javac Four .Java at DOS
prompt.
 On successful compilation execute, using Java Four.
 The output of the program is given below:
April is in Spring
KernelTraining.com/core-java
Conditional Operator
 The conditional operator is otherwise known as the
ternary operator and is considered to be an
alternative to the if else construct. It returns a value
and the syntax is:
 test ? pass : fail
 If the value of test is true, the conditional operator
returns pass, else it returns fail. The following
example delineates the usage of the ternary operator.
KernelTraining.com/core-java
class Ternary {
 public static void main (String args[ ]) {
 int i = 10;
 int j = 78;
 int z = 0;
 z=i < j ? i : j;
 System.out.println ("The value assigned is " + z);
 }
 }
KernelTraining.com/core-java
 Save this file as Five.java and compile using javac
Five.java at DOS prompt.
 On successful compilation execute using: Java Five.
 The output is given below:
The value assigned is 10
Note the usage of conditional operator at line number
6. If the value of the variable i is less than j, then z
contains the value of i, else it contains the value-of j.
KernelTraining.com/core-java
The while loop
The while loop executes a set of code repeatedly until
the condition returns false. The syntax of the while
loop is given below:
while (condition ) {
body of loop;
}
The do while loop is similar to the while loop except
that the condition to be evaluated is given at the end.
Hence the loop is executed at least once even when the
condition is false.
KernelTraining.com/core-java
Example depicts the usage of the while loop. class Fibo {
 public static void main (String args[ ]) {
 int max = 25;
 int prev =0;
 int next = 1;
 int sum;
 while (next <= max)
 {
 System.out.println ("The Fibonacci series is "+next);
 sum = prev + next;
 prev = next;
 next = sum;
 }
 }
 }KernelTraining.com/core-java
 Save this file as Fibo.java and compile using javac Fibo.java at DOS prompt.
 On successful compilation, execute using Java Fibo.
 The output appears as given below:
The Fibonacci series is 1
The Fibonacci series is 1
The Fibonacci series is 2
The Fibonacci series is 3
The Fibonacci series is 5
The Fibonacci series is 8
The Fibonacci series is 13
The Fibonacci series is 21
 The while loop, shown from line 7 - 13, is executed as long as the value of the
variable next is less than or equal to 25. This program generates the Fibonacci
series
KernelTraining.com/core-java
The for loop
 The for loop repeats a set of statements a certain number of
times until a condition is matched. It is commonly used for
simple iteration. The for loop appears as shown.
for (initialization; test; expression) )
set of statements;
}
 In the first part a variable is initialized to a value. The second
part consists of a test condition that returns only a Boolean. The
last part is an expression, evaluated every time the loop is
executed.
 The following example depicts the usage of the for loop.
KernelTraining.com/core-java
 class ForDemo {
 public static void main (String args[ ]) {
 int i;
 for (i = 0;i < 10;i=i+2)
 {
 if ((i%2) = = 0)
 System.out.println ("The number"+1+"is a even number");
 }
 }
 }
KernelTraining.com/core-java
 Save this file as ForDemo.java and compile using javac
ForDemo.java at DOS prompt.
 On successful compilation, execute using Java ForDemo.
 The output appears as given below:
The number 0 is an even number
The number 2 is an even number
The number 4 is an even number
The number 6 is an even number
The number 8 is an even number
 This example generates even numbers that are less than 8.
Notice the usage of the for loop from line numbers 4-8.
KernelTraining.com/core-java
Switch Statement
The switch statement dispatches control to the
different parts of the code based on the value of a
single variable or expression. The value of
expression is compared with each of the literal
values in the case statements. If they match, the
following code sequence is executed. Otherwise
an optional default statement is executed. The
general form of switch statement is given below.
KernelTraining.com/core-java
switch (test) {
case valueone:
resultone;
break;
case valuetwo:
resulttwo;
break;
default :
defaultresult;
}
 An illustration of the switch statement's usage is given below in Example
KernelTraining.com/core-java
 class season {
 public static void. main (String args[ ]) {
 int v = 4;
 switch(v) {
 case 1:
 case 2:
 case 3:
 System.out.println ("Spring is around the corner");
 break;
 case 4:
 case 5:
 case 6:
 System.out.println ("Summer is scorching its way through");
KernelTraining.com/core-java
 break;
 case 7:
 case 8:
 case 9:
 System.out.println ("Autumn leaves are abundant");
 break;
 case 10:
 case 11:
 case 12:
 System.out.println ("Winter is freezing");
 break;
 }
 }
 }
KernelTraining.com/core-java
 Save this file as season.java and compile using javac season.java at
DOS prompt.
 On successful compilation, execute using Java season.
 The output appears as given below:
 Summer is scorching its way through
 Note the usage of the switch statement between lines 4 - 25.
KernelTraining.com/core-java
Break and Continue
The break keyword halts the execution of the
current loop and forces control out of the loop.
The term break refers to the act of breaking out
of a block of code. It tells the runtime to pick up
execution past the end of the named block. In
order to refer to a block by name, Java has a label
construct that assigns a name to every block.
The following example demonstrates the usage of
break statement.
KernelTraining.com/core-java
 class breakdemo {
 public static void main (String args[ ] ) {
 boolean t=true;
 {
 {
 {
 System.out.println ("Before the break");
 if (t)
 break b;
 System.out.println ("This will not execute");
 }
 System.out.println ("This will not execute");
 }
 System.out.println ("This is after b");
 }
 }
 }
KernelTraining.com/core-java
 Save this file as breakdemo.java and compile using javac
breakdemo.java at DOS prompt.
 On successful compilation, execute using Java breakdemo.
 The output appears as given below:
Before the break
This is after b
 continue is similar to break, except that instead of halting the
execution of the loop, it starts the next iteration.
 The following example demonstrates the usage of continue
statement.
KernelTraining.com/core-java
 class continuedemo {
 public static void main (String args[ ]) {
 for (int i=0; i<10; i++) {
 System.out.print (+i+ " ");
 if (i % 2 == 0)
 continue;
 System.out.println (" ");
 }
 }
 }
KernelTraining.com/core-java
Save this file as continuedemo.java and compile using
javac continuedemo.java at DOS prompt.
 On successful compilation, execute using Java
continuedemo.
 The output appears as given below:
0 1
2 3
4 5
6 7
8 9
KernelTraining.com/core-java

More Related Content

What's hot (20)

Basic Java Programming
Basic Java ProgrammingBasic Java Programming
Basic Java Programming
 
Java Presentation For Syntax
Java Presentation For SyntaxJava Presentation For Syntax
Java Presentation For Syntax
 
Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz Java history, versions, types of errors and exception, quiz
Java history, versions, types of errors and exception, quiz
 
Java features
Java featuresJava features
Java features
 
Java 101 Intro to Java Programming
Java 101 Intro to Java ProgrammingJava 101 Intro to Java Programming
Java 101 Intro to Java Programming
 
Introduction to java 101
Introduction to java 101Introduction to java 101
Introduction to java 101
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Java training in delhi
Java training in delhiJava training in delhi
Java training in delhi
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
New Features Of JDK 7
New Features Of JDK 7New Features Of JDK 7
New Features Of JDK 7
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Java &amp; advanced java
Java &amp; advanced javaJava &amp; advanced java
Java &amp; advanced java
 
Core java online training
Core java online trainingCore java online training
Core java online training
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
1 java programming- introduction
1  java programming- introduction1  java programming- introduction
1 java programming- introduction
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
 
Java platform
Java platformJava platform
Java platform
 
Java basic introduction
Java basic introductionJava basic introduction
Java basic introduction
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
 
Java Notes
Java Notes Java Notes
Java Notes
 

Viewers also liked

Viewers also liked (8)

Php peers
Php peersPhp peers
Php peers
 
Core java
Core javaCore java
Core java
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
 
Core java
Core javaCore java
Core java
 
Presentation on java
Presentation  on  javaPresentation  on  java
Presentation on java
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Java basic
Java basicJava basic
Java basic
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
 

Similar to Core Java introduction | Basics | free course

Similar to Core Java introduction | Basics | free course (20)

In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
 
Java introduction
Java introductionJava introduction
Java introduction
 
Bt0074 oops with java
Bt0074 oops with javaBt0074 oops with java
Bt0074 oops with java
 
Hello java
Hello java   Hello java
Hello java
 
Hello Java-First Level
Hello Java-First LevelHello Java-First Level
Hello Java-First Level
 
Hello java
Hello java  Hello java
Hello java
 
Java basic concept
Java basic conceptJava basic concept
Java basic concept
 
College Project - Java Disassembler - Description
College Project - Java Disassembler - DescriptionCollege Project - Java Disassembler - Description
College Project - Java Disassembler - Description
 
Proyect of english
Proyect of englishProyect of english
Proyect of english
 
Javascript
JavascriptJavascript
Javascript
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
Knowledge of Javascript
Knowledge of JavascriptKnowledge of Javascript
Knowledge of Javascript
 
1- java
1- java1- java
1- java
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
Java7
Java7Java7
Java7
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Javalecture 1
Javalecture 1Javalecture 1
Javalecture 1
 
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)
 
JAVA(module1).pptx
JAVA(module1).pptxJAVA(module1).pptx
JAVA(module1).pptx
 
Operators in java
Operators in javaOperators in java
Operators in java
 

Recently uploaded

Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...raviapr7
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxAditiChauhan701637
 
3.26.24 Race, the Draft, and the Vietnam War.pptx
3.26.24 Race, the Draft, and the Vietnam War.pptx3.26.24 Race, the Draft, and the Vietnam War.pptx
3.26.24 Race, the Draft, and the Vietnam War.pptxmary850239
 
Protein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptxProtein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptxvidhisharma994099
 
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
 
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
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxDr. Asif Anas
 
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...Dr. Asif Anas
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxraviapr7
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptxSandy Millin
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptxraviapr7
 
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
 
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya
 
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTDR. SNEHA NAIR
 
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptxSlides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptxCapitolTechU
 
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
 
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
 
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
 
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
 

Recently uploaded (20)

Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...Patient Counselling. Definition of patient counseling; steps involved in pati...
Patient Counselling. Definition of patient counseling; steps involved in pati...
 
In - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptxIn - Vivo and In - Vitro Correlation.pptx
In - Vivo and In - Vitro Correlation.pptx
 
3.26.24 Race, the Draft, and the Vietnam War.pptx
3.26.24 Race, the Draft, and the Vietnam War.pptx3.26.24 Race, the Draft, and the Vietnam War.pptx
3.26.24 Race, the Draft, and the Vietnam War.pptx
 
Protein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptxProtein Structure - threading Protein modelling pptx
Protein Structure - threading Protein modelling pptx
 
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
 
Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.Drug Information Services- DIC and Sources.
Drug Information Services- DIC and Sources.
 
Ultra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptxUltra structure and life cycle of Plasmodium.pptx
Ultra structure and life cycle of Plasmodium.pptx
 
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...
Unveiling the Intricacies of Leishmania donovani: Structure, Life Cycle, Path...
 
Prescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptxPrescribed medication order and communication skills.pptx
Prescribed medication order and communication skills.pptx
 
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdfPersonal Resilience in Project Management 2 - TV Edit 1a.pdf
Personal Resilience in Project Management 2 - TV Edit 1a.pdf
 
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
2024.03.23 What do successful readers do - Sandy Millin for PARK.pptx
 
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptxClinical Pharmacy  Introduction to Clinical Pharmacy, Concept of clinical pptx
Clinical Pharmacy Introduction to Clinical Pharmacy, Concept of clinical pptx
 
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
 
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....Riddhi Kevadiya. WILLIAM SHAKESPEARE....
Riddhi Kevadiya. WILLIAM SHAKESPEARE....
 
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINTARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
ARTICULAR DISC OF TEMPOROMANDIBULAR JOINT
 
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.pptxSlides CapTechTalks Webinar March 2024 Joshua Sinai.pptx
Slides CapTechTalks Webinar March 2024 Joshua Sinai.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.
 
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
 
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
 
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
 

Core Java introduction | Basics | free course

  • 1. Session 1 - Introduction to Java
  • 2.  What Is Java?  Java Java is not just a programming language but it is a complete platform for object oriented programming.  JRE Java standard class libraries which provide Application Programming Interface and JVM together form JRE (Java Runtime Environment).  JDK JDK (Java development kit) provides all the needed support for software development in Java. KernelTraining.com/core-java
  • 3. Java Virtual Machine (JVM) Runs the Byte Code. Makes Java platform independent. Handles Memory Management. KernelTraining.com/core-java
  • 4. How Java works ? KernelTraining.com/core-java
  • 5. How Java works ?  Java compilers convert your code from human readable to something called “byte code” in the Java world.  “Byte code” is interpreted by a JVM, which operates much like a physical CPU to actually execute the compiled code.  Just-in-time (JIT) compiler is a program that turns Java byte code into instructions that can be sent directly to the processor. KernelTraining.com/core-java
  • 6. History James Gosling and Sun Microsystems Oak Java, May 20, 1995, Sun World Hot Java  The first Java-enabled Web browser JDK Evolutions J2SE, J2ME, and J2EE KernelTraining.com/core-java
  • 7. Characteristics of Java  Platform Independent  Portable  Object Oriented  Robust & Secure  Distributed  Simple & Small  Multi Threaded  Dynamic  Compile & Interpreted  High Performance KernelTraining.com/core-java
  • 8. JDK Versions  JDK Alpha and Beta (1995)  JDK 1.0 (January 23, 1996)  JDK 1.1 (February 19, 1997)  J2SE 1.2 (December 8, 1998)  J2SE 1.3 (May 8, 2000)  J2SE 1.4 (February 6, 2002)  J2SE 5.0 (September 30, 2004)  Java SE 6 (December 11, 2006)  Java SE 7 (July 28, 2011)  Java SE 8 (March 18, 2014)  Java SE 9  Java SE 10 KernelTraining.com/core-java
  • 9. JDK Editions  Java Standard Edition (J2SE)  J2SE can be used to develop client-side standalone applications or applets.  Java Enterprise Edition (J2EE)  J2EE can be used to develop server-side applications such as Java servlets and Java Server Pages.  Java Micro Edition (J2ME).  J2ME can be used to develop applications for mobile devices such as cell phones. KernelTraining.com/core-java
  • 10. Java IDE Tools Forte by Sun Microsystems Borland JBuilder Microsoft Visual J++ WebGain Café IBM Visual Age for Java KernelTraining.com/core-java
  • 11. Getting Started with Java Programming A Simple Java Application Compiling Programs Executing Applications KernelTraining.com/core-java
  • 12. A Simple Application Example 1.1 //This application program prints Welcome //to Java! public class Welcome { public static void main(String[] args) { System.out.println("Welcome to Java!"); } } RunSource NOTE: To run the program, install slide files on hard disk. KernelTraining.com/core-java
  • 13. Creating and Compiling Programs On command line  javac file.java Source Code Create/Modify Source Code Compile Source Code i.e. javac Welcome.java Bytecode Run Byteode i.e. java Welcome Result If compilation errors If runtime errors or incorrect result KernelTraining.com/core-java
  • 15. Comments In Java, comments are preceded by two slashes (//) in a line, or enclosed between /* and */ in one or multiple lines. When the compiler sees //, it ignores all text after // in the same line. When it sees /*, it scans for the next */ and ignores any text between /* and */. KernelTraining.com/core-java
  • 16. Java Basic Data Types KernelTraining.com/core-java
  • 17. Program demonstrating DataTypes  class Second {  public static void main (String args[ ]) {  int x - 90;  short y = 4;  float z = 10.87f;  String name = "Sarti";  System.Out.println( "The integer value is " + x) ;  System.out.println ("The short value is " + y);  System.out.println ("The float value is " + z);  System.out.println ("The string value is " + name);  }  } KernelTraining.com/core-java
  • 18.  Save this file as Second. java and compile using javac Second.java at DOS prompt.  On successful compilation, execute the program using Java Second  The output is displayed as : The integer value is 90 The short value is 4 The float value is 10.87 The string value is Sarti  The lines 3-6 depict the declaration, initialization and naming of various data types. The values of the declared variables are printed from lines 7-10. The + operator is used here as a concatenation operator . KernelTraining.com/core-java
  • 19. Operators  Operators are special symbols used in expressions.  They include arithmetic operators, assignment operators, increment and decrement operators, logical operators, bitwise operators and comparison operators. KernelTraining.com/core-java
  • 20. Arithmetic Operators Java has five basic arithmetic operators. Each of these operators takes two operands, one on either side of the operator. The list of arithmetic operators is given below:Operator Meaning Example + Addition 8+10 - Subtraction 10-8 * Multiplication 20*84 / Division 10/5 % Modulus 10% 6 KernelTraining.com/core-java
  • 21. Example illustrates the usage of various arithmetic operators.  class Three {  public static void main (String args[ ]) {  int x = 10;  int y = 20;  float z = 25.98f;  System.out.println ("The value of x + y is " + (x + y));  System. out. println ("The value of z - y is " + (z - y) );  System.out.println ("The value of x * y is " + (x * y));  System.out.println ("The value of z / y is " + (z / y));  System.out.println ("The value of z % y is " + (z % y));  }  } KernelTraining.com/core-java
  • 22.  Save this file as Three.java and compile using javac Three.java at DOS prompt.  On successful compilation, execute the source code using: Java Three  The output appears as shown below: The value of x + y is 30 The value of z - y is 5.98 The value of x * y is 200 The value of z / y is 1.299 The value of z % y is 5.98  Notice the usage of the various arithmetic operators from lines 6-10. KernelTraining.com/core-java
  • 23. Assignment Operators The assignment operators used in C and C++ are also used in Java. A selection of assignment operators is given. Expression Meaning x += y x = x + y x -+ y x = x-y x *= y x = x * y x /= y x = x /y x=y x=y KernelTraining.com/core-java
  • 24. Example demonstrates the various operator assignments in action.  class assign{  public static void main(String args[ ]) {  int a=1;  int b=2;  int c=3;  a+=5;  b*=4;  c+=a*b;  c%=6;  System.out.println ("a=" +a);  System.out.println("b=" +b);  System.out.println("c=" +c);  }  } KernelTraining.com/core-java
  • 25.  Save this file as assign.java and compile using javac assign.java at DOS prompt.  On successful compilation, execute the source code using: Java assign  The output appears as shown below: a=6 b=8 c=3 KernelTraining.com/core-java
  • 26. Incrementing andDecrementing  To increment or decrement a value by one, the ++ operator and — operator are used respectively. The increment and the decrement operators can be prefixed or post fixed. The different increment and decrement operators can be used as given below:  ++a (Pre increment operator) -Increment a by 1, then use the new value of a in the expression in which a resides.  a++ (Post increment operator) - Use the current value of a in the expression in which a resides and then increment a by 1.  - -b (Pre decrement operator) - Decrement b by 1, then use the new value of b in the expression in which b resides.  b- -(Post decrement operator) - Use the current value of b in the expression in which b resides and then decrement b by 1. KernelTraining.com/core-java
  • 27. Example demonstrates the usage of the increment and decrement operators.  class IncDec {  public static void main (String args[ ] ) {  int a =1;  int b=2;  int c=++b;  int d=a++;  C++;  System.out.println ("a =" +a);  System.out.println ("b =" +b);  System.out.println ("c =" +c);  System.out.println ("d =" +d) ;  }  } KernelTraining.com/core-java
  • 28.  Save this file as IncDec.java and compile using javac IncDec.java at DOS prompt.  On successful compilation, execute the source code using : Java IncDec  The output appears as given below: a=2 b=3 c=4 d=l KernelTraining.com/core-java
  • 29. Comparison Operators There are several expressions for testing equality and magnitude. All these expressions return a Boolean value. Table 1.5 enlists the comparison operators.Operator Meaning Example == Equal u==45 ! = Not equal u!=75 < Less than u<85 > Greater than u>68 <= Less than or equal to u <= 53 >= Greater than or equal to u >= 64 KernelTraining.com/core-java
  • 30. Logical Operators  Logical operators available are AND, OR, XOR and NOT.  The AND operator (& or &&) returns true only if both sides in an expression are true. If any one side fails, the operator returns false. For example, consider the following statement  gender ==1 && age >=65  This condition is true if and only if both the simple conditions are true. In the && operator, if the left side of the expression returns false, the whole expression returns false and the right side is totally neglected. The & operator evaluates both sides irrespective of outcome. KernelTraining.com/core-java
  • 31.  The I or II is used for OR combination. This returns true if any of the expressions is true. Only if all the conditions are false, the expression is false.Consider the following statement semesterAverage>=90 | | finalExam >=90  The above condition is true if either of the two conditions is true. The II evaluates the left expression first and if it returns true, never evaluates the right side expression. A single I evaluates both the expressions regardless of the outcome.  The XOR operator indicated by ^, returns true only if its operands are different. If both its operands are similar (true-true, false- false), it returns false.  The ! operator is used for NOT. The value of NOT is negation of the expression. KernelTraining.com/core-java
  • 32. Bitwise Operators The bitwise operators are inherited from C and C++. They are used to perform operations on individual bits in integers. A list of the bitwise operators available is given Operator Meaning & Bitwise AND I Bitwise OR ^ Bitwise XOR << Left Shift >> Right Shift >>>> Zero fill right shift ~ Bitwise Complement <<= Left Shift assignment >>= Right Shift assignment >>>= Zero fill right shift assignment x&=y AND assignment x l=y OR assignment x ^= y XOR assignment KernelTraining.com/core-java
  • 33. The following example demonstrates the usage of bitwise operators.  class BitOp {  public static void main (String args [ ]) {  int a=1;  int b=2;  int c=3;  a=a|4;  b>>=1;  c<<=1;  a=a^c;  System.out.println ("a=" +a);  System. out.println ("b=" +b);  System.out.println ("c=" +c);  }  } KernelTraining.com/core-java
  • 34.  Save this file as BitOp.java and compile using javac BitOp.java at DOS prompt.  On successful compilation, execute the source code using : Java BitOp  The output appears as shown. a=3 b=1 c=6 KernelTraining.com/core-java
  • 35. Programming Constructs  Programming constructs in Java are the if construct and ternary operator, switch statement, the while, do while and for loops.  The If Construct  The if else construct executes different bits of code based on successful completion of a condition, that returns only boolean values. If the execution is unsuccessful, the sets of instructions under else are executed. if (condition) body of loop; else body of loop; KernelTraining.com/core-java
  • 36. The following example illustrates usage of the if else construct and logical operators.  class Four{  public static void main (String args[ ]) {  int month = 4;  String season;  if (month==12 || month = =1 || month = =2) {  seasons="Winter";  }  else if (month = =3 || month = =4 || month = =5){  season="Spring";  }  else if (month = =6 | | month = =7 | | month = =8){  season="Summer";  }  else if (month = =9 | | month = =10 | | month = =11) {  season="Autunm";  } KernelTraining.com/core-java
  • 37.  else{  season="Invalid month";  }  System.out-println ("April is in " + season + ".");  }  }  Save this as Four.java and compile using javac Four .Java at DOS prompt.  On successful compilation execute, using Java Four.  The output of the program is given below: April is in Spring KernelTraining.com/core-java
  • 38. Conditional Operator  The conditional operator is otherwise known as the ternary operator and is considered to be an alternative to the if else construct. It returns a value and the syntax is:  test ? pass : fail  If the value of test is true, the conditional operator returns pass, else it returns fail. The following example delineates the usage of the ternary operator. KernelTraining.com/core-java
  • 39. class Ternary {  public static void main (String args[ ]) {  int i = 10;  int j = 78;  int z = 0;  z=i < j ? i : j;  System.out.println ("The value assigned is " + z);  }  } KernelTraining.com/core-java
  • 40.  Save this file as Five.java and compile using javac Five.java at DOS prompt.  On successful compilation execute using: Java Five.  The output is given below: The value assigned is 10 Note the usage of conditional operator at line number 6. If the value of the variable i is less than j, then z contains the value of i, else it contains the value-of j. KernelTraining.com/core-java
  • 41. The while loop The while loop executes a set of code repeatedly until the condition returns false. The syntax of the while loop is given below: while (condition ) { body of loop; } The do while loop is similar to the while loop except that the condition to be evaluated is given at the end. Hence the loop is executed at least once even when the condition is false. KernelTraining.com/core-java
  • 42. Example depicts the usage of the while loop. class Fibo {  public static void main (String args[ ]) {  int max = 25;  int prev =0;  int next = 1;  int sum;  while (next <= max)  {  System.out.println ("The Fibonacci series is "+next);  sum = prev + next;  prev = next;  next = sum;  }  }  }KernelTraining.com/core-java
  • 43.  Save this file as Fibo.java and compile using javac Fibo.java at DOS prompt.  On successful compilation, execute using Java Fibo.  The output appears as given below: The Fibonacci series is 1 The Fibonacci series is 1 The Fibonacci series is 2 The Fibonacci series is 3 The Fibonacci series is 5 The Fibonacci series is 8 The Fibonacci series is 13 The Fibonacci series is 21  The while loop, shown from line 7 - 13, is executed as long as the value of the variable next is less than or equal to 25. This program generates the Fibonacci series KernelTraining.com/core-java
  • 44. The for loop  The for loop repeats a set of statements a certain number of times until a condition is matched. It is commonly used for simple iteration. The for loop appears as shown. for (initialization; test; expression) ) set of statements; }  In the first part a variable is initialized to a value. The second part consists of a test condition that returns only a Boolean. The last part is an expression, evaluated every time the loop is executed.  The following example depicts the usage of the for loop. KernelTraining.com/core-java
  • 45.  class ForDemo {  public static void main (String args[ ]) {  int i;  for (i = 0;i < 10;i=i+2)  {  if ((i%2) = = 0)  System.out.println ("The number"+1+"is a even number");  }  }  } KernelTraining.com/core-java
  • 46.  Save this file as ForDemo.java and compile using javac ForDemo.java at DOS prompt.  On successful compilation, execute using Java ForDemo.  The output appears as given below: The number 0 is an even number The number 2 is an even number The number 4 is an even number The number 6 is an even number The number 8 is an even number  This example generates even numbers that are less than 8. Notice the usage of the for loop from line numbers 4-8. KernelTraining.com/core-java
  • 47. Switch Statement The switch statement dispatches control to the different parts of the code based on the value of a single variable or expression. The value of expression is compared with each of the literal values in the case statements. If they match, the following code sequence is executed. Otherwise an optional default statement is executed. The general form of switch statement is given below. KernelTraining.com/core-java
  • 48. switch (test) { case valueone: resultone; break; case valuetwo: resulttwo; break; default : defaultresult; }  An illustration of the switch statement's usage is given below in Example KernelTraining.com/core-java
  • 49.  class season {  public static void. main (String args[ ]) {  int v = 4;  switch(v) {  case 1:  case 2:  case 3:  System.out.println ("Spring is around the corner");  break;  case 4:  case 5:  case 6:  System.out.println ("Summer is scorching its way through"); KernelTraining.com/core-java
  • 50.  break;  case 7:  case 8:  case 9:  System.out.println ("Autumn leaves are abundant");  break;  case 10:  case 11:  case 12:  System.out.println ("Winter is freezing");  break;  }  }  } KernelTraining.com/core-java
  • 51.  Save this file as season.java and compile using javac season.java at DOS prompt.  On successful compilation, execute using Java season.  The output appears as given below:  Summer is scorching its way through  Note the usage of the switch statement between lines 4 - 25. KernelTraining.com/core-java
  • 52. Break and Continue The break keyword halts the execution of the current loop and forces control out of the loop. The term break refers to the act of breaking out of a block of code. It tells the runtime to pick up execution past the end of the named block. In order to refer to a block by name, Java has a label construct that assigns a name to every block. The following example demonstrates the usage of break statement. KernelTraining.com/core-java
  • 53.  class breakdemo {  public static void main (String args[ ] ) {  boolean t=true;  {  {  {  System.out.println ("Before the break");  if (t)  break b;  System.out.println ("This will not execute");  }  System.out.println ("This will not execute");  }  System.out.println ("This is after b");  }  }  } KernelTraining.com/core-java
  • 54.  Save this file as breakdemo.java and compile using javac breakdemo.java at DOS prompt.  On successful compilation, execute using Java breakdemo.  The output appears as given below: Before the break This is after b  continue is similar to break, except that instead of halting the execution of the loop, it starts the next iteration.  The following example demonstrates the usage of continue statement. KernelTraining.com/core-java
  • 55.  class continuedemo {  public static void main (String args[ ]) {  for (int i=0; i<10; i++) {  System.out.print (+i+ " ");  if (i % 2 == 0)  continue;  System.out.println (" ");  }  }  } KernelTraining.com/core-java
  • 56. Save this file as continuedemo.java and compile using javac continuedemo.java at DOS prompt.  On successful compilation, execute using Java continuedemo.  The output appears as given below: 0 1 2 3 4 5 6 7 8 9 KernelTraining.com/core-java