SlideShare a Scribd company logo
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

More Related Content

PPT
Java Basics
PDF
Java Programming
PPT
Java basic
PPTX
Basics of Java
PPT
Java basic tutorial by sanjeevini india
PDF
New Features Of JDK 7
PPTX
Core Java Tutorials by Mahika Tutorials
PPT
Java Tutorial
Java Basics
Java Programming
Java basic
Basics of Java
Java basic tutorial by sanjeevini india
New Features Of JDK 7
Core Java Tutorials by Mahika Tutorials
Java Tutorial

What's hot (20)

PPT
JAVA BASICS
PPT
PPTX
Core Java introduction | Basics | free course
PDF
Java programming basics
PPT
Core java
PPT
Presentation to java
PDF
Basic java for Android Developer
PPT
Invoke dynamics
PDF
Java Programming - 01 intro to java
PPTX
Introduction to Java programming - Java tutorial for beginners to teach Java ...
PPS
Packages and inbuilt classes of java
PPTX
Java history, versions, types of errors and exception, quiz
PPTX
Core java
PPT
Java tutorial for Beginners and Entry Level
PPT
Unit 2 Java
PDF
Java 8 features
PPT
Java tutorial PPT
PPT
Java Tut1
PPT
Java Tutorial
PPT
Java API, Exceptions and IO
JAVA BASICS
Core Java introduction | Basics | free course
Java programming basics
Core java
Presentation to java
Basic java for Android Developer
Invoke dynamics
Java Programming - 01 intro to java
Introduction to Java programming - Java tutorial for beginners to teach Java ...
Packages and inbuilt classes of java
Java history, versions, types of errors and exception, quiz
Core java
Java tutorial for Beginners and Entry Level
Unit 2 Java
Java 8 features
Java tutorial PPT
Java Tut1
Java Tutorial
Java API, Exceptions and IO
Ad

Viewers also liked (8)

PPS
Java session01
PPT
Chapter 1 introduction to java technology
PDF
Introduction to java technology
PDF
Chapter 1. java programming language overview
PPT
Intuit commissions manager
PDF
Jena – A Semantic Web Framework for Java
PPT
Object Oriented Programming with Java
PDF
Object-Oriented Analysis And Design With Applications Grady Booch
Java session01
Chapter 1 introduction to java technology
Introduction to java technology
Chapter 1. java programming language overview
Intuit commissions manager
Jena – A Semantic Web Framework for Java
Object Oriented Programming with Java
Object-Oriented Analysis And Design With Applications Grady Booch
Ad

Similar to 02 basic java programming and operators (20)

PPTX
Java introduction
PPTX
PDF
Java programming material for beginners by Nithin, VVCE, Mysuru
PPTX
Core java &collections
PPTX
Core java1
PPTX
Programming in Java
PDF
Introduction java programming
PPT
Java SpringMVC SpringBOOT (Divergent).ppt
PPT
Java platform
PPTX
1 java programming- introduction
PPTX
Java basics
PPTX
LECTURE 2 -Object oriented Java Basics.pptx
PDF
java notes.pdf
PPTX
Java Programming and J2ME: The Basics
PPTX
oop unit1.pptx
PPT
Introduction what is java
PPT
PPT
Java01
PPT
RIBBUN SOFTWARE
PPT
Java introduction
Java programming material for beginners by Nithin, VVCE, Mysuru
Core java &collections
Core java1
Programming in Java
Introduction java programming
Java SpringMVC SpringBOOT (Divergent).ppt
Java platform
1 java programming- introduction
Java basics
LECTURE 2 -Object oriented Java Basics.pptx
java notes.pdf
Java Programming and J2ME: The Basics
oop unit1.pptx
Introduction what is java
Java01
RIBBUN SOFTWARE

More from Danairat Thanabodithammachari (20)

PDF
Thailand State Enterprise - Business Architecture and SE-AM
PDF
PDF
Agile Organization and Enterprise Architecture v1129 Danairat
PDF
Blockchain for Management
PDF
Enterprise Architecture and Agile Organization Management v1076 Danairat
PDF
Agile Enterprise Architecture - Danairat
PDF
Digital Transformation, Enterprise Architecture, Big Data by Danairat
PDF
Big data Hadoop Analytic and Data warehouse comparison guide
PDF
Big data hadooop analytic and data warehouse comparison guide
PDF
Perl for System Automation - 01 Advanced File Processing
PDF
Perl Programming - 04 Programming Database
PDF
Perl Programming - 03 Programming File
PDF
Perl Programming - 02 Regular Expression
PDF
Perl Programming - 01 Basic Perl
PDF
Setting up Hadoop YARN Clustering
PDF
JEE Programming - 03 Model View Controller
PDF
JEE Programming - 05 JSP
PDF
JEE Programming - 04 Java Servlets
PDF
JEE Programming - 08 Enterprise Application Deployment
PDF
JEE Programming - 07 EJB Programming
Thailand State Enterprise - Business Architecture and SE-AM
Agile Organization and Enterprise Architecture v1129 Danairat
Blockchain for Management
Enterprise Architecture and Agile Organization Management v1076 Danairat
Agile Enterprise Architecture - Danairat
Digital Transformation, Enterprise Architecture, Big Data by Danairat
Big data Hadoop Analytic and Data warehouse comparison guide
Big data hadooop analytic and data warehouse comparison guide
Perl for System Automation - 01 Advanced File Processing
Perl Programming - 04 Programming Database
Perl Programming - 03 Programming File
Perl Programming - 02 Regular Expression
Perl Programming - 01 Basic Perl
Setting up Hadoop YARN Clustering
JEE Programming - 03 Model View Controller
JEE Programming - 05 JSP
JEE Programming - 04 Java Servlets
JEE Programming - 08 Enterprise Application Deployment
JEE Programming - 07 EJB Programming

Recently uploaded (20)

PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Transform Your Business with a Software ERP System
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PDF
Digital Strategies for Manufacturing Companies
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
System and Network Administration Chapter 2
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
Online Work Permit System for Fast Permit Processing
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPT
Introduction Database Management System for Course Database
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Softaken Excel to vCard Converter Software.pdf
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
AI in Product Development-omnex systems
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Transform Your Business with a Software ERP System
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Digital Strategies for Manufacturing Companies
Odoo POS Development Services by CandidRoot Solutions
ManageIQ - Sprint 268 Review - Slide Deck
2025 Textile ERP Trends: SAP, Odoo & Oracle
System and Network Administration Chapter 2
Understanding Forklifts - TECH EHS Solution
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Odoo Companies in India – Driving Business Transformation.pdf
Operating system designcfffgfgggggggvggggggggg
How to Migrate SBCGlobal Email to Yahoo Easily
Online Work Permit System for Fast Permit Processing
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Introduction Database Management System for Course Database
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Softaken Excel to vCard Converter Software.pdf
ISO 45001 Occupational Health and Safety Management System
AI in Product Development-omnex systems

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