Download as pdf or txt
Download as pdf or txt
You are on page 1of 37

Introduction to Java

Programming
Objectives:
• To Identify History & Features of Java Programming
• To Identify the Code Structure & Anatomy of Java Programming
• To Understand the Different Variables in Java Programming
Java
Programming
Java Programming
• Was originally developed by Sun Microsystems which was initiated by
James Gosling and released in 1995 as core component of Sun
Microsystems' Java platform (Java 1.0 [J2SE]).
• Java is guaranteed to be Write Once, Run Anywhere (WORA).
• Is a general-purpose, concurrent, class-based, object-oriented language
that is specifically designed to have as few implementation dependencies
as possible.
• It is currently one of the most popular programming languages in use, and
is widely used from application software to web applications
Java Application
Java Application
This are typically compiled to byte code (class file) that
can run on any Java Virtual Machine (JVM) regardless of
computer architecture.
Code Structure in
Java
What goes in a What goes in a What goes in method?
source file? class? • Methods must be declared inside a class
A source code file •The class represents a Within the curly braces this writes the
holds one class piece of your program. methods on the instruction that
definition. •The class also must go shall be performed by the program.
within a pair of curly
brace • Methods is basically a set of statements.
Anatomy of
Class
Anatomy of Class
When the JVM starts running. It looks for the class you give
it at the command line. Then it starts looking for a specially-
written methods.
Variables
Variables
• Variables are locations in memory in which values can be
stored.
• They have a name, a type, and a value.
Two (2) Groups of
Data Types
Groups of Data Types
• Primitive (Intrinsic)
• Non-Primitive (Derived)
Groups of Data Types
• Primitive (Intrinsic) - specifies the size and type of variable
values, and it has no additional methods.
• Non-Primitive (Derived) - Non-primitive data types can be
created or modified by programmers.
Primitive
• Int – Stores integers (whole numbers), without decimals, such as
100 or -100
• Float- stores floating point numbers, with decimals, such as 19.99
or -19.99
• Char- stores single characters, such as 'a' or 'B'. Char values are
surrounded by single quotes
• Boolean - stores values with two states: true or false
• Double - Stores fractional numbers. Sufficient for storing 15
decimal digits
Non- Primitive
• Strings - contains a collection of characters surrounded by double
quotes.
• Arrays
• Classes
Strings
• Strings in Java are Objects that are backed internally by a char
array.
• Whenever a change to a String is made, an entirely new String is
created.
Strings
INT
• short for "integer," is a fundamental variable type built into the
compiler and used to define numeric variables holding whole
numbers.
• The int is a numeric primitive data types in Java.
• is a data type that stores 32 bit signed two's compliment integer
INT
FLOAT
• Float is a data type in java.
• float takes 4 bytes(i.e. 32 bits) in memory.
• float is a single precision floating point decimal number (i.e. we can
represent 7 places of decimal accuracy or in simple terms we can
take 7 digits after decimal).
• Default value of float is 0.0f.
FLOAT
CHAR
• char is a primitive data type whereas String is a class in java.
• char represents a single character whereas String can have zero or more
characters. So String is an array of chars.
• We define char in java program using single quote (‘) whereas we can
define String in Java using double quotes (“). Since String is a special
class, we get this option to define string using double quotes, we can
also create a String using new keyword.
CHAR
Boolean
• is a primitive data type.
• It is used to store only two possible values, either true or false.
• It specifies 1-bit of information and its "size" can't be defined precisely.
Boolean
Scanner
• Scanner is a class in java.util package used for obtaining the input of the
primitive types like int, double, etc. and strings. It is the easiest way to
read input in a Java program, though not very efficient if you want an
input method for scenarios where time is a constraint like in competitive
programming.
Scanner
Thank you!
Exercise

You might also like