4. What is Java?
A most popular programming language
developed by James Gosling
Object Oriented
A simple, object oriented, distributed, interpreted,
robust, secure, WORA(Write Once Run Anywhere),
portable, high performance, multithreaded, dynamic
language.
5. Some History
1993 Oak project at Sun
small, robust, architecture independent, Object-Oriented, language to
control interactive TV.
didn’t go anywhere
1995 Oak becomes Java
Focus on the web
1996 Java 1.0 available
1997 (March) Java 1.1 - some language changes, much larger library, new
event handling model
1997 (September) Java 1.2 beta – huge increase in libraries including
Swing, new collection classes, J2EE
1998 (October) Java 1.2 final (Java2!)
2000 (April) Java 1.3 final
2001 Java 1.4 final (assert)
2004 Java 1.5 (parameterized types, enum, …) (Java5!)
2005 J2EE 1.5
7. Difference between JAVA & C
JAVA is Object-Oriented while C is procedural. Different Paradigms,
that is.
Java is an Interpreted language while C is a compiled language.
C is a low-level language while JAVA is a high-level language.
C uses the top-down {sharp & smooth} approach while JAVA uses
the bottom-up {on the rocks} approach.
Pointer go backstage in JAVA while C requires explicit handling of
pointers.
JAVA supports Method Overloading while C does not support
overloading at all.
Unlike C, JAVA does not support Preprocessors, & does not really
them.
8. Data types
There are eight basic data types in JAVA :
char – to store a character(1 byte).
int – to store an integer value(4 bytes).
float – to store a floating point number(4 bytes).
double –to store a double precision floating point
number(8 bytes).
Long
Short
9.
10. if
if statement:
Executes a set of commands only if a certain condition is true.
Otherwise, the commands are skipped.
Syntax:
if(condition)
{
statements
}
Example:
if(age>=18)
System.out.println(“You can vote”);
11. if/else
if/else statement:
Executes one set of statements if a certain condition is True, and a second
set if it is False.
Syntax:
if(condition)
statements;
else
statements;
Example:
if (a < 10)
System.out.println(“a is less than 10n”);
else if (a == 10)
System.out.println(“a is 10n”);
else
System.out.println(“a is greater than 10n”);
12. Switch
int c = 10;
switch (c)
{
case 0:
printf(“c is 0n”);
break;
……
default:
printf(“Unknown value of cn”);
break;
}
13.
14. for loops
It executes a particular set of statements specified number of times.
Depending on the language mode, you may not be able to declare variable inside
a for-loop definition:
Syntax:
declaration
for(initialisation;condition;updation)
statements;
Example:
int i;
for (i = 0; i < 10; i++)
{
printf(“%d n”, i);
}
15. PROGRAM
# Program to print “Hello World”.
class World
{
public static void main(String[]args)
{
System.out.println(“Hello, Worldn");
}}