Download 1. Java does not include the C unique statement, keywords goto

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
JAVA INTRODUCTION
What is Java?
1. Java is a Pure Object – Oriented language
2. Java is developing by existing languages like C and C++.
How Java Differs From C?
1. Java does not include the C unique statement, keywords goto, sizeof,
and typedef.
2. Java does not support an explicit pointer type.
3. Java adds new operator such as instanceof and >>>
4. Java adds labeled break and continue statements.
5. Java does not have a preprocessor and therefore we cannot use
#define, #include, and #ifdef statements.
How Java Differs From C++?
1. Java does not support operator overloading.
2. Java does not have template classes as in C++.
3. Java does not support multiple inheritance of classes.
4. Java does not support global variables.
5. Java does not use Pointers
6. Java has replaced the destructor function with a finalize() function.
7. There are no header files in Java.
Java Compilation Process
Java Source Code
Java Compiler
Java Byte Code
(Java Class File)
Java Machine Code
Java Interpreter
What are the Java Features or Buzzwords.
1. Compiled and Interpreted
2. Platform – Independent and Portable
3. Object – Oriented
4. Robust and Secure
5. Distributed
6. Familiar, Simple and Small
7. Multithreaded and Interactive
8. High Performance
9. Dynamic and Extensible
What are the access leveling of the different access control?
private
private protected
friendly
protected
public
-
Same class in Same package
Sub class in Same package
Non – Sub class in Same package
Sub class in Other package
Other class in Other Package
What are the restrictions of the Static Method?
1. They can only call other static methods.
2. They must only access static data.
3. They cannot refer to this or super in any way.
What is the Purpose of final keyword?
a. Can’t redefined the initialization of the variable
b. Can’t Method Overriding
c. Can’t Inherit the Other class.
Pacakge X
A
B
C
Pacakge Y
D
E
ACCESS PROTECTION
Access Modifier
Access Location
Public
Protected
friendly
(default)
private
protected
private
Same Class
Yes
Yes
Yes
Yes
Yes
Subclass in same
package
Yes
Yes
Yes
Yes
No
Other classes in
same
package
Yes
Yes
Yes
No
No
Subclass in other
package
Yes
Yes
No
Yes
No
Non – subclasses
in other
packages
Yes
No
No
No
No
What are the conditions for the Abstract Classes?
1. We cannot use abstract classes to instantiate objects directly. For
example. Shape s = new Shape(); is illegal because shape is an abstract
class
2. The abstract methods of an abstract class must be defined in its
subclass
3. We cannot declare abstract constructors or abstract static
methods.
What are the differences between Abstract Classes and Interfaces?
Abstract classes
Interfaces
Abstract classes are used only when there is a “is-a”
type of relationship between the classes.
Interfaces can be implemented by classes that are not
related to one another.
You cannot extend more than one abstract class.
You can implement more than one interface.
it contains both abstract methods and non abstract
methods
Interface contains all abstract methods
Abstract class can implemented some methods also.
Interfaces can not implement methods.
With abstract classes, you are grabbing away each
class’s individuality.
With Interfaces, you are merely extending each class’s
functionality.
What are the differences between Class and Interfaces
Classes
Interfaces
Create a object for the Class.
Can’t Create the object for the interface.
Class can’t support multiple Inheritances.
Interface can support multiple Inheritances.
The methods present in classes are well defined.
The methods present in interfaces are pure abstract
(only declaration).
The access specifiers public, private, protected are
possible with classes.
But the interface uses only one spcifier public
Class contain for the member declaration as well as
member definition.
Interface contain only for the member declaration.
PACKAGES
What is Packages?
Packages are java’s way of grouping a variety of classes and / or interfaces
together. The grouping is usually done according to functionality. In fact, packages act as
“containers” for classes.
Types of Packages
Java packages are therefore classified into two types.
1. Pre – defined packages (Java API Packages)
2. User – defined packages
Java API Packages
Package Name
Contents
java.lang
Language support classes. These are classes that java compiler itself uses and therefore they
are automatically imported. They include classes for primitive types, strings, math
functions, threads and exceptions
java.util
Language utility classes such as vectors, hash tables, random numbers, date, etc.
java.io
Input / Output support classes. They provide facilities for the input and output of data.
java.awt
Set of classes for implementing graphical user interface. They include classes for windows,
buttons, lists, menus and so on.
java.net
Classes for networking. They include classes for communicating with local computers as
well as with internet servers.
java.applet
Classes for creating and implementing applets.
USER DEFINED PACKAGES
How to Creating our own Packages
Creating our own package involves the following steps:
1. Declare the package at the beginning of a file using the form
package package_name;
2. Define the class that is to be put in the package and declare it public
3. Create a subdirectory under the directory where the main source files are
stored.
4. Store the listing as the classname.java file in the subdirectory created.
5. Compile the file. This creates .class file in the subdirectory.
6. The subdirectory name must match the package name exactly.
Note:
Java also supports the concept of package hierarchy. This done by specifying
multiple names in a package statement, separated by dots.
Example:
package firstPackage.secondpackage;