introduction& data types
Day-1
1. platform independent
windows
| runs
windows
ex : C,CPP
windows
windows Linux mac ......etc
ex: java
C : n/w , hardware , drivers
java : internet based : www : Gmail, bank , reservation....etc
2. open source.
free of cost
source code open : we can download the source code we can do the
modifications.
JDBC ----> Hibernate
Jsp ----> JSF
servlets ----> structs
EJB ----> spring
java Developers:
level-1
core java
adv java
level-2
hibernate
spring
level-3:
web services
spring Boot, security
micro services oAuth
DP
Day-2
There are three parts of java:
1) J2SE/JSE (java 2 standard edition)
2) J2EE/JEE (java 2 enterprise edition)
3) J2ME/JME (java 2 micro edition)
//java introduction:
Author : James gosling
vendor : sun micro systems (oracle)
Initial name : Oak lang [tree name]
present name : java
java dev : 1991
beta version : 1995
initial version : jdk1.0 1996
present version : java 14
stable version : java 8
parts of java : j2se j2ee j2me
operating systems : all
moto of java : WORA [write once run anywhere]
implemented lang : C,CPP
file extension : .java, .class
Website : oracle.com/java/
type of s/w : open source
compilation process : java compiler
execution process : JVM [java virtual machine]
C-lang is procedure oriented deals with : functions
java-lang is object oriented deals with : classes
Importance of core java: According to the SUN 3 billion devices run on the java
language only.
Java is used to develop Desktop Applications such as Media Player, Antivirus
etc.
Java is Used to Develop Web Applications such as Durga soft.com, irctc.co.in
etc.
Java is Used to Develop Enterprise Application such as Banking applications.
Java is Used to Develop Mobile Applications.
Java is Used to Develop Embedded System.
Java is Used to Develop Smartcards.
Java is Used to Develop Robotics.
Java is used to Develop Games ………………………..etc.
Programming languages are giving the instructions to computer to perform some
action.
there are three types of programming languages.
1. low level lang
0101010101010101
2. middle level lang
01ABN0100HGJ
3. high level lang
general language (like English)
"java is high level language"
http://pypl.github.io/PYPL.html
java software:
download the software
https://www.oracle.com/in/java/technologies/javase/javase-jdk8-
downloads.html
Windows x64 211.54 MB jdk-8u251-windows-x64.exe
install the software
next -> next -> next -> next ------ finish
C:\Program Files\Java
JDK
JRE
Day-3
C:\Program Files\Java
JDK : compile & runtime environment
development we need JDK
JRE : only Runtime environment
production env
//set the path:
To perform compilation & execution we need below commands
javac : java compiler
java : java execution
the commands are present in location : C:\Program Files\Java\jdk1.8.0_231\bin
to give the above commands to entire os(C,D,E,F,G....) we have to
set the path.
once we set the path we can save the .java file any location & we can do the
compilation & execution.
variable name : path
Variable value : C:\Program Files\Java\jdk1.8.0_231\bin
editors : notepad, notepad++, editplus...
https://www.editplus.com/download.html
keywords : 50
data types : byte short int long float double char boolean 8
flow control : if,else,switch,case,default,break,for,while,do,continue 10
exception : try, catch, finally, throw, throws 5
object level : new, this, super, instanceof 4
source file : class, extends, interface, implements, package, import 6
method level : void, return 2
java 1.5 : enum, assert 2
un-used : goto, const 2
modifiers : public,private,protected,abstract,final,static,strictfp,
synchronized,volatile,native,transient 11
constants : true, false, null 3
Reserved words(53) = keywords(50) + cons(3)
Assignment: what are the different types of apps in mobile.
Day-4
C-lang : Dennis Retchie : 1972 : AT & T bell lab : PD : .c .obj .exe
#include<stdio.h>
void main()
{ printf("Ratan world")
}
in c-language predefined support in the form of header files ---> the header file
contains functions in above example we are using printf() & this function present
in stdio.h so include that header file using #inculde
In c-lang execution starts from the main method: called by Operating system
CPP-lang : Designed by Bjarne Stroustrup : First appeared 1985 : AT & T
bell : .cpp .h : PD
#include<iostream.h>
void main()
{ cout<<"Ratan world";
}
in CPP-language predefiend support in the form of header files ---> the header file
contians functions
in above example we are using cout() & this function present in iostream.h so
include that header file using #inculde
In cpp-lang execution starts from main method : called by Operating system
Java-lang : James gosling : 1995 : sun Microsystems(oracle) : .java .class : object
oriented deals with classes.
import java.lang.System;
import java.lang.String;
class Test
{ public static void main(String[] args)
{ System.out.println("ratan world");
}
}
in java-language predefiend support in the form of pacakges---> The pacakges
contians classes
in above example we are using two predefined classes(System,String) & these classes
are present in java.lang so import the pacakge using import statement.
we can import the classes in two ways,
1. importing all classes
import java.lang.*;
2. importing required classes [this is recommanded approach]
import java.lang.System;
import java.lang.String;
In java-lang execution starts from main method : called by JVM
ASCII vs. Unicode:
ASCII : American Standard Code for Information Interchange
supports only english
a-z A-Z 0-9 special symbols
char 1-byte
range : 0-255
a=97 b=98 A=65 B=66 0=48 1=49
Unicode : universal code
supports all languages present in world
char 2-bytes
range : 0-65535
a=97 b=98 A=65 B=66 0=48 1=49
"r a t a n"
121 97
11100
machhine : 01010010101
Day-5
steps to design first application:
step 1 : write the application.
step 2 : save the application.
step 3 : compilation process.
step 4 : execution process
step 1 : write the application.
import java.lang.System;
import java.lang.String;
class Test
{ public static void main(String[] args)
{ System.out.println("Ratan World");
}
}
class A
{
}
class B
{
}
System,String -----> java.lang
so import the classes using import statement.
we can import the classes in two ways
1. importing all classes
import java.lang.*;
2. importing required classes
import java.lang.System;
import java.lang.String;
step 2: save the application
save the application using .java extension.
rules:
a. if the application contains public class then save the application using public
cls name.
b. if there is no public cls then we can save the application using any name.
Note: the source file allowed only one public class. if we declare more than one
public cls we will get error.
application location:
E:
|--->java7pm
|--->Zak.java
step 3: compilation process. : java compiler
compile the application using javac command.
syntax : javac file-name
javac Zak.java
a. compiler checks syntax error : if any error compiler generates error
message.
b. if no error in source file then compiler translates .java ---- .class
Note : compiler is a transaltor it will translate .java-----.class
compiler is a transaltor it will translate high level language -----
intermediate code(byte code).
Note : Compiler generates .class files based on number of classes present in
source file.
A.class B.class Test.class
Note : byte code is platform independent. once the byte code is ready we can run
that byte using any os.
step 4: exeuction process : JVM : java virtual machine.
execute the application using java command.
syntax : java class-name
java Test
a. JVM loads .class file byte code into memory
b. after loading the class JVM will call main method to
start the execution process.
E:\java7pm>java Test
Ratan World
E:\java7pm>java A
Error: Main method not found in class A, please define the main method as:
E:\java7pm>java B
Error: Main method not found in class B, please define the main method as:
E:\java7pm>java C
Error: Could not find or load main class C
java predefined support in the form of pacakges, the packages contains 6-elements
classes
interfaces
enums
Annotations
Exceptions
Errors
day-6
java coding convensions :
camel case:
starts with upper case & every inner word also starts with upper case.
classes : String, StringBuffer , InputStreamReader
interfaces : Serializable, RandomAccess
enums : Enum
annotations : Override SuppressWarnings
exceptions : ArithmeticException
errors : StackOverflowError
mixed case:
starts with lower case & inner words starts with upper case
methods : post() charAt() toUpperCase()
variables : out in pageContext
lower case:
every character is lower case
keywords : try,new,this,super.
packages : java.lang java.io java.util
upper case:
every character is upper case
enums cons : MAX_PRIORITY MIN_PRIORITY NORM_PRIORITY
conclusion-1 : The java contains 14-packages.
ex: java.lang java.io java.util
The default pacakge in java is java.lang package.
conclusion-2: The coding convensions are mandatory for predefined library &
optional for userdefined library but we have to fallow.
class test
{ public static void main(String[] args)
{ System.out.println("Niharika World!");
}
}
E:\java7pm>javac Zak.java
E:\java7pm>java test
Niharika World!
conclusion-3:
E:
|---->java7pm
|-->A.java
|-->B.java
|-->C.java
|-->D.java
javac A.java 1-file compiled
javac B.java C.java 2-files are compiled
javac *.java all files are compiled
possible to compile multiple files at a time but possible to execute only one class
file.
conclusion-4:
class Test //main class
{ public static void main(String[] args)
{ System.out.println("Test World!");
}
}
class A
{ public static void main(String[] args)
{ System.out.println("A World!");
}
}
class B
{ public static void main(String[] args)
{ System.out.println("B World!");
}
}
E:\java7pm>javac Zak.java
E:\java7pm>java Test
Test World!
E:\java7pm>java A
A World!
E:\java7pm>java B
B World!
The source file allows to declare multiple main classes.
The source file allows to declare only one public class.
conclusion-5:
java is platform independent but JVM is patform dependent.
Java Comments:
Comments are used to write the detailed description about application logics to
understand the logics easily.
The main objective of comments is application maintenance will become easy.
Comments are non-executable code these are ignored during compilation.
There are 3 types of comments.
Single line Comments: Possible to write the description in single line.
Syntax: //description
Multi line Comments: To write the description in more than one line.
Starts with : /*
Ends with : */
Syntax: /* satement-1
statement-2
;;;;;;;;;;;;;;
statement-n
*/
Documentation Comments: Used to prepare API documents.
Syntax: - /*
*statement-1
*statement-2
*statement-3
*statement-4
*/
API(Application programming interface) :
It contains detailed description about how to use java product.
It is an interface between end-user & product.
https://docs.oracle.com/javase/8/docs/api/ : to see the docs
http://docs.oracle.com/javase/8/docs : to download the document
Day-7
data types : To represent the data.
data types memory(bytes) range default-values(JVM)
byte 1 -128 to 127 0
short 2 0
int 4 0
long 8 0
float 4 0.0
double 8 0.0
char 2 0-65535 space
boolean no-size false
byte,short,int,long ----- numaric data --- 10 20 30 40
float double ----- decimal data ----10.5 20.4
char ----- single characger ---- 'a' 'C'
boolean ----- boolean data ---- true,false
byte data type:
size : 1-byte
range : -128 to 127
-2n to 2n-1 where n = number of bits n = 8
1-bit is sign bit 0=+ve 1=-ve
//printing the varaibles
int num = 10;
System.out.println(num); // valid
System.out.println("num"); // Invalid
System.out.println('num'); // Invalid
//user assigned values are printted
int a = 10;
System.out.println(a); // 10
//default values are printed
int a;
System.out.println(a); // 0
Emp proj :
int eid = 111;
String ename = "ratan";
double esal = 10000.45;
String is not a data type, it is a class to represent a group of characters
enclosed in double-quotes.
String str= "ratan";
System.out.println(str); // ratan
String str;
System.out.println(str); // null
Note : any cls type the default value is null.
ex-1: In java the decimal values are by default double values hence to represent
float value use f constant or perform type casting.
float f = 10.5f; //using f constant (valid)
float f = (float)10.5; //using type casting (valid)
class Test
{ public static void main(String[] args)
{ float f = 10.5f;
System.out.println(f);
double d = 20.5;
System.out.println(d);
}
}
ex-2:A double variable can provide precision up to 15 to 16 decimal points as
compared to float precision of 6 to 7 decimal digits.
class Test
{ public static void main(String[] args)
{ float f=10.123456789f;
System.out.println(f);
double d=10.123456789123456789;
System.out.println(d);
}
}
E:\java7pm>java Test
10.123457
10.123456789123457
ex-3: in java the numraic data is by default int type so to represent long value
use l constant.
class Test
{ public static void main(String[] args)
{
long card = 7875876798780989l;
System.out.println(card);
}
}
ex 4: uderscores in numaric literals : java7
With Java 7, you can include underscores in numeric literals to make them more
readable. The underscore is only present in the representation of the literal in
Java code, and will not show up when you print the value.
class Test
{ public static void main(String[] args)
{ long card = 7875_8767_9878_0989l;
System.out.println(card);
}
}
rules :
a. Consecutive underscores is legal.
int n = 544__543____543; valid
b. before & after the constant underscores are not allowed.
long card = 4354334345345_l; Invalid
long card = 4354334345345l_; Invalid
float f = 10.5f_; Invalid
float f = 10.5_f; Invalid
c. Before & after decimal point underscores are not allowed.
double d = 2323_.323; Invalid
double d = 2323._323; Invalid
d. starting & ending of the value underscores are not allowed.
int num = _100; Invalid
int num = 100_; Invalid
ex: print(): used to print the data after printing the data control present in same
location.
println(): used to print the data after printing the data control goes to new
line.
class Test
{ public static void main(String[] args)
{
System.out.print("Zak");
System.out.print("sai");
System.out.println("ratan");
System.out.println("anu");
}
}
E:\java7pm>java Test
Zaksairatan
anu
Assignmnet : Number system
Binary system : Base 2 : 0 1
octal system : Base 8 : 0 1 2 3 4 5 6 7
decimal system : Base 10 : 0 1 2 3 4 5 6 7 8 9
hexa deciaml : Base 16 : 0-9 a-f a=10 b-11 c-13 d-14
ex: A character preceded by a backslash (\) is an escape sequence and has special
meaning to the compiler. The following table shows the Java escape sequences.
class Test
{ public static void main(String[] args)
{
System.out.println("hi ratan sir");
System.out.println("hi \"ratan\" sir");
System.out.println("hi \'ratan\' sir");
System.out.println("hi \\ratan\\ sir");
System.out.println("hi\t\t ratan \t\tsir");
System.out.println("hi \nratan\nsir");
}
}
Java Tokens:
The smallest individual part of a java program is called Token &It is possible to
provide n number of spaces in between two tokens.
class Test
{ public
static void main (String[] args)
{
System .
out .
println
("hi ratan sir");
}
}
Java identifiers: Every name in java is called an identifier such as, Class-name,
Method-name, Variable-name…etc
rules:
1. Identifier contains (a-z , A-Z , 0-9 , _ , $) but not start with number & not
allowed special characters.
class MyClass123 : valid
class 123MyClass : invaid
class MyClass_123 : valid
class MyClass*123 : invalid
2. must be unique
class A{
}
class A{
}
3. case sensitive.
class Test
{
int a=10;
int A=20;
}
4. no length limit
class Test
{
}
5. keywords are not possible to take the identifier.
int num = 10; valid
int this = 20; Invalid
6. It is possible to use predefined class names & interfaces names as a identifier
but it is not recommended.
class Test
{ public static void main(String[] args)
{
int String = 100;
System.out.println(String);
int Serializable = 200;
System.out.println(Serializable);
}
}
E:\>javac Test.java
E:\>java Test
100
200