SlideShare a Scribd company logo
1 of 47
Download to read offline
9801 200 111 | info@neosphere.com.np
9801 200 111 | info@neosphere.com.np
Application Fundamentals
9801 200 111 | info@neosphere.com.np
Types of Software
https://whatis.techtarget.com/definition/system-software
System Software
https://searchsoftwarequality.techtarget.com/definition/application
Application Software
Application
Software
Games, MS Office,
Browser etc.
System Software
Operating System,
Tools & Utilities,
Compilers
Hardware
Disk, CPU, RAM
9801 200 111 | info@neosphere.com.np
Types of
Application
Web Desktop Mobile
▪ Java
▪ .NET
▪ PHP
▪ Python
▪ Others
▪ Java
▪ .NET
▪ Python
▪ Others
▪ Android (java, Kotlin)
▪ iOS (Swift)
L
a
n
g
u
a
g
e
s
9801 200 111 | info@neosphere.com.np
We require
database to
store data
9801 200 111 | info@neosphere.com.np
Driver
We require JDBC (Java
Database Connectivity) Driver
to perform operation with
Databases
9801 200 111 | info@neosphere.com.np
It is intended to let application developers "write once,
run anywhere" (WORA), meaning that compiled Java
code can run on all platforms that support Java without
the need for recompilation.
9801 200 111 | info@neosphere.com.np
Java is Object Oriented
9801 200 111 | info@neosphere.com.np
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
Compile: javac filename.java
Run: java ClassName
9801 200 111 | info@neosphere.com.np
javac HelloWorld.java
Compile:
java HelloWorld
Run:
9801 200 111 | info@neosphere.com.np
This is the entry point of our Java program. the main method has to have this
exact signature in order to be able to run our program.
public again means that anyone can access it.
static means that you can run this method without creating an instance of
HelloWorld.
void means that this method doesn't return any value.
main is the name of the method.
9801 200 111 | info@neosphere.com.np
• The HelloWorld.java file is known as source code file.
• It is compiled by invoking tool named javac.exe, which compiles the source code into a .class file.
• The .class file contains the bytecode which is interpreted by java.exe tool.
• java.exe interprets the bytecode and runs the program.
9801 200 111 | info@neosphere.com.np
Package in Java
A package in Java is used to group related classes. Think of it as a folder
in a file directory. We use packages to avoid name conflicts, and to
write a better maintainable code. Packages are divided into two
categories:
9801 200 111 | info@neosphere.com.np
Java Packages
• Built-in Packages (packages from the Java API)
• User-defined Packages (create your own packages)
9801 200 111 | info@neosphere.com.np
Importing packages
import package.name.Class; // Import a single class
import package.name.*; // Import the whole package
9801 200 111 | info@neosphere.com.np
Scanner Class in Java
import java.util.Scanner;
class MyClass {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in);
System.out.println("Enter username");
String userName = myObj.nextLine();
System.out.println("Username is: " + userName);
}
}
9801 200 111 | info@neosphere.com.np
To import a whole package,
end the statement with an asterisk sign (*).
import java.util.*;
9801 200 111 | info@neosphere.com.np
Methods in Java
• A method is a block of code which only runs when it is called.
• You can pass data, known as parameters, into a method.
9801 200 111 | info@neosphere.com.np
modifier returnType nameOfMethod (Parameter List) {
// method body
}
9801 200 111 | info@neosphere.com.np
Variables and Types
Although Java is object oriented, not all types are objects. It is built on top of basic variable types
called primitives.
List of all primitives in Java:
byte (number, 1 byte)
short (number, 2 bytes)
int (number, 4 bytes)
long (number, 8 bytes)
float (float number, 4 bytes)
double (float number, 8 bytes)
char (a character, 2 bytes)
boolean (true or false, 1 byte)
9801 200 111 | info@neosphere.com.np
Java is a strong typed language, which means variables need to
be defined before we use them.
int myNumber;
myNumber = 5;
9801 200 111 | info@neosphere.com.np
String is not a primitive. It's a real type, but Java has special treatment for String.
// Create a string with a constructor
String s1 = new String("Who let the dogs out?");
// Just using "" creates a string, so no need to write it the previous way.
String s2 = "Who who who who!";
// Java defined the operator + on strings to concatenate:
String s3 = s1 + s2;
int num = 5;
String s = "I have " + num + " cookies"; //Be sure not to use ""
with primitives.
Can also concat string to primitives:
9801 200 111 | info@neosphere.com.np
Operator
Operator in java is a symbol that is used to perform operations
9801 200 111 | info@neosphere.com.np
Operator Precedence
Operators Precedence
postfix expr++ expr--
unary ++expr --expr +expr -expr ~ !
multiplicative * / %
additive + -
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
9801 200 111 | info@neosphere.com.np
Simple Assignment Operator
=
9801 200 111 | info@neosphere.com.np
Arithmetic Operators
+ Additive operator (also used for String concatenation)
- Subtraction operator
* Multiplication operator
/ Division operator
% Remainder operator
9801 200 111 | info@neosphere.com.np
Unary Operators
+ Unary plus operator; indicates positive value (numbers are
positive without this, however)
- Unary minus operator; negates an expression
++ Increment operator; increments a value by 1
-- Decrement operator; decrements a value by 1
! Logical complement operator; inverts the value of a boolean
9801 200 111 | info@neosphere.com.np
Equality and Relational Operators
== Equal to
!= Not equal to
> Greater than
>= Greater than or equal to
< Less than
<= Less than or equal to
9801 200 111 | info@neosphere.com.np
&& Conditional-AND
|| Conditional-OR
?: Ternary (shorthand for if-then-else statement)
9801 200 111 | info@neosphere.com.np
Bitwise and Bit Shift Operators
~ Unary bitwise complement
<< Signed left shift
>> Signed right shift
>>> Unsigned right shift
& Bitwise AND
^ Bitwise exclusive OR
| Bitwise inclusive OR
9801 200 111 | info@neosphere.com.np
Conditionals
Java uses boolean variables to evaluate conditions. The boolean values true
and false are returned when an expression is compared or evaluated. For
example:
int a = 4;
boolean b = a == 4;
if (b) {
System.out.println("It's true!");
}
9801 200 111 | info@neosphere.com.np
The if-then Statement
The if-then statement is the most basic of all the control flow statements
void applyBrakes() {
// the "if" clause: bicycle must be moving
if (isMoving){
// the "then" clause: decrease current speed
currentSpeed--;
}
}
9801 200 111 | info@neosphere.com.np
If this test evaluates to false (meaning that the bicycle is not in motion),
control jumps to the end of the if-then statement.
void applyBrakes() {
// the "if" clause: bicycle must be moving
if (isMoving){
// the "then" clause: decrease current speed
currentSpeed--;
}
}
9801 200 111 | info@neosphere.com.np
The if-then-else Statement
void applyBrakes() {
if (isMoving) {
currentSpeed--;
} else {
System.err.println("The bicycle has already stopped!");
}
}
9801 200 111 | info@neosphere.com.np
class IfElseDemo {
public static void main(String[] args) {
int testscore = 76;
char grade;
if (testscore >= 90) {
grade = 'A';
} else if (testscore >= 80) {
grade = 'B';
} else if (testscore >= 70) {
grade = 'C';
} else if (testscore >= 60) {
grade = 'D';
} else {
grade = 'F';
}
System.out.println("Grade = " + grade);
}
}
9801 200 111 | info@neosphere.com.np
The switch Statement
A switch works with the byte, short, char, and int primitive
data types.
It also works with enumerated types (discussed in Enum
Types), the String class, and a few special classes that wrap
certain primitive types: Character, Byte, Short, and Integer
9801 200 111 | info@neosphere.com.np
public class SwitchDemo {
public static void main(String[] args) {
int month = 8;
String monthString;
switch (month) {
case 1: monthString = "January";
break;
case 2: monthString = "February";
break;
case 3: monthString = "March";
break;
case 4: monthString = "April";
break;
9801 200 111 | info@neosphere.com.np
case 5: monthString = "May";
break;
case 6: monthString = "June";
break;
case 7: monthString = "July";
break;
case 8: monthString = "August";
break;
case 9: monthString = "September";
break;
case 10: monthString = "October";
break;
case 11: monthString = "November";
break;
case 12: monthString = "December";
break;
default: monthString = "Invalid month";
break;
}
System.out.println(monthString);
}
9801 200 111 | info@neosphere.com.np
• The body of a switch statement is known as a switch block.
• A statement in the switch block can be labeled with one or
more case or default labels.
• The switch statement evaluates its expression, then executes
all statements that follow the matching case label.
9801 200 111 | info@neosphere.com.np
The while and do-while Statements
The while statement continually executes a block of statements while a
particular condition is true. Its syntax can be expressed as:
while (expression) {
statement(s)
}
9801 200 111 | info@neosphere.com.np
The while statement evaluates expression, which must return a
boolean value.
9801 200 111 | info@neosphere.com.np
class WhileDemo {
public static void main(String[] args){
int count = 1;
while (count < 11) {
System.out.println("Count is: " + count);
count++;
}
}
}
9801 200 111 | info@neosphere.com.np
Do…while
class DoWhileDemo {
public static void main(String[] args){
int count = 1;
do {
System.out.println("Count is: " + count);
count++;
} while (count < 11);
}
}
9801 200 111 | info@neosphere.com.np
The for Statement
The for statement provides a compact way to iterate over a range of
values. Programmers often refer to it as the "for loop" because of the
way in which it repeatedly loops until a particular condition is satisfied.
9801 200 111 | info@neosphere.com.np
for (initialization; termination; increment) {
statement(s)
}
9801 200 111 | info@neosphere.com.np
class ForDemo {
public static void main(String[] args){
for(int i=1; i<11; i++){
System.out.println("Count is: " + i);
}
}
}
9801 200 111 | info@neosphere.com.np
Enhanced for
class EnhancedForDemo {
public static void main(String[] args){
int[] numbers = {1,2,3,4,5,6,7,8,9,10};
for (int item : numbers) {
System.out.println("Count is: " + item);
}
}
}

More Related Content

What's hot

Python workshop session 6
Python workshop session 6Python workshop session 6
Python workshop session 6Abdul Haseeb
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]vikram mahendra
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2Amit Kapoor
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Dharma Kshetri
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONvikram mahendra
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Saket Pathak
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2vikram mahendra
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribdAmit Kapoor
 
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVINGGOWSIKRAJAP
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 FocJAYA
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointersMomenMostafa
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)Make Mannan
 
Advance python programming
Advance python programming Advance python programming
Advance python programming Jagdish Chavan
 

What's hot (20)

Python workshop session 6
Python workshop session 6Python workshop session 6
Python workshop session 6
 
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]FUNCTIONS IN PYTHON[RANDOM FUNCTION]
FUNCTIONS IN PYTHON[RANDOM FUNCTION]
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)Maharishi University of Management (MSc Computer Science test questions)
Maharishi University of Management (MSc Computer Science test questions)
 
INTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHONINTRODUCTION TO FUNCTIONS IN PYTHON
INTRODUCTION TO FUNCTIONS IN PYTHON
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 
Functions in C
Functions in CFunctions in C
Functions in C
 
C aptitude scribd
C aptitude scribdC aptitude scribd
C aptitude scribd
 
C program
C programC program
C program
 
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING18CSS101J PROGRAMMING FOR PROBLEM SOLVING
18CSS101J PROGRAMMING FOR PROBLEM SOLVING
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Arrays
ArraysArrays
Arrays
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
Unit 3
Unit 3 Unit 3
Unit 3
 
8 arrays and pointers
8  arrays and pointers8  arrays and pointers
8 arrays and pointers
 
C programs
C programsC programs
C programs
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
 
Functions
FunctionsFunctions
Functions
 
Advance python programming
Advance python programming Advance python programming
Advance python programming
 

Similar to Java Programming Workshop (20)

Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
 
Reading and writting v2
Reading and writting v2Reading and writting v2
Reading and writting v2
 
Nalinee java
Nalinee javaNalinee java
Nalinee java
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
 
MT_01_unittest_python.pdf
MT_01_unittest_python.pdfMT_01_unittest_python.pdf
MT_01_unittest_python.pdf
 
Java
JavaJava
Java
 
Java tut1
Java tut1Java tut1
Java tut1
 
Tutorial java
Tutorial javaTutorial java
Tutorial java
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Best Practices
Best PracticesBest Practices
Best Practices
 
Unit I Advanced Java Programming Course
Unit I   Advanced Java Programming CourseUnit I   Advanced Java Programming Course
Unit I Advanced Java Programming Course
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
Beyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software ArchitectureBeyond PITS, Functional Principles for Software Architecture
Beyond PITS, Functional Principles for Software Architecture
 
Data-Driven Unit Testing for Java
Data-Driven Unit Testing for JavaData-Driven Unit Testing for Java
Data-Driven Unit Testing for Java
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Java Annotations and Pre-processing
Java  Annotations and Pre-processingJava  Annotations and Pre-processing
Java Annotations and Pre-processing
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
 

More from neosphere

Digital Marketing in Business
Digital Marketing in BusinessDigital Marketing in Business
Digital Marketing in Businessneosphere
 
CCNP Presentation- neosphere
CCNP Presentation- neosphereCCNP Presentation- neosphere
CCNP Presentation- neosphereneosphere
 
Digital marketing
Digital marketingDigital marketing
Digital marketingneosphere
 
Career in Software Development
Career in Software Development  Career in Software Development
Career in Software Development neosphere
 
Building career in Information Technology
Building career in Information TechnologyBuilding career in Information Technology
Building career in Information Technologyneosphere
 
Career as network specialist
Career as network specialistCareer as network specialist
Career as network specialistneosphere
 
Career in Ethical Hacking
Career in Ethical Hacking Career in Ethical Hacking
Career in Ethical Hacking neosphere
 

More from neosphere (7)

Digital Marketing in Business
Digital Marketing in BusinessDigital Marketing in Business
Digital Marketing in Business
 
CCNP Presentation- neosphere
CCNP Presentation- neosphereCCNP Presentation- neosphere
CCNP Presentation- neosphere
 
Digital marketing
Digital marketingDigital marketing
Digital marketing
 
Career in Software Development
Career in Software Development  Career in Software Development
Career in Software Development
 
Building career in Information Technology
Building career in Information TechnologyBuilding career in Information Technology
Building career in Information Technology
 
Career as network specialist
Career as network specialistCareer as network specialist
Career as network specialist
 
Career in Ethical Hacking
Career in Ethical Hacking Career in Ethical Hacking
Career in Ethical Hacking
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 

Recently uploaded (20)

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 

Java Programming Workshop

  • 1. 9801 200 111 | info@neosphere.com.np
  • 2. 9801 200 111 | info@neosphere.com.np Application Fundamentals
  • 3. 9801 200 111 | info@neosphere.com.np Types of Software https://whatis.techtarget.com/definition/system-software System Software https://searchsoftwarequality.techtarget.com/definition/application Application Software Application Software Games, MS Office, Browser etc. System Software Operating System, Tools & Utilities, Compilers Hardware Disk, CPU, RAM
  • 4. 9801 200 111 | info@neosphere.com.np Types of Application Web Desktop Mobile ▪ Java ▪ .NET ▪ PHP ▪ Python ▪ Others ▪ Java ▪ .NET ▪ Python ▪ Others ▪ Android (java, Kotlin) ▪ iOS (Swift) L a n g u a g e s
  • 5. 9801 200 111 | info@neosphere.com.np We require database to store data
  • 6. 9801 200 111 | info@neosphere.com.np Driver We require JDBC (Java Database Connectivity) Driver to perform operation with Databases
  • 7. 9801 200 111 | info@neosphere.com.np It is intended to let application developers "write once, run anywhere" (WORA), meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.
  • 8. 9801 200 111 | info@neosphere.com.np Java is Object Oriented
  • 9. 9801 200 111 | info@neosphere.com.np public class HelloWorld { public static void main(String[] args) { System.out.println("Hello, World!"); } } Compile: javac filename.java Run: java ClassName
  • 10. 9801 200 111 | info@neosphere.com.np javac HelloWorld.java Compile: java HelloWorld Run:
  • 11. 9801 200 111 | info@neosphere.com.np This is the entry point of our Java program. the main method has to have this exact signature in order to be able to run our program. public again means that anyone can access it. static means that you can run this method without creating an instance of HelloWorld. void means that this method doesn't return any value. main is the name of the method.
  • 12. 9801 200 111 | info@neosphere.com.np • The HelloWorld.java file is known as source code file. • It is compiled by invoking tool named javac.exe, which compiles the source code into a .class file. • The .class file contains the bytecode which is interpreted by java.exe tool. • java.exe interprets the bytecode and runs the program.
  • 13. 9801 200 111 | info@neosphere.com.np Package in Java A package in Java is used to group related classes. Think of it as a folder in a file directory. We use packages to avoid name conflicts, and to write a better maintainable code. Packages are divided into two categories:
  • 14. 9801 200 111 | info@neosphere.com.np Java Packages • Built-in Packages (packages from the Java API) • User-defined Packages (create your own packages)
  • 15. 9801 200 111 | info@neosphere.com.np Importing packages import package.name.Class; // Import a single class import package.name.*; // Import the whole package
  • 16. 9801 200 111 | info@neosphere.com.np Scanner Class in Java import java.util.Scanner; class MyClass { public static void main(String[] args) { Scanner myObj = new Scanner(System.in); System.out.println("Enter username"); String userName = myObj.nextLine(); System.out.println("Username is: " + userName); } }
  • 17. 9801 200 111 | info@neosphere.com.np To import a whole package, end the statement with an asterisk sign (*). import java.util.*;
  • 18. 9801 200 111 | info@neosphere.com.np Methods in Java • A method is a block of code which only runs when it is called. • You can pass data, known as parameters, into a method.
  • 19. 9801 200 111 | info@neosphere.com.np modifier returnType nameOfMethod (Parameter List) { // method body }
  • 20. 9801 200 111 | info@neosphere.com.np Variables and Types Although Java is object oriented, not all types are objects. It is built on top of basic variable types called primitives. List of all primitives in Java: byte (number, 1 byte) short (number, 2 bytes) int (number, 4 bytes) long (number, 8 bytes) float (float number, 4 bytes) double (float number, 8 bytes) char (a character, 2 bytes) boolean (true or false, 1 byte)
  • 21. 9801 200 111 | info@neosphere.com.np Java is a strong typed language, which means variables need to be defined before we use them. int myNumber; myNumber = 5;
  • 22. 9801 200 111 | info@neosphere.com.np String is not a primitive. It's a real type, but Java has special treatment for String. // Create a string with a constructor String s1 = new String("Who let the dogs out?"); // Just using "" creates a string, so no need to write it the previous way. String s2 = "Who who who who!"; // Java defined the operator + on strings to concatenate: String s3 = s1 + s2; int num = 5; String s = "I have " + num + " cookies"; //Be sure not to use "" with primitives. Can also concat string to primitives:
  • 23. 9801 200 111 | info@neosphere.com.np Operator Operator in java is a symbol that is used to perform operations
  • 24. 9801 200 111 | info@neosphere.com.np Operator Precedence Operators Precedence postfix expr++ expr-- unary ++expr --expr +expr -expr ~ ! multiplicative * / % additive + - shift << >> >>> relational < > <= >= instanceof equality == != bitwise AND & bitwise exclusive OR ^ bitwise inclusive OR | logical AND && logical OR || ternary ? : assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=
  • 25. 9801 200 111 | info@neosphere.com.np Simple Assignment Operator =
  • 26. 9801 200 111 | info@neosphere.com.np Arithmetic Operators + Additive operator (also used for String concatenation) - Subtraction operator * Multiplication operator / Division operator % Remainder operator
  • 27. 9801 200 111 | info@neosphere.com.np Unary Operators + Unary plus operator; indicates positive value (numbers are positive without this, however) - Unary minus operator; negates an expression ++ Increment operator; increments a value by 1 -- Decrement operator; decrements a value by 1 ! Logical complement operator; inverts the value of a boolean
  • 28. 9801 200 111 | info@neosphere.com.np Equality and Relational Operators == Equal to != Not equal to > Greater than >= Greater than or equal to < Less than <= Less than or equal to
  • 29. 9801 200 111 | info@neosphere.com.np && Conditional-AND || Conditional-OR ?: Ternary (shorthand for if-then-else statement)
  • 30. 9801 200 111 | info@neosphere.com.np Bitwise and Bit Shift Operators ~ Unary bitwise complement << Signed left shift >> Signed right shift >>> Unsigned right shift & Bitwise AND ^ Bitwise exclusive OR | Bitwise inclusive OR
  • 31. 9801 200 111 | info@neosphere.com.np Conditionals Java uses boolean variables to evaluate conditions. The boolean values true and false are returned when an expression is compared or evaluated. For example: int a = 4; boolean b = a == 4; if (b) { System.out.println("It's true!"); }
  • 32. 9801 200 111 | info@neosphere.com.np The if-then Statement The if-then statement is the most basic of all the control flow statements void applyBrakes() { // the "if" clause: bicycle must be moving if (isMoving){ // the "then" clause: decrease current speed currentSpeed--; } }
  • 33. 9801 200 111 | info@neosphere.com.np If this test evaluates to false (meaning that the bicycle is not in motion), control jumps to the end of the if-then statement. void applyBrakes() { // the "if" clause: bicycle must be moving if (isMoving){ // the "then" clause: decrease current speed currentSpeed--; } }
  • 34. 9801 200 111 | info@neosphere.com.np The if-then-else Statement void applyBrakes() { if (isMoving) { currentSpeed--; } else { System.err.println("The bicycle has already stopped!"); } }
  • 35. 9801 200 111 | info@neosphere.com.np class IfElseDemo { public static void main(String[] args) { int testscore = 76; char grade; if (testscore >= 90) { grade = 'A'; } else if (testscore >= 80) { grade = 'B'; } else if (testscore >= 70) { grade = 'C'; } else if (testscore >= 60) { grade = 'D'; } else { grade = 'F'; } System.out.println("Grade = " + grade); } }
  • 36. 9801 200 111 | info@neosphere.com.np The switch Statement A switch works with the byte, short, char, and int primitive data types. It also works with enumerated types (discussed in Enum Types), the String class, and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer
  • 37. 9801 200 111 | info@neosphere.com.np public class SwitchDemo { public static void main(String[] args) { int month = 8; String monthString; switch (month) { case 1: monthString = "January"; break; case 2: monthString = "February"; break; case 3: monthString = "March"; break; case 4: monthString = "April"; break;
  • 38. 9801 200 111 | info@neosphere.com.np case 5: monthString = "May"; break; case 6: monthString = "June"; break; case 7: monthString = "July"; break; case 8: monthString = "August"; break; case 9: monthString = "September"; break; case 10: monthString = "October"; break; case 11: monthString = "November"; break; case 12: monthString = "December"; break; default: monthString = "Invalid month"; break; } System.out.println(monthString); }
  • 39. 9801 200 111 | info@neosphere.com.np • The body of a switch statement is known as a switch block. • A statement in the switch block can be labeled with one or more case or default labels. • The switch statement evaluates its expression, then executes all statements that follow the matching case label.
  • 40. 9801 200 111 | info@neosphere.com.np The while and do-while Statements The while statement continually executes a block of statements while a particular condition is true. Its syntax can be expressed as: while (expression) { statement(s) }
  • 41. 9801 200 111 | info@neosphere.com.np The while statement evaluates expression, which must return a boolean value.
  • 42. 9801 200 111 | info@neosphere.com.np class WhileDemo { public static void main(String[] args){ int count = 1; while (count < 11) { System.out.println("Count is: " + count); count++; } } }
  • 43. 9801 200 111 | info@neosphere.com.np Do…while class DoWhileDemo { public static void main(String[] args){ int count = 1; do { System.out.println("Count is: " + count); count++; } while (count < 11); } }
  • 44. 9801 200 111 | info@neosphere.com.np The for Statement The for statement provides a compact way to iterate over a range of values. Programmers often refer to it as the "for loop" because of the way in which it repeatedly loops until a particular condition is satisfied.
  • 45. 9801 200 111 | info@neosphere.com.np for (initialization; termination; increment) { statement(s) }
  • 46. 9801 200 111 | info@neosphere.com.np class ForDemo { public static void main(String[] args){ for(int i=1; i<11; i++){ System.out.println("Count is: " + i); } } }
  • 47. 9801 200 111 | info@neosphere.com.np Enhanced for class EnhancedForDemo { public static void main(String[] args){ int[] numbers = {1,2,3,4,5,6,7,8,9,10}; for (int item : numbers) { System.out.println("Count is: " + item); } } }