SlideShare una empresa de Scribd logo
1 de 43
Descargar para leer sin conexión
Module 02 – Basic Java Programming
Danairat T.
Line ID: Danairat
FB: Danairat Thanabodithammachari
+668-1559-1446
Fundamental Java Programming
The Course Outline
Module 01 – Introduction to Java
Module 02 – Basic Java Programming
Module 03 – Control Flow and Exception Handling
Module 04 – Object Oriented in Java
Module 05 – Java Package and Access Control
Module 06 – Java File IO
Module 07 – Java Networking
Module 08 – Java Threading
Module 02 – Basic Java Programming and Operators
• Basic Java Programming
• Deploying Java Application
• Building Java Archive File
• Executing Basic Java Application
• Monitoring Basic Java Application
• Java Operators
Java File (ASCII Source Code) and Class File (Binary)
In the Java programming language, all source code is first
written in plain text files ending with the .java extension.
Those source files are then compiled into .class file
(bytecode) by the javac compiler.
The java launcher tool then runs your application with an
instance of the Java Virtual Machine.
JVM (Java Virtual Machine)
Because the Java VM is available on many different operating
systems, the same .class files are capable of running on Microsoft
Windows OS, the Solaris Operating System, Linux, or Mac OS.
The Java Platform
The Java platform has two components:
• The Java Virtual Machine
• The Java Application Programming Interface (API)
The API is a large collection of ready-made software components that provide many
useful capabilities. It is grouped into libraries of related classes and interfaces; these
libraries are known as packages.
A Closer Look at the "Hello World!" Application
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
}
}
Class Definition The main Method
The System class from the core library to print the "Hello World!"
message to standard output. System class contains member called
“static PrintStream out” to use as a "standard" output stream.
LAB – Building your first Application with JDeveloper
1.) Click “New Application ” from Jdeveloper 2.) Enter your “Application Name”,
Select “Application Template”, Click ”Next”
LAB – Building your first Application with JDeveloper
3.) (Optional) Enter “Application Package
Prefix”
to organize the structure of Java class files.
4.) Click “Finish”
LAB – Building your first Application with JDeveloper
5.) Right Click “New ” from the Project 6.) Select “Java Class”, Click “OK”
LAB – Building your first Application with JDeveloper
7.) Enter “Name” of the class,
Check “Main Method”
8.) Click “OK”
LAB – Building your first Application with JDeveloper
9.) Write codes in the main method
System.out.println(“Hello World”);
10.) Click “Run” button.
LAB – Building your first Application with JDeveloper
11.) See the result from the console output 12.) (Optional) Review the folder structure
for java source code file
LAB – Building your first Application with JDeveloper
13.) (Optional) Review the file output and Application Directory Structure
Deploying Java Application to execute outside the
IDE with jar command line
Java provides a capability to export your class files into a
single cross platform archive file named Java™ Archive (JAR).
JAR file contains the class files and auxiliary resources
associated
1.) We first create a text file named Manifest.txt with the following contents:
Main-Class: MyPackage.MyClass
2.) We then create a JAR file named MyJar.jar by entering the following command:
jar cfm MyJar.jar Manifest.txt MyPackage/*.class
3.) When you run the JAR file with the following command, the main method of
MyClass executes: -
java -jar MyJar.jar
The jar command line options
Operation Command
To create a JAR file jar cf jar-file input-file(s)
To view the contents of a JAR file jar tf jar-file
To extract the contents of a JAR file jar xf jar-file
To run an application packaged as a
JAR file (requires the Main-class manifest
header)
java -jar app.jar
LAB - Creating Java Archive File (JAR) and Run application
outside the IDE
1.) Click “New ” from the project menu 2.) Select “JAR File”, click “OK”
LAB - Creating Java Archive File (JAR) and Run application
outside the IDE
3.) Enter your application name “my_first_app” 4.) Click “Browse” to select the started class
LAB - Creating Java Archive File (JAR) and Run application
outside the IDE
5.) Select the “Main Class Name:” which is “Class1” 6.) Click “OK”
LAB - Creating Java Archive File (JAR) and Run application
outside the IDE
7.) Select “Deploy” from the project menu 8.) Click “Next”
LAB - Creating Java Archive File (JAR) and Run application
outside the IDE
9) Click “Finish” 10.) Review the result jar file “my_first_app.jar”
LAB - Creating Java Archive File (JAR) and Run application
outside the IDE
11.) Using Command Line Client to execute the JAR file
D:JDevelopermyworkApplication2Project1deploy>java -jar my_first_app.jar
Monitoring Basic Java Application
Using JConsole
The JConsole graphical user interface is a monitoring tool
that complies to the Java Management Extensions (JMX)
specification. JConsole uses the extensive instrumentation
of the Java Virtual Machine (Java VM) to provide information
about the performance and resource consumption of
applications running on the Java platform.
Starting JConsole
The jconsole executable can be found in JDK_HOME/bin, where JDK_HOME is the
directory in which the Java Development Kit (JDK) is installed. If this directory is in
your system path, you can start JConsole by simply typing jconsole in a command
(shell) prompt.
LAB – Monitoring Java Application with JConsole
1.) Create Java Application 2.) Deploy Java Application
Adding the loop into the code for long running app simulation.
for (int i=1; i<1000000; i++) {
System.out.println("Hi");
}
LAB – Monitoring Java Application with JConsole
3.) Execute Java Application
>java -jar my_first_app.jar
4.) Start Jconsole and select your targeted
Java process
>jconsole
LAB – Monitoring Java Application with JConsole
5.) Review Monitoring Results
LAB – Monitoring Java Application with JConsole
6.) Exit the JConsole
Java Class
A class is a blueprint or prototype from which objects are
created. This section defines a class that models the state
and behavior of a real-world object. It intentionally focuses on
the basics, showing how even a simple class can cleanly
model state and behavior.
Java Object
Java Object is conceptually similar to real-world objects.
They consist of state and behavior.
An object stores its state in fields (variables) and exposes its
behavior through methods.
Methods operate on an object's internal state. Hiding internal
state is known as data encapsulation
Class
Object 1
Object 2
Blueprint
Instance
Java Variables
Class Variables (Static Fields)
The field member are declared as static modifier; this tells the
compiler that there is exactly one copy of this variable in
existence, regardless of how many times the class has been
instantiated.
Instance Variables (Non-Static Fields)
The field members are unique to each instance of a class the
instance.
Local Variables
The variable is declared in a method. Local variables are only
visible to the methods. they are not accessible from the rest of the
class.
Java Language Keywords
abstract continue for new switch
assert*** default goto* package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum**** instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp** volatile
const* float native super while
*not used
**added in 1.2
***added in 1.4
****added in 5.0
Naming Convention:-
Do not use the Java Keywords as you variable.
Normally, The variable should start with lowercase and
follow by uppercase for the next word, eg. custArray,
printManager
Java Primitive Data Types
Default Value and Wrapper Class
The IEEE 754 Standard
The wrapper classes help you to perform conversion; eg converting String to integer:-
Interger.valueOf(“15”).intValue(); or int j = Integer.parseInt("10"); Please see java.lang.* library
Type Contains Default Size Range
Wrapper
Class
boolean true or false false 1 bit NA Boolean
char Unicode character u0000 16 bits u0000 to uFFFF Character
byte Signed integer 0 8 bits -128 to 127 Byte
Short
short Signed integer 0 16 bits -32768 to 32767 Integer
int Signed integer 0 32 bits -2147483648 to 2147483647 Long
long Signed integer 0 64 bits
-9223372036854775808 to
9223372036854775807
Character
float IEEE 754 floating point 0.0 32 bits ±1.4E-45 to ±3.4028235E+38 Float
double IEEE 754 floating point 0.0 64 bits
±4.9E-324 to
±1.7976931348623157E+308
Double
String is not a part of Java primitive data types.
Escape Character
Escape Sequence Character Value
b Backspace
t Horizontal tab
n Newline
f Form feed
r Carriage return
" Double quote
' Single quote
 Backslash
uxxxx
The Unicode character with encoding xxxx, where
xxxx is four hexadecimal digits. Unicode escapes
can appear anywhere in a Java program, not only
in character and string literals.
Primitive Type Conversion
Convert
From:
Convert To:
boolean byte short char int long float double
boolean - N N N N N N N
byte N - Y C Y Y Y Y
short N C - C Y Y Y Y
char N C C - Y Y Y Y
int N C C C - Y Y* Y*
long N C C C C - Y* Y*
float N C C C C C - Y
double N C C C C C C -
The letter N in the table means that the conversion cannot be performed. The letter Y means that the conversion is a
widening conversion and is therefore performed automatically and implicitly by Java. The letter C means that the
conversion is a narrowing conversion and requires an explicit cast. Finally, the notation Y* means that the conversion is
an automatic widening conversion, but that some of the least significant digits of the value may be lost by the conversion.
Java Operators
Operators Precedence
postfix expr++ expr--
unary ++expr --expr +expr -expr ~ !
multiplicative * / %
additive + -
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ? :
assignment = += -= *= /=
LAB - ArithmeticDemo
class ArithmeticDemo {
public static void main (String[] args){
int result = 1 + 2; // result is now 3
System.out.println(result);
result = result - 1; // result is now 2
System.out.println(result);
result = result * 2; // result is now 4
System.out.println(result);
result = result / 2; // result is now 2
System.out.println(result);
result = result + 8; // result is now 10
result = result % 7; // result is now 3
System.out.println(result);
}
}
LAB - ConcatDemo
class ConcatDemo {
public static void main(String[] args){
String firstString = "This is";
String secondString = " a concatenated string.";
String thirdString = firstString+secondString;
System.out.println(thirdString);
}
}
LAB - UnaryDemo
class UnaryDemo {
public static void main(String[] args){
int result = +1; // result is now 1
System.out.println(result);
result--; // result is now 0
System.out.println(result);
result++; // result is now 1
System.out.println(result);
result = -result; // result is now -1
System.out.println(result);
boolean success = false;
System.out.println(success); // false
System.out.println(!success); // true
}
}
LAB - PrePostDemo
class PrePostDemo {
public static void main(String[] args){
int i = 3;
i++;
System.out.println(i); // "4"
++i;
System.out.println(i); // "5"
System.out.println(++i); // "6"
System.out.println(i++); // "6"
System.out.println(i); // "7"
}
}
LAB - ComparisonDemo
class ComparisonDemo {
public static void main(String[] args){
int value1 = 1;
int value2 = 2;
if(value1 == value2) System.out.println("value1 == value2");
if(value1 != value2) System.out.println("value1 != value2");
if(value1 > value2) System.out.println("value1 > value2");
if(value1 < value2) System.out.println("value1 < value2");
if(value1 <= value2) System.out.println("value1 <= value2");
}
}
LAB - ConditionalDemo1
class ConditionalDemo1 {
public static void main(String[] args){
int value1 = 1;
int value2 = 2;
if((value1 == 1) && (value2 == 2)) System.out.println("value1 is 1 AND
value2 is 2");
if((value1 == 1) || (value2 == 1)) System.out.println("value1 is 1 OR
value2 is 1");
}
}
LAB – ConditionalDemo2
class ConditionalDemo2 {
public static void main(String[] args){
int value1 = 1;
int value2 = 2;
int result;
boolean someCondition = true;
result = someCondition ? value1 : value2;
System.out.println(result);
}
}
Danairat T.
Line ID: Danairat
FB: Danairat Thanabodithammachari
+668-1559-1446
Thank you

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

JAVA BASICS
JAVA BASICSJAVA BASICS
JAVA BASICS
 
Java Basics
Java BasicsJava Basics
Java Basics
 
Core Java introduction | Basics | free course
Core Java introduction | Basics | free course Core Java introduction | Basics | free course
Core Java introduction | Basics | free course
 
Java programming basics
Java programming basicsJava programming basics
Java programming basics
 
Core java
Core javaCore java
Core java
 
Presentation to java
Presentation  to  javaPresentation  to  java
Presentation to java
 
Basic java for Android Developer
Basic java for Android DeveloperBasic java for Android Developer
Basic java for Android Developer
 
Invoke dynamics
Invoke dynamicsInvoke dynamics
Invoke dynamics
 
Java Programming - 01 intro to java
Java Programming - 01 intro to javaJava Programming - 01 intro to java
Java Programming - 01 intro to java
 
Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...Introduction to Java programming - Java tutorial for beginners to teach Java ...
Introduction to Java programming - Java tutorial for beginners to teach Java ...
 
Packages and inbuilt classes of java
Packages and inbuilt classes of javaPackages and inbuilt classes of java
Packages and inbuilt classes of java
 
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
 
Core java
Core java Core java
Core java
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Unit 2 Java
Unit 2 JavaUnit 2 Java
Unit 2 Java
 
Java 8 features
Java 8 featuresJava 8 features
Java 8 features
 
Java tutorial PPT
Java tutorial PPTJava tutorial PPT
Java tutorial PPT
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java API, Exceptions and IO
Java API, Exceptions and IOJava API, Exceptions and IO
Java API, Exceptions and IO
 

Destacado

Java session01
Java session01Java session01
Java session01Niit Care
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technologysshhzap
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overviewJong Soon Bok
 
Intuit commissions manager
Intuit commissions managerIntuit commissions manager
Intuit commissions managersshhzap
 
Jena – A Semantic Web Framework for Java
Jena – A Semantic Web Framework for JavaJena – A Semantic Web Framework for Java
Jena – A Semantic Web Framework for JavaAleksander Pohl
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
Object-Oriented Analysis And Design With Applications Grady Booch
Object-Oriented Analysis And Design With Applications Grady BoochObject-Oriented Analysis And Design With Applications Grady Booch
Object-Oriented Analysis And Design With Applications Grady BoochSorina Chirilă
 

Destacado (8)

Java session01
Java session01Java session01
Java session01
 
Chapter 1 introduction to java technology
Chapter 1 introduction to java technologyChapter 1 introduction to java technology
Chapter 1 introduction to java technology
 
Introduction to java technology
Introduction to java technologyIntroduction to java technology
Introduction to java technology
 
Chapter 1. java programming language overview
Chapter 1. java programming language overviewChapter 1. java programming language overview
Chapter 1. java programming language overview
 
Intuit commissions manager
Intuit commissions managerIntuit commissions manager
Intuit commissions manager
 
Jena – A Semantic Web Framework for Java
Jena – A Semantic Web Framework for JavaJena – A Semantic Web Framework for Java
Jena – A Semantic Web Framework for Java
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Object-Oriented Analysis And Design With Applications Grady Booch
Object-Oriented Analysis And Design With Applications Grady BoochObject-Oriented Analysis And Design With Applications Grady Booch
Object-Oriented Analysis And Design With Applications Grady Booch
 

Similar a 02 basic java programming and operators

Unit of competency
Unit of competencyUnit of competency
Unit of competencyloidasacueza
 
Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction AKR Education
 
java basic for begginers
java basic for begginersjava basic for begginers
java basic for begginersdivaskrgupta007
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for MainframersRich Helton
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1sotlsoc
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT studentsPartnered Health
 
Introduction
IntroductionIntroduction
Introductionrichsoden
 
How to run java program without IDE
How to run java program without IDEHow to run java program without IDE
How to run java program without IDEShweta Oza
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)Prof. Erwin Globio
 
Introduction to java programming tutorial
Introduction to java programming   tutorialIntroduction to java programming   tutorial
Introduction to java programming tutorialjackschitze
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to JavaSMIJava
 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMmanish kumar
 
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)Shaharyar khan
 
Java OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slidesunny khan
 

Similar a 02 basic java programming and operators (20)

Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction
 
Java introduction
Java introductionJava introduction
Java introduction
 
Java lab-manual
Java lab-manualJava lab-manual
Java lab-manual
 
java basic for begginers
java basic for begginersjava basic for begginers
java basic for begginers
 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
 
Java for Mainframers
Java for MainframersJava for Mainframers
Java for Mainframers
 
Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
 
Introduction
IntroductionIntroduction
Introduction
 
How to run java program without IDE
How to run java program without IDEHow to run java program without IDE
How to run java program without IDE
 
JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)JAVA Object Oriented Programming (OOP)
JAVA Object Oriented Programming (OOP)
 
Introduction to java programming tutorial
Introduction to java programming   tutorialIntroduction to java programming   tutorial
Introduction to java programming tutorial
 
SMI - Introduction to Java
SMI - Introduction to JavaSMI - Introduction to Java
SMI - Introduction to Java
 
Java
JavaJava
Java
 
Java
JavaJava
Java
 
Lecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVMLecture - 2 Environment setup & JDK, JRE, JVM
Lecture - 2 Environment setup & JDK, JRE, JVM
 
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 OOP Concepts 1st Slide
Java OOP Concepts 1st SlideJava OOP Concepts 1st Slide
Java OOP Concepts 1st Slide
 

Más de Danairat Thanabodithammachari

Thailand State Enterprise - Business Architecture and SE-AM
Thailand State Enterprise - Business Architecture and SE-AMThailand State Enterprise - Business Architecture and SE-AM
Thailand State Enterprise - Business Architecture and SE-AMDanairat Thanabodithammachari
 
Agile Organization and Enterprise Architecture v1129 Danairat
Agile Organization and Enterprise Architecture v1129 DanairatAgile Organization and Enterprise Architecture v1129 Danairat
Agile Organization and Enterprise Architecture v1129 DanairatDanairat Thanabodithammachari
 
Enterprise Architecture and Agile Organization Management v1076 Danairat
Enterprise Architecture and Agile Organization Management v1076 DanairatEnterprise Architecture and Agile Organization Management v1076 Danairat
Enterprise Architecture and Agile Organization Management v1076 DanairatDanairat Thanabodithammachari
 
Digital Transformation, Enterprise Architecture, Big Data by Danairat
Digital Transformation, Enterprise Architecture, Big Data by DanairatDigital Transformation, Enterprise Architecture, Big Data by Danairat
Digital Transformation, Enterprise Architecture, Big Data by DanairatDanairat Thanabodithammachari
 
Big data Hadoop Analytic and Data warehouse comparison guide
Big data Hadoop Analytic and Data warehouse comparison guideBig data Hadoop Analytic and Data warehouse comparison guide
Big data Hadoop Analytic and Data warehouse comparison guideDanairat Thanabodithammachari
 
Big data hadooop analytic and data warehouse comparison guide
Big data hadooop analytic and data warehouse comparison guideBig data hadooop analytic and data warehouse comparison guide
Big data hadooop analytic and data warehouse comparison guideDanairat Thanabodithammachari
 
Perl for System Automation - 01 Advanced File Processing
Perl for System Automation - 01 Advanced File ProcessingPerl for System Automation - 01 Advanced File Processing
Perl for System Automation - 01 Advanced File ProcessingDanairat Thanabodithammachari
 
JEE Programming - 08 Enterprise Application Deployment
JEE Programming - 08 Enterprise Application DeploymentJEE Programming - 08 Enterprise Application Deployment
JEE Programming - 08 Enterprise Application DeploymentDanairat Thanabodithammachari
 

Más de Danairat Thanabodithammachari (20)

Thailand State Enterprise - Business Architecture and SE-AM
Thailand State Enterprise - Business Architecture and SE-AMThailand State Enterprise - Business Architecture and SE-AM
Thailand State Enterprise - Business Architecture and SE-AM
 
Agile Management
Agile ManagementAgile Management
Agile Management
 
Agile Organization and Enterprise Architecture v1129 Danairat
Agile Organization and Enterprise Architecture v1129 DanairatAgile Organization and Enterprise Architecture v1129 Danairat
Agile Organization and Enterprise Architecture v1129 Danairat
 
Blockchain for Management
Blockchain for ManagementBlockchain for Management
Blockchain for Management
 
Enterprise Architecture and Agile Organization Management v1076 Danairat
Enterprise Architecture and Agile Organization Management v1076 DanairatEnterprise Architecture and Agile Organization Management v1076 Danairat
Enterprise Architecture and Agile Organization Management v1076 Danairat
 
Agile Enterprise Architecture - Danairat
Agile Enterprise Architecture - DanairatAgile Enterprise Architecture - Danairat
Agile Enterprise Architecture - Danairat
 
Digital Transformation, Enterprise Architecture, Big Data by Danairat
Digital Transformation, Enterprise Architecture, Big Data by DanairatDigital Transformation, Enterprise Architecture, Big Data by Danairat
Digital Transformation, Enterprise Architecture, Big Data by Danairat
 
Big data Hadoop Analytic and Data warehouse comparison guide
Big data Hadoop Analytic and Data warehouse comparison guideBig data Hadoop Analytic and Data warehouse comparison guide
Big data Hadoop Analytic and Data warehouse comparison guide
 
Big data hadooop analytic and data warehouse comparison guide
Big data hadooop analytic and data warehouse comparison guideBig data hadooop analytic and data warehouse comparison guide
Big data hadooop analytic and data warehouse comparison guide
 
Perl for System Automation - 01 Advanced File Processing
Perl for System Automation - 01 Advanced File ProcessingPerl for System Automation - 01 Advanced File Processing
Perl for System Automation - 01 Advanced File Processing
 
Perl Programming - 04 Programming Database
Perl Programming - 04 Programming DatabasePerl Programming - 04 Programming Database
Perl Programming - 04 Programming Database
 
Perl Programming - 03 Programming File
Perl Programming - 03 Programming FilePerl Programming - 03 Programming File
Perl Programming - 03 Programming File
 
Perl Programming - 02 Regular Expression
Perl Programming - 02 Regular ExpressionPerl Programming - 02 Regular Expression
Perl Programming - 02 Regular Expression
 
Perl Programming - 01 Basic Perl
Perl Programming - 01 Basic PerlPerl Programming - 01 Basic Perl
Perl Programming - 01 Basic Perl
 
Setting up Hadoop YARN Clustering
Setting up Hadoop YARN ClusteringSetting up Hadoop YARN Clustering
Setting up Hadoop YARN Clustering
 
JEE Programming - 03 Model View Controller
JEE Programming - 03 Model View ControllerJEE Programming - 03 Model View Controller
JEE Programming - 03 Model View Controller
 
JEE Programming - 05 JSP
JEE Programming - 05 JSPJEE Programming - 05 JSP
JEE Programming - 05 JSP
 
JEE Programming - 04 Java Servlets
JEE Programming - 04 Java ServletsJEE Programming - 04 Java Servlets
JEE Programming - 04 Java Servlets
 
JEE Programming - 08 Enterprise Application Deployment
JEE Programming - 08 Enterprise Application DeploymentJEE Programming - 08 Enterprise Application Deployment
JEE Programming - 08 Enterprise Application Deployment
 
JEE Programming - 07 EJB Programming
JEE Programming - 07 EJB ProgrammingJEE Programming - 07 EJB Programming
JEE Programming - 07 EJB Programming
 

Último

Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024Mind IT Systems
 
Webinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptWebinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptkinjal48
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilVICTOR MAESTRE RAMIREZ
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxAutus Cyber Tech
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdfMeon Technology
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorShane Coughlan
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?AmeliaSmith90
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...OnePlan Solutions
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native BuildpacksVish Abrams
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageDista
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeNeo4j
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.Sharon Liu
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Jaydeep Chhasatia
 

Último (20)

Top Software Development Trends in 2024
Top Software Development Trends in  2024Top Software Development Trends in  2024
Top Software Development Trends in 2024
 
Webinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptWebinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.ppt
 
Generative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-CouncilGenerative AI for Cybersecurity - EC-Council
Generative AI for Cybersecurity - EC-Council
 
ERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptxERP For Electrical and Electronics manufecturing.pptx
ERP For Electrical and Electronics manufecturing.pptx
 
online pdf editor software solutions.pdf
online pdf editor software solutions.pdfonline pdf editor software solutions.pdf
online pdf editor software solutions.pdf
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS Calculator
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?
 
Salesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptxSalesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptx
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
 
Kawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in TrivandrumKawika Technologies pvt ltd Software Development Company in Trivandrum
Kawika Technologies pvt ltd Software Development Company in Trivandrum
 
Streamlining Your Application Builds with Cloud Native Buildpacks
Streamlining Your Application Builds  with Cloud Native BuildpacksStreamlining Your Application Builds  with Cloud Native Buildpacks
Streamlining Your Application Builds with Cloud Native Buildpacks
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
 
IA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG timeIA Generativa y Grafos de Neo4j: RAG time
IA Generativa y Grafos de Neo4j: RAG time
 
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
20240319 Car Simulator Plan.pptx . Plan for a JavaScript Car Driving Simulator.
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
 

02 basic java programming and operators

  • 1. Module 02 – Basic Java Programming Danairat T. Line ID: Danairat FB: Danairat Thanabodithammachari +668-1559-1446
  • 2. Fundamental Java Programming The Course Outline Module 01 – Introduction to Java Module 02 – Basic Java Programming Module 03 – Control Flow and Exception Handling Module 04 – Object Oriented in Java Module 05 – Java Package and Access Control Module 06 – Java File IO Module 07 – Java Networking Module 08 – Java Threading
  • 3. Module 02 – Basic Java Programming and Operators • Basic Java Programming • Deploying Java Application • Building Java Archive File • Executing Basic Java Application • Monitoring Basic Java Application • Java Operators
  • 4. Java File (ASCII Source Code) and Class File (Binary) In the Java programming language, all source code is first written in plain text files ending with the .java extension. Those source files are then compiled into .class file (bytecode) by the javac compiler. The java launcher tool then runs your application with an instance of the Java Virtual Machine.
  • 5. JVM (Java Virtual Machine) Because the Java VM is available on many different operating systems, the same .class files are capable of running on Microsoft Windows OS, the Solaris Operating System, Linux, or Mac OS.
  • 6. The Java Platform The Java platform has two components: • The Java Virtual Machine • The Java Application Programming Interface (API) The API is a large collection of ready-made software components that provide many useful capabilities. It is grouped into libraries of related classes and interfaces; these libraries are known as packages.
  • 7. A Closer Look at the "Hello World!" Application public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World"); } } Class Definition The main Method The System class from the core library to print the "Hello World!" message to standard output. System class contains member called “static PrintStream out” to use as a "standard" output stream.
  • 8. LAB – Building your first Application with JDeveloper 1.) Click “New Application ” from Jdeveloper 2.) Enter your “Application Name”, Select “Application Template”, Click ”Next”
  • 9. LAB – Building your first Application with JDeveloper 3.) (Optional) Enter “Application Package Prefix” to organize the structure of Java class files. 4.) Click “Finish”
  • 10. LAB – Building your first Application with JDeveloper 5.) Right Click “New ” from the Project 6.) Select “Java Class”, Click “OK”
  • 11. LAB – Building your first Application with JDeveloper 7.) Enter “Name” of the class, Check “Main Method” 8.) Click “OK”
  • 12. LAB – Building your first Application with JDeveloper 9.) Write codes in the main method System.out.println(“Hello World”); 10.) Click “Run” button.
  • 13. LAB – Building your first Application with JDeveloper 11.) See the result from the console output 12.) (Optional) Review the folder structure for java source code file
  • 14. LAB – Building your first Application with JDeveloper 13.) (Optional) Review the file output and Application Directory Structure
  • 15. Deploying Java Application to execute outside the IDE with jar command line Java provides a capability to export your class files into a single cross platform archive file named Java™ Archive (JAR). JAR file contains the class files and auxiliary resources associated 1.) We first create a text file named Manifest.txt with the following contents: Main-Class: MyPackage.MyClass 2.) We then create a JAR file named MyJar.jar by entering the following command: jar cfm MyJar.jar Manifest.txt MyPackage/*.class 3.) When you run the JAR file with the following command, the main method of MyClass executes: - java -jar MyJar.jar
  • 16. The jar command line options Operation Command To create a JAR file jar cf jar-file input-file(s) To view the contents of a JAR file jar tf jar-file To extract the contents of a JAR file jar xf jar-file To run an application packaged as a JAR file (requires the Main-class manifest header) java -jar app.jar
  • 17. LAB - Creating Java Archive File (JAR) and Run application outside the IDE 1.) Click “New ” from the project menu 2.) Select “JAR File”, click “OK”
  • 18. LAB - Creating Java Archive File (JAR) and Run application outside the IDE 3.) Enter your application name “my_first_app” 4.) Click “Browse” to select the started class
  • 19. LAB - Creating Java Archive File (JAR) and Run application outside the IDE 5.) Select the “Main Class Name:” which is “Class1” 6.) Click “OK”
  • 20. LAB - Creating Java Archive File (JAR) and Run application outside the IDE 7.) Select “Deploy” from the project menu 8.) Click “Next”
  • 21. LAB - Creating Java Archive File (JAR) and Run application outside the IDE 9) Click “Finish” 10.) Review the result jar file “my_first_app.jar”
  • 22. LAB - Creating Java Archive File (JAR) and Run application outside the IDE 11.) Using Command Line Client to execute the JAR file D:JDevelopermyworkApplication2Project1deploy>java -jar my_first_app.jar
  • 23. Monitoring Basic Java Application Using JConsole The JConsole graphical user interface is a monitoring tool that complies to the Java Management Extensions (JMX) specification. JConsole uses the extensive instrumentation of the Java Virtual Machine (Java VM) to provide information about the performance and resource consumption of applications running on the Java platform. Starting JConsole The jconsole executable can be found in JDK_HOME/bin, where JDK_HOME is the directory in which the Java Development Kit (JDK) is installed. If this directory is in your system path, you can start JConsole by simply typing jconsole in a command (shell) prompt.
  • 24. LAB – Monitoring Java Application with JConsole 1.) Create Java Application 2.) Deploy Java Application Adding the loop into the code for long running app simulation. for (int i=1; i<1000000; i++) { System.out.println("Hi"); }
  • 25. LAB – Monitoring Java Application with JConsole 3.) Execute Java Application >java -jar my_first_app.jar 4.) Start Jconsole and select your targeted Java process >jconsole
  • 26. LAB – Monitoring Java Application with JConsole 5.) Review Monitoring Results
  • 27. LAB – Monitoring Java Application with JConsole 6.) Exit the JConsole
  • 28. Java Class A class is a blueprint or prototype from which objects are created. This section defines a class that models the state and behavior of a real-world object. It intentionally focuses on the basics, showing how even a simple class can cleanly model state and behavior.
  • 29. Java Object Java Object is conceptually similar to real-world objects. They consist of state and behavior. An object stores its state in fields (variables) and exposes its behavior through methods. Methods operate on an object's internal state. Hiding internal state is known as data encapsulation Class Object 1 Object 2 Blueprint Instance
  • 30. Java Variables Class Variables (Static Fields) The field member are declared as static modifier; this tells the compiler that there is exactly one copy of this variable in existence, regardless of how many times the class has been instantiated. Instance Variables (Non-Static Fields) The field members are unique to each instance of a class the instance. Local Variables The variable is declared in a method. Local variables are only visible to the methods. they are not accessible from the rest of the class.
  • 31. Java Language Keywords abstract continue for new switch assert*** default goto* package synchronized boolean do if private this break double implements protected throw byte else import public throws case enum**** instanceof return transient catch extends int short try char final interface static void class finally long strictfp** volatile const* float native super while *not used **added in 1.2 ***added in 1.4 ****added in 5.0 Naming Convention:- Do not use the Java Keywords as you variable. Normally, The variable should start with lowercase and follow by uppercase for the next word, eg. custArray, printManager
  • 32. Java Primitive Data Types Default Value and Wrapper Class The IEEE 754 Standard The wrapper classes help you to perform conversion; eg converting String to integer:- Interger.valueOf(“15”).intValue(); or int j = Integer.parseInt("10"); Please see java.lang.* library Type Contains Default Size Range Wrapper Class boolean true or false false 1 bit NA Boolean char Unicode character u0000 16 bits u0000 to uFFFF Character byte Signed integer 0 8 bits -128 to 127 Byte Short short Signed integer 0 16 bits -32768 to 32767 Integer int Signed integer 0 32 bits -2147483648 to 2147483647 Long long Signed integer 0 64 bits -9223372036854775808 to 9223372036854775807 Character float IEEE 754 floating point 0.0 32 bits ±1.4E-45 to ±3.4028235E+38 Float double IEEE 754 floating point 0.0 64 bits ±4.9E-324 to ±1.7976931348623157E+308 Double String is not a part of Java primitive data types.
  • 33. Escape Character Escape Sequence Character Value b Backspace t Horizontal tab n Newline f Form feed r Carriage return " Double quote ' Single quote Backslash uxxxx The Unicode character with encoding xxxx, where xxxx is four hexadecimal digits. Unicode escapes can appear anywhere in a Java program, not only in character and string literals.
  • 34. Primitive Type Conversion Convert From: Convert To: boolean byte short char int long float double boolean - N N N N N N N byte N - Y C Y Y Y Y short N C - C Y Y Y Y char N C C - Y Y Y Y int N C C C - Y Y* Y* long N C C C C - Y* Y* float N C C C C C - Y double N C C C C C C - The letter N in the table means that the conversion cannot be performed. The letter Y means that the conversion is a widening conversion and is therefore performed automatically and implicitly by Java. The letter C means that the conversion is a narrowing conversion and requires an explicit cast. Finally, the notation Y* means that the conversion is an automatic widening conversion, but that some of the least significant digits of the value may be lost by the conversion.
  • 35. Java Operators Operators Precedence postfix expr++ expr-- unary ++expr --expr +expr -expr ~ ! multiplicative * / % additive + - shift << >> >>> relational < > <= >= instanceof equality == != bitwise AND & bitwise inclusive OR | logical AND && logical OR || ternary ? : assignment = += -= *= /=
  • 36. LAB - ArithmeticDemo class ArithmeticDemo { public static void main (String[] args){ int result = 1 + 2; // result is now 3 System.out.println(result); result = result - 1; // result is now 2 System.out.println(result); result = result * 2; // result is now 4 System.out.println(result); result = result / 2; // result is now 2 System.out.println(result); result = result + 8; // result is now 10 result = result % 7; // result is now 3 System.out.println(result); } }
  • 37. LAB - ConcatDemo class ConcatDemo { public static void main(String[] args){ String firstString = "This is"; String secondString = " a concatenated string."; String thirdString = firstString+secondString; System.out.println(thirdString); } }
  • 38. LAB - UnaryDemo class UnaryDemo { public static void main(String[] args){ int result = +1; // result is now 1 System.out.println(result); result--; // result is now 0 System.out.println(result); result++; // result is now 1 System.out.println(result); result = -result; // result is now -1 System.out.println(result); boolean success = false; System.out.println(success); // false System.out.println(!success); // true } }
  • 39. LAB - PrePostDemo class PrePostDemo { public static void main(String[] args){ int i = 3; i++; System.out.println(i); // "4" ++i; System.out.println(i); // "5" System.out.println(++i); // "6" System.out.println(i++); // "6" System.out.println(i); // "7" } }
  • 40. LAB - ComparisonDemo class ComparisonDemo { public static void main(String[] args){ int value1 = 1; int value2 = 2; if(value1 == value2) System.out.println("value1 == value2"); if(value1 != value2) System.out.println("value1 != value2"); if(value1 > value2) System.out.println("value1 > value2"); if(value1 < value2) System.out.println("value1 < value2"); if(value1 <= value2) System.out.println("value1 <= value2"); } }
  • 41. LAB - ConditionalDemo1 class ConditionalDemo1 { public static void main(String[] args){ int value1 = 1; int value2 = 2; if((value1 == 1) && (value2 == 2)) System.out.println("value1 is 1 AND value2 is 2"); if((value1 == 1) || (value2 == 1)) System.out.println("value1 is 1 OR value2 is 1"); } }
  • 42. LAB – ConditionalDemo2 class ConditionalDemo2 { public static void main(String[] args){ int value1 = 1; int value2 = 2; int result; boolean someCondition = true; result = someCondition ? value1 : value2; System.out.println(result); } }
  • 43. Danairat T. Line ID: Danairat FB: Danairat Thanabodithammachari +668-1559-1446 Thank you