JAVA Programming
Introduction
What is Programming?
Allows programmers to communicate with
computers with their MACHINE LANGUAGE.
What is JAVA?
The language is derived from C++ (which itself
emanated from C).
is a high-level programming. Ex: Python, C++, C#,
Java, VB.Net, Ruby, etc.
is a platform independent language. It’s run in
Windows, Mac OS, various versions of UNIX (Linux)
What is JAVA?
Java is guaranteed to be
“Write Once, Run Anywhere”
Introduction
class HelloWorld {
Schematic Flow of Java public static void main(String args[ ])
Software Development {
System.out.println(“Hello
Life Cycle World!”);
Java Program
}
}
Compiler
Interpreter Interpreter Interpreter
Hello
Hello Hello
World!
World! World!
Windows Solaris/Unix MacOS
JAVA Editors
Two (2) Editors to write and run the Java Programs:
Java Development Kit (JDK)
Integrated Development Environment (IDE)
JAVA Editors
Java Development Kit(JDK)
write in Notepad.
run in the command prompt environment and uses
command-line tools.
JAVA Editors
IDE’s are great for programmers to write an
error-free code more efficiently (to help you
to DEBUG easier).
It is a powerful development tools.
Java app for android (Mobile)
SOFTWARE FOR (IDE’s) JAVA COMPILERS
BlueJ * NetBeans
Codenvy * Xcode
DrJava * MyEclipse
Eclipse *jGRASP
Greenfoot * IntelliJ IDEA
Jcreator *(Oracle) JDeveloper
Introduction
Using Netbeans IDE
PRESS the following:
F6 (single program)
Shift F6 (Multi program are Open & Run)
A Simple JAVA Program
Class
Declaration
public class HelloWorld {
Method Header
public static void main(String args[]){
// print a message Single Line Comment
System.out.println("HELLO WORLD!"); Method Body
}
}
Semicolon
Open & Close Braces
Java Source File Structure
public class helloworld { }
Class
Name
Method inside the Class
Java
JavaSource
SourceFile
FileStructure
Structure
public static void main ( ) { }
Parameters
(String[] args[])
Statement or Instructions
Difference between print & print.ln
print & println are built-in method to
libraries of java.
println, means Print Line (next line).
print, means print at the same line of
statement.
Java Program
public class HelloWorld {
public static void main(String args[]){
System.out.print(“HELLO");
System.out.print(“WORLD!");
System.out.println(“HELLO");
System.out.println(“WORLD!");
}
} What is the difference
Java Program
Difference between OUT & ERR
System.out.println(“HELLO");
out (color is Black)
System.err.println(“WORLD!");
Err (Error, Color is RED)
Java Keywords
The following list shows the reserved words in Java. These
reserved words may not be used as constant or variable or
any other identifier names.
abstract assert boolean break
byte case catch char
class const continue default
do double else enum
extends final finally float
for goto if implements
Java Keywords
The following list shows the reserved words in Java. These
reserved words may not be used as constant or variable or
any other identifier names.
import instanceof int interface
long native new package
private protected public return
short static strictfp super
switch synchronized this throw
throws transient try void
volatile while
Java Identifier
• Are the names used for classes, variables and methods.
• There are several points to remember about identifiers. They
are as follows:
1. All identifiers should begin with a letter (A to Z or a to z),
currency character ($) or an underscore (_).
2. After the first character, identifiers can have any
combination of characters.
3. A keyword cannot be used as an identifier.
Java Identifier
• Are the names used for classes, variables and methods.
• There are several points to remember about identifiers. They are
as follows:
4. Most importantly identifiers are case sensitive.
5. Examples of Legal identifiers: age, $salary, _value,
__1_value.
6. Examples of Illegal identifiers: 123abc, -salary
Java Separators
• Separators help define the structure of a
program.
Following are the some characters which are
generally used as the separators in Java.
Java Separators
Separator Name Use
. Period It is used to separate the package name from sub-
package name & class name. It is also used to
separate variable or method from its object or
instance.
, Comma It is used to separate the consecutive parameters
in the method definition. It is also used to
separate the consecutive variables of same type
while declaration.
; Semicolon It is used to terminate the statement in Java.
Java Separators
Separator Name Use
() Parenthesis This holds the list of parameters in method
definition. Also used in control statements.
{} Braces This is used to define the block/scope of
code, class, methods.
[] Brackets It is used in array declaration.
Java Notation
Notation Character represented
\n Newline (0x0a)
\b Backspace (0x08)
\s Space (0x20)
\t Tab
\" Double quote
\' Single quote
\\ Backslash
Java Variable
Scope of Variable
public class Variable_Global_Local {
static int gvar1=1, gvar2=2; //GLOBAL DECLARATION
public static void main (String[] args){
int lvar1 = 11, lvar2 = 12; //LOCAL DECLARATION
System.out.println("Global Variables:");
System.out.println("gvar1 = " + gvar1);
System.out.println("gvar2 = " + gvar2);
System.out.println("\nLocal Variables:");
System.out.println("lvar1 = " + lvar1);
System.out.println("lvar2 = " + lvar2);
}
}
Questions?
Clarifications?
Thank you for listening!