_Unit 3 Java as Object Oriented Programming Language- Overview
_Unit 3 Java as Object Oriented Programming Language- Overview
College of Engineering
SE Computer- Division A
Course Name :Principles of Programming Language
Course Code: 210256
Course InCharge: Kainjan M. Sanghavi
Fundamentals of JAVA, Arrays: one dimensional Herbert Schildt, "The Complete Reference
Java", 9th Ed, TMH,ISBN: 978-0-07-
array, multi-dimensional array, alternative array
180856-9.
declaration statements ,String Handling: String class
methods Programming With Java, 3rd Edition, E.
Classes and Methods: class fundamentals, declaring
Balaguruswamy
Departmentof
Department ofComputer
ComputerEngineering
Engineering
SNJB’s Late Sau. K. B. J. College of Engineering
Topic Book To Refer
String Handling: String class methods Herbert Schildt, "The Complete Reference
Java", 9th Ed, TMH,ISBN: 978-0-07-
Classes and Methods: class fundamentals, declaring
180856-9.
objects, assigning object reference variables, adding
methods to a class, returning a value, constructors,
this keyword, garbage collection, finalize() method,
overloading methods, argument passing, object as
parameter, returning objects, access control, static,
final, nested and inner classes, command line
arguments, variable -length arguments.
Departmentof
Department ofComputer
ComputerEngineering
Engineering
SNJB’s Late Sau. K. B. J. College of Engineering
Topic Book To Refer
String Handling: String class methods Herbert Schildt, "The Complete Reference
Java", 9th Ed, TMH,ISBN: 978-0-07-
180856-9.
Page No- 413-431
Departmentof
Department ofComputer
ComputerEngineering
Engineering
SNJB’s Late Sau. K. B. J. College of Engineering
What is Java?
Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in
the year 1995. James Gosling is known as the father of Java. Before Java, its name was
Oak. Since Oak was already a registered company, so James Gosling and his team
changed the Oak name to Java.
5 6 7 8 0 2 4 6 1
199 199 199 199 200 200 200 200 201 2014
Java SE 6
Java SE 7
Java SE 8
J2SE 1.2
J2SE 1.3
J2SE 1.4
J2SE 5.0
JDK 1.0
JDK 1.1
Of Java SE 9
Java
Is Java Purely
Object Oriented?
No Then Why?
JDK is a software development kit whereas JRE is a software bundle that allows Java program
to run, whereas JVM is an environment for executing bytecode.
View
}
Department of Computer Engineering
SNJB’s Late Sau. K. B. J. College of Engineering
JAVA: Accessing a Specific Element in a Java Array
} OUTPUT
public static void main(String args[]) 1
{ 2
int x[] = { 1, 2, 3 }; 3
display(x); //Passed array x to method display
}
}
Department of Computer Engineering
SNJB’s Late Sau. K. B. J. College of Engineering
Click Here
Memory Allocation
and
Java Garbage Collection
69
String Intern Pool maintained in Java Heap Space
SNJB’s Late Sau. K. B. J. College of Engineering
70
Department of Computer Engineering
SNJB’s Late Sau. K. B. J. College of Engineering
71
Department of Computer Engineering
SNJB’s Late Sau. K. B. J. College of Engineering
s1 = s1 + s2;
72
Department of Computer Engineering
String Pool Concept in Java (String Interning)
● String is immutable in Java
● All Strings are stored in String Pool (also called String Intern Pool) allocated
within Java Heap Space
● It is implementation of String Interning Concept.
● String interning is a method of storing only one copy of each distinct string
value, which must be immutable.
● Interning strings makes some string processing tasks more time- or space-
efficient at the cost of requiring more time when the string is created or
interned.
● The distinct values are stored in a string intern pool.
● Using new operator, we force String class to create a new String object in heap
space. 73
String Pool Concept in Java (String Interning)
public class InternExample{
String s2="hello";
}}
74
java.lang.String API – Important methods
75
java.lang.String API – Important methods
76
java.lang.String API – Examples
77
java.lang.String API – Examples
public class EqualsSample{
public static void main(String args[]){
String s1="string";
String s2="string";
String s3="swing";
String s4= “ ABC ”;
System.out.println(s4.trim() +":wordpress.com");
//ABC.wordpress.com
System.out.println(s1.charAt(4)); // n
}
}
80
SNJB’s Late Sau. K. B. J. College of Engineering
Converting String to numbers and vice versa
● String to Number
○ int i = Integer.parseInt(str);
○ Integer i = Integer.valueOf(str);
○ double d = Double.parseDouble(str);
○ Double d = Double.valueOf(str);
Note: Both throw NumberFormatException If the String is not valid for conversion
Department of Computer Engineering
SNJB’s Late Sau. K. B. J. College of Engineering
Converting String to numbers and vice versa
● String to Boolean
○ boolean b = Boolean.parseBoolean(str);
Click Here
● Core of Java.
● Logical construct upon which the entire Java language is built
● Defines the shape and nature of and object.
● In fact, methods define the interface to most classes. This allows the
class implementor to hide the specific layout of internal data
structures behind cleaner method abstractions.
● In addition to defining methods that provide access to data,you can
also define methods that are used internally by the class itself.
Polymorphism.
● In Java it is possible to define two or more methods within the same class
that share the same name, as long as their parameter declarations are different
● When an overloaded method is invoked, Java uses the type and/or number of
arguments as its guide to determine which version of the overloaded
method to actually call
● The return type alone is insufficient to distinguish two versions of a
method.
these and supplies them to args[]. It can be confirmed that they are
using args.length.
args[ ] array that we pass into the main() function. We can check
Open the command prompt window and compile the program- javac Hello.java
System.out.println(s);
Department of Computer Engineering
SNJB’s Late Sau. K. B. J. College of Engineering
Varargs("Apple",
"Mango", "Pear");
Varargs();
Varargs("Magic");