Upload
menageshkumar5342
View
219
Download
0
Embed Size (px)
Citation preview
8/7/2019 Java Remaining
1/6
Nimbus InfocomAura Of Excellence In Computer Education
7, Daan Bari
Jawahar Nagar
Kota (Rajasthan)Mobile No. : 09928088743
C, C++, DSA, VB, VB.Net, C#, ASP.Net, Java(Core & Adv), PHP+MySql, UNIX, LINUX, Oracle, PL/SQL, BCA, MCA, BTECH
Local Applet and Remote Applet
An Applet is a window based java program that is used for internet applications. These can berun by using either web browser or with an applet viewer. There are two types of applets: Localapplets and Remote applets.
Local AppletA LOCAL applet is the one which is stored on our computer system.when browser try to accessthe applet, it is not necessary for our computer to be connected to The Internet.
Remote appletsRemote applets are developed by unknown persons and stored in remote computers. To run a
remote applet internet connection is needed. At the run time the system searches the appletcode in the internet and it is downloaded. To download a remote applet, we must give the
address of the applet in HTML page.
Difference between JDK, JRE and JVMJDK (Java Development Kit)Java Developer Kit contains tools needed to develop the Java programs, andJREto run theprograms. The tools include compiler (javac.exe), Java application launcher (java.exe),Appletviewer, etc
Compiler converts java code into byte code. Java application launcher opens aJRE, loads the
class, and invokes its main method.
You needJDK, if at all you want to write your own programs, and to compile the m. For runningjava programs, JRE is sufficient.
JRE is targeted for execution of Java files i.e. JRE = JVM + Java Packages Classes(like util,math, lang, awt,swing etc)+runtime libraries.JDKis mainly targeted for java development. I.e. You can create a Java file (with the help ofJava packages), compile a Java file and run a java file
JRE (Java Runtime Environment)Java Runtime Environment contains JVM, class libraries, and other supporting files. It does notcontain any development tools such as compiler, debugger, etc. Actually JVM runs the program,and it uses the class libraries, and other supporting files provided in JRE. If you want to run any
java program, you need to have JRE installed in the system
TheJava Virtual Machine provides a platform-independent way of executing code;programmers can concentrate on writing software, without having to be concerned with how or
where it will run.
If u just want to run applets (ex: Online Yahoo games or puzzles),JREneeds to be installed onthe machine.
JVM (Java Virtual Machine)As we all aware when we compile aJava file, output is not an 'exe' but it's a '.class' file. '.class'
file consists ofJava byte codes which are understandable by JVM. Java Virtual Machineinterprets the byte code into the machine code depending upon the underlying operatingsystem and hardware combination. It is responsible for all the things like garbage collection,array bounds checking, etc JVM is platform dependent.
Topic : Java Page 1Notes ByNAGESH KUMAR Contact No: 09928088743
http://classof1.com/homework_answers/computer_science/html/http://classof1.com/homework_answers/computer_science/html/8/7/2019 Java Remaining
2/6
Nimbus InfocomAura Of Excellence In Computer Education
7, Daan Bari
Jawahar Nagar
Kota (Rajasthan)Mobile No. : 09928088743
C, C++, DSA, VB, VB.Net, C#, ASP.Net, Java(Core & Adv), PHP+MySql, UNIX, LINUX, Oracle, PL/SQL, BCA, MCA, BTECH
TheJVMis called "virtual" because it provides a machine interface that does not depend on theunderlying operating system and machine hardware architecture. This independence fromhardware and operating system is a cornerstone of the write-once run-anywhere value of Java
programs.
There are different JVM implementations are there. These may differ in things like performance,reliability, speed, etc. These implementations will differ in those areas where Java specification
doesnt mention how to implement the features, like how the garbage collection process worksis JVM dependent, Java spec doesnt define any specific way to do this.
Getting User InputIn Java 1.0, the only way to perform console input was to use a byte stream, and older codethat uses this approach persists. Today, using a byte stream to read console input is still
technically possible, but doing so may require the use of a deprecated method, and thisapproach is not recommended. The preferred method of reading console input for Java 2 is to
use a character-oriented stream, which makes your program easier to internationalize andmaintain.
Java does not have a generalized console input method that parallels the standard C functionscanf( ) or C++ input operators.In Java, console input is accomplished by reading from System.in. To obtain a character-basedstream that is attached to the console, you wrap System.in in a BufferedReader object, tocreate a character stream. BuffereredReader supports a buffered input stream. Its mostcommonly used constructor is shown here:
BufferedReader(Reader inputReader)
Here, inputReaderis the stream that is linked to the instance ofBufferedReader that is being
created. Reader is an abstract class. One of its concrete subclasses is InputStreamReader,which converts bytes to characters. To obtain an InputStreamReader object that is linked toSystem.in, use the following constructor:
InputStreamReader(InputStream inputStream)
Because System.in refers to an object of type InputStream, it can be used for inputStream.Putting it all together, the following line of code creates a BufferedReader that is connected to
the keyboard:
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
After this statement executes, br is a character-based stream that is linked to the consolethrough System.in.
Reading CharactersTo read a character from a BufferedReader, use read( ). The version ofread( ) that we willbe using is int read( ) throws IOException Each time that read( ) is called, it reads a characterfrom the input stream and returns it as an integer value. It returns 1 when the end of thestream is encountered. As you can see, it can throw an IOException.
The following program demonstrates read( ) by reading characters from the console until theuser types a q:
// Use a BufferedReader to read characters from the console.import java.io.*;class BRRead{
public static void main(String args[]) throws IOException{
Topic : Java Page 2Notes ByNAGESH KUMAR Contact No: 09928088743
8/7/2019 Java Remaining
3/6
Nimbus InfocomAura Of Excellence In Computer Education
7, Daan Bari
Jawahar Nagar
Kota (Rajasthan)Mobile No. : 09928088743
C, C++, DSA, VB, VB.Net, C#, ASP.Net, Java(Core & Adv), PHP+MySql, UNIX, LINUX, Oracle, PL/SQL, BCA, MCA, BTECH
char c;BufferedReader br = new BufferedReader(new InputStreamReader(System.in));System.out.println("Enter characters, 'q' to quit.");
// read charactersdo
{c = (char) br.read();
System.out.println(c);} while(c != 'q');
}}Here is a sample run:Enter characters, 'q' to quit.123abcq1
23
ab
cqThis output may look a little different from what you expected, because System.in is linebuffered, by default. This means that no input is actually passed to the program until you pressENTER. As you can guess, this does not make read( ) particularly valuable for interactive,console input.
Reading Strings
To read a string from the keyboard, use the version ofreadLine( ) that is a member of theBufferedReader class. Its general form is shown here:
String readLine( ) throws IOException
It returns a String object.The following program demonstrates BufferedReader and the readLine( ) method; theprogram reads and displays lines of text until you enter the word stop:
// Read a string from console using a BufferedReader.import java.io.*;class BRReadLines
{ public static void main(String args[]) throws IOException{
// create a BufferedReader using System.inBufferedReader br = new BufferedReader(new InputStreamReader(System.in));String str;System.out.println("Enter lines of text.");System.out.println("Enter 'stop' to quit.");do{
str = br.readLine();
System.out.println(str);}
while(!str.equals("stop"));}
}
Topic : Java Page 3Notes ByNAGESH KUMAR Contact No: 09928088743
8/7/2019 Java Remaining
4/6
Nimbus InfocomAura Of Excellence In Computer Education
7, Daan Bari
Jawahar Nagar
Kota (Rajasthan)Mobile No. : 09928088743
C, C++, DSA, VB, VB.Net, C#, ASP.Net, Java(Core & Adv), PHP+MySql, UNIX, LINUX, Oracle, PL/SQL, BCA, MCA, BTECH
Comparison of Java and C++The differences between the C++ and Java programming languages can be traced to theirheritage, as they
have different design goals.
C++ was designed mainly for systems programming, extending the C programming language. To this
procedural programming language designed for efficient execution, C++ has added support for
statically-typedobject-oriented programming,exception handling,scoped resource management, and
generic programming, in particular. It also added a standard librarywhich includes generic containers
and algorithms.
Java was created initially to support network computing. It relies on a virtual machine to be secure
and highlyportable. It is bundled with an extensive library designed to provide a complete abstraction
of the underlying platform. Java is a statically-typed object-oriented language that uses a syntax
similar to C++, but is not compatible with it. It was designed from scratch, with the goal of being easy
to use and accessible to a wider audience.
The different goals in the development of C++ and Java resulted in different principles and design trade-offs
between the languages. The differences are as follows:
C++ Java
Compatible with Csource code, except for a few
corner cases.
No backward compatibility with any previous
language. The syntax is however strongly influenced
by C/C++.
Write once compile anywhere (WOCA)Write once run anywhere / everywhere (WORA /
WORE)
Allowsprocedural programming,object-oriented
programming, and generic programming.
Encourages an object orientedprogramming paradigm.
Allows direct calls to native system libraries.Call through theJava Native Interface and recently
Java Native Access
Exposes low-level system facilities. Runs in a protected virtual machine.
Only provides object types and type names.Is reflective, allowing metaprogramming and dynamic
code generation at runtime.
Has multiple binary compatibility standards
(commonly Microsoft and Itanium/GNU)
Has a binary compatibility standard, allowing runtime
check of correctness of libraries.
Optional automatedbounds checking. (e.g. the at()
method in vector and string containers)
Normally performs bounds checking.HotSpot can
remove bounds checking.
Supports native unsigned arithmetic. No native support for unsigned arithmetic.
Standardized minimum limits for all numerical types,but the actual sizes are implementation-defined.
Standardized types are available as typedefs
(uint8_t, ..., uintptr_t).
Standardized limits and sizes of all primitive types on
all platforms.
Pointers, References, and pass by value are supportedPrimitive and reference data types always passed by
value.
Explicit memory management, though third party
frameworks exist to provide garbage collection.
Supports destructors.
Automatic garbage collection (can be triggered
manually). Doesn't have the concept ofDestructorand
usage offinalize() is not recommended.
Supports class, struct, and union and can allocate them
onheaporstack
Supports only class and allocates them on the heap.
Java SE 6 optimizes with escape analysis to allocate
some objects on the stack.Allows explicitly overriding types.
Rigidtype safetyexcept for widening conversions.
Autoboxing/Unboxing added in Java 1.5.
TheC++ Standard Library has a much more limited The standard library has grown with each release. By
Topic : Java Page 4Notes ByNAGESH KUMAR Contact No: 09928088743
http://en.wikipedia.org/wiki/Virtual_Heritagehttp://en.wikipedia.org/wiki/Virtual_Heritagehttp://en.wikipedia.org/wiki/C_(programming_language)http://en.wikipedia.org/wiki/Procedural_programminghttp://en.wikipedia.org/wiki/Static_typinghttp://en.wikipedia.org/wiki/Object-oriented_programminghttp://en.wikipedia.org/wiki/Object-oriented_programminghttp://en.wikipedia.org/wiki/Exception_handlinghttp://en.wikipedia.org/wiki/Exception_handlinghttp://en.wikipedia.org/wiki/Exception_handlinghttp://en.wikipedia.org/wiki/RAIIhttp://en.wikipedia.org/wiki/RAIIhttp://en.wikipedia.org/wiki/Generic_programminghttp://en.wikipedia.org/wiki/C%2B%2B_Standard_Libraryhttp://en.wikipedia.org/wiki/C%2B%2B_Standard_Libraryhttp://en.wikipedia.org/wiki/Network_computinghttp://en.wikipedia.org/wiki/Virtual_machinehttp://en.wikipedia.org/wiki/Computer_securityhttp://en.wikipedia.org/wiki/Portinghttp://en.wikipedia.org/wiki/Portinghttp://en.wikipedia.org/wiki/C_(programming_language)http://en.wikipedia.org/wiki/C_(programming_language)http://en.wikipedia.org/wiki/Corner_casehttp://en.wikipedia.org/wiki/Procedural_programminghttp://en.wikipedia.org/wiki/Procedural_programminghttp://en.wikipedia.org/wiki/Object-oriented_programminghttp://en.wikipedia.org/wiki/Object-oriented_programminghttp://en.wikipedia.org/wiki/Object-oriented_programminghttp://en.wikipedia.org/wiki/Generic_programminghttp://en.wikipedia.org/wiki/Programming_paradigmhttp://en.wikipedia.org/wiki/Java_Native_Interfacehttp://en.wikipedia.org/wiki/Java_Native_Interfacehttp://en.wikipedia.org/wiki/Java_Native_Accesshttp://en.wikipedia.org/wiki/Reflection_(computer_science)http://en.wikipedia.org/wiki/Reflection_(computer_science)http://en.wikipedia.org/wiki/Bounds_checkinghttp://en.wikipedia.org/wiki/Bounds_checkinghttp://en.wikipedia.org/wiki/HotSpothttp://en.wikipedia.org/wiki/HotSpothttp://en.wikipedia.org/wiki/Destructor_(computer_science)http://en.wikipedia.org/wiki/Destructor_(computer_science)http://en.wikipedia.org/wiki/Dynamic_memory_allocationhttp://en.wikipedia.org/wiki/Dynamic_memory_allocationhttp://en.wikipedia.org/wiki/Dynamic_memory_allocationhttp://en.wikipedia.org/wiki/Stack-based_memory_allocationhttp://en.wikipedia.org/wiki/Dynamic_memory_allocationhttp://en.wikipedia.org/wiki/Java_version_history#Java_SE_6_Update_14http://en.wikipedia.org/wiki/Escape_analysishttp://en.wikipedia.org/wiki/Stack-based_memory_allocationhttp://en.wikipedia.org/wiki/Type_safetyhttp://en.wikipedia.org/wiki/Type_safetyhttp://en.wikipedia.org/wiki/Type_safetyhttp://en.wikipedia.org/wiki/C%2B%2B_Standard_Libraryhttp://en.wikipedia.org/wiki/C%2B%2B_Standard_Libraryhttp://en.wikipedia.org/wiki/Virtual_Heritagehttp://en.wikipedia.org/wiki/C_(programming_language)http://en.wikipedia.org/wiki/Procedural_programminghttp://en.wikipedia.org/wiki/Static_typinghttp://en.wikipedia.org/wiki/Object-oriented_programminghttp://en.wikipedia.org/wiki/Exception_handlinghttp://en.wikipedia.org/wiki/RAIIhttp://en.wikipedia.org/wiki/Generic_programminghttp://en.wikipedia.org/wiki/C%2B%2B_Standard_Libraryhttp://en.wikipedia.org/wiki/Network_computinghttp://en.wikipedia.org/wiki/Virtual_machinehttp://en.wikipedia.org/wiki/Computer_securityhttp://en.wikipedia.org/wiki/Portinghttp://en.wikipedia.org/wiki/C_(programming_language)http://en.wikipedia.org/wiki/Corner_casehttp://en.wikipedia.org/wiki/Procedural_programminghttp://en.wikipedia.org/wiki/Object-oriented_programminghttp://en.wikipedia.org/wiki/Object-oriented_programminghttp://en.wikipedia.org/wiki/Generic_programminghttp://en.wikipedia.org/wiki/Programming_paradigmhttp://en.wikipedia.org/wiki/Java_Native_Interfacehttp://en.wikipedia.org/wiki/Java_Native_Accesshttp://en.wikipedia.org/wiki/Reflection_(computer_science)http://en.wikipedia.org/wiki/Bounds_checkinghttp://en.wikipedia.org/wiki/HotSpothttp://en.wikipedia.org/wiki/Destructor_(computer_science)http://en.wikipedia.org/wiki/Dynamic_memory_allocationhttp://en.wikipedia.org/wiki/Stack-based_memory_allocationhttp://en.wikipedia.org/wiki/Dynamic_memory_allocationhttp://en.wikipedia.org/wiki/Java_version_history#Java_SE_6_Update_14http://en.wikipedia.org/wiki/Escape_analysishttp://en.wikipedia.org/wiki/Stack-based_memory_allocationhttp://en.wikipedia.org/wiki/Type_safetyhttp://en.wikipedia.org/wiki/C%2B%2B_Standard_Library8/7/2019 Java Remaining
5/6
Nimbus InfocomAura Of Excellence In Computer Education
7, Daan Bari
Jawahar Nagar
Kota (Rajasthan)Mobile No. : 09928088743
C, C++, DSA, VB, VB.Net, C#, ASP.Net, Java(Core & Adv), PHP+MySql, UNIX, LINUX, Oracle, PL/SQL, BCA, MCA, BTECH
scope and functionality than the Java standard library
but includes: Language support, Diagnostics, General
Utilities, Strings, Locales, Containers, Algorithms,Iterators, Numerics, Input/Output and Standard C
Library. The Boost library offers much more
functionality including threads and network I/O. Users
must choose from a plethora of (mostly mutually
incompatible) third-party libraries for GUI and other
functionality.
version 1.6 the library included support for locales,
logging, containers and iterators, algorithms, GUI
programming (but not using the system GUI), graphics,
multi-threading, networking, platform security,introspection, dynamic class loading, blocking and
non-blocking I/O, and provided interfaces or support
classes forXML, XSLT, MIDI, database connectivity,
naming services (e.g.LDAP), cryptography, security
services (e.g. Kerberos), print services, and web
services. SWT offers an abstraction for platform
specific GUIs.
Operator overloadingfor most operators
The meaning of operators is generally immutable,
however the + and += operators have been overloaded
for Strings.
Full multiple inheritance, including virtual inheritance. Single inheritance only from classes, multiple frominterfaces.
Compile time Templates
Genericsare used to achieve an analogous effect to C+
+ templates, however they do not translate from source
code to byte code due to the use ofType Erasure by the
compiler.
Function pointers, function objects, lambdas (in C+
+0x) and interfaces
No function pointer mechanism. Instead idioms such as
Interfaces, Adapters and Listeners are extensively used.
No standard inline documentation mechanism. 3rd
party software (e.g. Doxygen) exists.Javadoc standard documentation
const keyword for defining immutable variables and
member functions that do not change the object.
final provides a limited version ofconst,
equivalent to type* const pointers for objects andplain const of primitive types only. No const
member functions, nor any equivalent to const type*
pointers.
Supports the goto statement. Supports labels with loops and statement blocks.
Source code can be written to be platform independent
(can be compiled forWindows,BSD,Linux, Mac OS
X, Solaris etc. without needing modification) and
written to take advantage of platform specific features.
Is typically compiled into native machine code.
Is compiled into byte code for theJVM. Is dependent
on the Java platform but the source code is typically
written not to be dependent on operating system
specific features.
C++ is a powerful language designed for system programming. The Java language was designed to be simpleand easy to learn with a powerful cross-platform library. The Javastandard library is considerably large for a
standard library. However, Java does not always provide full access to the features and performance of the
platform on which the software runs. The C++ standard libraries are simple and robust providing containers
and associative arrays.
Java as an Internet LanguageJava is an object oriented language and a very simple language. Because it has no space for
complexities. At the initial stages of its development it was called as OAK. OAK wasdesigned for handling set up boxes and devices. But later new features were added to itand it was renamed as Java. Java became a general purpose language that had manyfeatures to support it as the internet language. Few of the features that favors it to be an
internet language are:
Topic : Java Page 5Notes ByNAGESH KUMAR Contact No: 09928088743
http://en.wikipedia.org/wiki/XMLhttp://en.wikipedia.org/wiki/XSLThttp://en.wikipedia.org/wiki/MIDIhttp://en.wikipedia.org/wiki/LDAPhttp://en.wikipedia.org/wiki/LDAPhttp://en.wikipedia.org/wiki/Kerberos_(protocol)http://en.wikipedia.org/wiki/Operator_overloadinghttp://en.wikipedia.org/wiki/Operator_overloadinghttp://en.wikipedia.org/wiki/Generics_in_Javahttp://en.wikipedia.org/wiki/Generics_in_Javahttp://en.wikipedia.org/wiki/Type_erasurehttp://en.wikipedia.org/wiki/Doxygenhttp://en.wikipedia.org/wiki/Javadochttp://en.wikipedia.org/wiki/Windowshttp://en.wikipedia.org/wiki/BSDhttp://en.wikipedia.org/wiki/BSDhttp://en.wikipedia.org/wiki/Linuxhttp://en.wikipedia.org/wiki/Linuxhttp://en.wikipedia.org/wiki/Mac_OS_Xhttp://en.wikipedia.org/wiki/Mac_OS_Xhttp://en.wikipedia.org/wiki/Solaris_(operating_system)http://en.wikipedia.org/wiki/JVMhttp://en.wikipedia.org/wiki/JVMhttp://en.wikipedia.org/wiki/JVMhttp://en.wikipedia.org/wiki/Operating_systemhttp://en.wikipedia.org/wiki/Standard_libraryhttp://en.wikipedia.org/wiki/Standard_libraryhttp://en.wikipedia.org/wiki/Container_(data_structure)http://en.wikipedia.org/wiki/Associative_arrayshttp://en.wikipedia.org/wiki/XMLhttp://en.wikipedia.org/wiki/XSLThttp://en.wikipedia.org/wiki/MIDIhttp://en.wikipedia.org/wiki/LDAPhttp://en.wikipedia.org/wiki/Kerberos_(protocol)http://en.wikipedia.org/wiki/Operator_overloadinghttp://en.wikipedia.org/wiki/Generics_in_Javahttp://en.wikipedia.org/wiki/Type_erasurehttp://en.wikipedia.org/wiki/Doxygenhttp://en.wikipedia.org/wiki/Javadochttp://en.wikipedia.org/wiki/Windowshttp://en.wikipedia.org/wiki/BSDhttp://en.wikipedia.org/wiki/Linuxhttp://en.wikipedia.org/wiki/Mac_OS_Xhttp://en.wikipedia.org/wiki/Mac_OS_Xhttp://en.wikipedia.org/wiki/Solaris_(operating_system)http://en.wikipedia.org/wiki/JVMhttp://en.wikipedia.org/wiki/Operating_systemhttp://en.wikipedia.org/wiki/Standard_libraryhttp://en.wikipedia.org/wiki/Container_(data_structure)http://en.wikipedia.org/wiki/Associative_arrays8/7/2019 Java Remaining
6/6
Nimbus InfocomAura Of Excellence In Computer Education
7, Daan Bari
Jawahar Nagar
Kota (Rajasthan)Mobile No. : 09928088743
C, C++, DSA, VB, VB.Net, C#, ASP.Net, Java(Core & Adv), PHP+MySql, UNIX, LINUX, Oracle, PL/SQL, BCA, MCA, BTECH
Cross Platform Compatibility: The java source files (java files with .java extension) after
compilation generates the bytecode (the files with .class extension) which is further converted
into the machine code by the interpreter. The byte code once generated can execute on any
machine having a JVM. Every operating system has it's unique Java Virtual Machine (JVM) and
the Java Runtime Environment (JRE).
Support to Internet Protocols: Java has a rich variety of classes that abstracts the Internet
protocols like HTTP , FTP, IP, TCP-IP, SMTP, DNS etc .
Support to HTML: Most of the programming languages that are used for web application uses
the html pages as a view to interact with the user. Java programming language provide it's
support to html. For example. Recently the extension packagejipxhtml is developed in java to
parse and create the html 4.0 documents.
Support to Java Reflection APIs: To map the functionalities, Java Reflection APIs provides
the mechanism to retrieve the values from respective fields and accordingly creates the java
objects. These objects enables to invoke methods to achieve the desired functionality.
Support to XML parsing: Java has JAXP-APIs to read the xml data and create the xmldocument using different xml parsers like DOM and SAX. These APIs provides mechanism to
share data among different applications over the internet.
Support to Web Services : Java has a rich variety of APIs to use xml technology in diverse
applications that supports N-Tiered Enterprise applications over the internet. Features like JAXB
, JAXM, JAX-RPC , JAXR etc enables to implement web services in java applications. It makes
java a most suited internet language.
Support to java enabled Mobile devices: Java programming language is made in such a way
so that it is compatible with mobile devices also. Java language also works with any java
enabled mobile devices that support MIDP 1.0/2.0 including the symbian OS mobile devices.
Support to Personal Digital Assistants: Java language is compatible with Personal Java 1.1
such as chaiVM, Jeode, CrEME, and JV-Lite2 or with all the later version and it also support
PDAs like HP/Compaq, iPAQ, Fujitsu-Siemens Pocket Loox and SimPad, HHP, NEC, Samsung,
Sharp Electronics, Toshiba, psion m5, and any other device with Windows CE/Pocket PC
2002/2003/2005).
Topic : Java Page 6Notes ByNAGESH KUMAR Contact No: 09928088743