2. Introduction to Java, History of Java,
Why we need JAVA?
compiling and executing a java program, basic
control structures,
Data types,
Methods,
Classes, String, array, container classes
Data Structure Algorithms
Exception handling, file handling, Object oriented
programming concepts,
And Multithreading.
3. Introduction to Java
Java is an object oriented Internet Programming
Language which is popular over a globe with his
two major features:
1. Platform Independency
2. Security
4.
5. Languages
There are majorly two types of languages.
one is Statically typed language
Dynamically typed languages
Java is statically typed and also a strongly typed
language because, in Java, each type of data
(such as integer, character, hexadecimal, packed
decimal, and so forth) is predefined as part of the
programming language and all constants or
variables defined for a given program must be
described with one of the data types.
8. Non-Primitive Data Type or
Reference Data Types
The Reference Data Types will contain a
memory address of variable value because the
reference types won’t store the variable value
directly in memory. They
are strings, objects, arrays, etc.
String
Class
Object
Interface
Array
9. Java Identifier
identifiers are used for identification purposes. In
Java, an identifier can be a class name, method
name, variable name, or label.
For example:
public class Test
{
public static void main(String[] args)
{ int a = 40; } }
10. Java Identifier
So, in this example we have 5 identifiers namely :
Test : class name.
main : method name.
String : predefined class name.
args : variable name.
a : variable name.
11. Java Naming Conventions
Below are some naming conventions of java programming
language. They must be followed while developing software in
java for good maintenance and readability of code. Java uses
CamelCase as a practice for writing names of methods,
variables, classes, packages and constants.
Camel case in Java Programming : It consists of compound
words or phrases such that each word or abbreviation begins
with a capital letter or first word with a lowercase letter, rest all
with capital.
Constant variables:Should be all uppercase with words
separated by underscores (“_”).
There are various constants used in predefined classes like Float,
Long, String etc.
Packages:The prefix of a unique package name is always
written in all-lowercase ASCII letters and should be one of the
top-level domain names, like com, edu, gov, mil, net, org.
Subsequent components of the package name vary according to
an organisation’s own internal naming conventions.Examples:
com.sun.eng com.apple.quicktime.v2 // java.lang packet in JDK
java.lang
12. Variables in Java
A variable is a name given to a memory location.
It is the basic unit of storage in a program.
The value stored in a variable can be changed
during program execution.
A variable is only a name given to a memory
location, all the operations done on the variable
effects that memory location.
In Java, all the variables must be declared before
use.
Varible Declaration:
Initialization
13. Types of variables
There are three types of variables in Java:
Local Variables
Instance Variables
Static Variables
14. Scope of Variables In Java
Member Variables (Class Level Scope)
Local Variables (Method Level Scope)
Loop Variables (Block Scope)
Some Important Points about Variable scope in Java:
In general, a set of curly brackets { } defines a scope.
In Java we can usually access a variable as long as it was
defined within the same set of brackets as the code we are
writing or within any curly brackets inside of the curly brackets
where the variable was defined.
Any variable defined in a class outside of any method can be
used by all member methods.
When a method has the same local variable as a member,
“this” keyword can be used to reference the current class
variable.
For a variable to be read after the termination of a loop, It must
be declared before the body of the loop.
15. Blank Final Variable in Java
A final variable in Java can be assigned a value
only once, we can assign a value either in
declaration or later.
final int i = 10; i = 30; // Error because i is
final.A blank final variable in Java is
a final variable that is not initialized during
declaration. Below is a simple example of blank
final.
// A simple blank final example
final int i; i = 30;
16. Loops in Java
Looping in programming languages is a feature
which facilitates the execution of a set of
instructions/functions repeatedly while some
condition evaluates to true.
Java provides three ways for executing the loops.
While all the ways provide similar basic
functionality, they differ in their syntax and
condition checking time.
while loop:
For Loop
Do-While Loop
17. While Loop
A while loop is a control
flow statement that allows
code to be executed
repeatedly based on a
given Boolean condition.
The while loop can be
thought of as a repeating
if statement.
18. For Loop
for loop provides a concise way of writing the loop structure.
Unlike a while loop, a for statement consumes the
initialization, condition and increment/decrement in one line
thereby providing a shorter, easy to debug structure of
looping.
19. do while:
do while loop is similar to while loop with only difference
that it checks for condition after executing the
statements, and therefore is an example of Exit Control
Loop.
20. Infinite Loop
Infinite loop: One of the most common mistakes while
implementing any sort of looping is that that it may not ever
exit, that is the loop runs for infinite time. This happens when
the condition fails for some reason.
93. for (i = 1; i <= n; i++) {
// left part of pattern
/*printing incremental numbers*/
for (j = 1; j <= (n - i + 1); j++) {
System.out.print(j + " ");
}
/*print spaces*/
for (int k = 0; k < 4 * (i - 1); k++) {
System.out.print(" ");
}
/* right part of the pattern*/
//printing decremental numbers
for (int l = (n - i + 1); l >= 1; l--) {
System.out.print(l + " ");
}
System.out.println();