You are on page 1of 32

CORE JAVA

By
Mr. Arun Kumar A
JAVA
• What is JAVA?
• JAVA is a platform independent programming
language
• Inventors of JAVA
• James Gosling, Mike Sheridan, Patrick
Naughton
Editions of Java
• J2SE -> Java Standard Edition
• J2EE -> Java Enterprise Edition
• J2ME -> Java Micro Edition
Difference Between JDK,JRE,JVM
Features of java
• 1)Simple
• 2)Secured
• 3)Platform independent
• 4)Architecture Neutral
• 5)Object oriented
• 6)Interpreted
• 7)High performance
• 8)Distributed
• 9)Dynamic
• 10)Robust
• 11)MultiThreaded
• 12)Portable
What is Java
Naming Conventions in Java
• Package name starts with lower case and each and
every word starting letter in upper case
• Example -> package myPack;
• Classes and interfaces starts with upper case and each
and every word starting letter in upper case
• Example -> class MyClass{
• Methods and variables start with lower case and each
and every word starting letter in upper case
• Example -> void add(){
-> int a = 10;
What are keywords
• Reserved words meant specific to
programming language and not to be used for
any other purpose
Identifiers
• Used for identification what ever names we use
in programs comes under identifiers
• RULES
• It should start with character (either upper case
or lower case) special character such as
underscore(_) and dollar allowed
• Numbers allowed but cannot start with numbers
• No keywords are to be used as identifier
Java Data Types
Data Type Size Range of values Default Values
->byte 1 -2^7 to 2^7-1 0
->short 2 -2^15 to 2^15-1 0
->int4 -2^31 to 2^31-1 0
->long 8 -2^63 to 2^63-1 0
->float 4 single precision 0.0
->double 8 double precision0.0
->char 2 unicode \u0000
->boolean 1bit true,false false
Architecture of JVM
Development Tools
• ->javac -> for compilation converting .java into
.class file java code to byte code file
• ->java -> for execution
• ->javap -> disassembler to view the class
• ->javadoc -> extracts documentation
comments
Comments
• Ignored by the compiler used for increasing
readability and understandability of program
• Three types of comments
• ->//single line comment
• ->/*Multi line
– Comment*/
– /**documentation comment*/
Is Java pure object oriented porgramming
language
• No
• Why?
• Because still data types are primitive and not
class we have wrapper classes which can give
object representation of the data
First Example-Hello world
Which is the default package imported by all
applications in java
• ->java.lang.*
• ->System and String is a class in java.lang
package
• ->System.out creates an instance or object of
PrintStream class in the package java.io.* with
which we access the println method and print
on the console screen
• System.out.println()
• System.out.print()
• System.out.printf()
• System.out.println(10+10+”Addition”)
• System.out.println(“Addition”+10+10)
• System.out.println(“Addition”+(10+10))
Variables in java
• Instance variable -> which comes inside the class but
outside all methods if uninitialized takes default
values access modifiers allowed
• Class/static variable -> which comes inside class but
outside all methods with static keyword if
uninitialized takes default values access modifier
allowed
• Local variable- >which comes inside methods must
be initialized else compiler error no access modifier
allowed
How to get input from user
• First import the java.util package
• Create an instance for Scanner class
• And access its respective methods to get the
input
• Scanner sc = new Scanner(System.in)
• Here System.in is a stream from which
represents a standard input device here it is
keyboard
How to get inputs methods of Scanner class

• -> int a = sc.nextInt()


• -> float b = sc.nextFloat()
• ->double d = sc.nextDouble()
• ->String str = sc.next()->to get word
• ->String str=sc.nextLine()-> to read sentence
• ->char ch = str.next().charAt(0)
• ->boolean b = sc.nextBoolean()
• ->long s = sc.nextLong()
Operators
• ->Unary operator ->
• ->binary operator ->
• ->ternary operator ->
• No operator overloading in java
Constructs
• ->Sequence
• ->Selection -> 1) Simple if
2) If else
3) If else if else if...else
4) Nested if
5) Switch case -> strings are allowed in switch
case in java

• ->Loops -> 1) while loop


• 2) do while loop
• 3) for loop
Statements
• ->break -> takes control out of loop
• ->continue -> skips particular iteration
Arrays
• Need for an array
• What is an array
• Types of array -> 1 D
• -> 2D
• -> 3D(multidimensional array)
• Jagged array

• What is the maximum dimension an array can


have
String Declare and intialize
• -> by literal -> String str = “Hello world”
• -> by new keyword -> String str = new String(“Hello world”)
• -> char arr[]={‘H’,’e’,’l’,’l’,’o’,’ ‘,’w’,’o’,’r’,’l’,’d’};
Strings
• String is a class in java.lang package since it is a class it can be called as data
type
• Methods of String
• ->length()
• ->trim()
• ->toUpperCase()
• ->toLowerCase()
• ->indexOf()
• ->lastIndexOf()
• ->startsWith()
• ->endsWith()
• ->concat()
• ->subString(bi,ei)
String
• ->replace()
• ->replaceAll()
• ->replaceFirst()
• ->split()
• ->getChars()
Comparison of String
• ->equals()
• ->equalsIgnoreCase()
• ->==
Immutability in String->does not allow
modification
StringBuffer and StringBuilder
• -> Mutable allows modification
• -> contains method which modifies the strings
• ->append()
• ->insert()
• ->delete()
• ->reverse()
• ->StringBuffer methods are synchronized
whereas StringBuilder not synchronized
Difference between static and instance
variable
Methods in java
• ->all methods are call by value no such thing
call by reference in java since no pointer
• ->instance method
• ->static method

You might also like