You are on page 1of 6

Nimbus Infocom

7, Daan Bari
Jawahar Nagar
Aura Of Excellence In Computer Education 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 be
run by using either web browser or with an applet viewer. There are two types of applets: Local
applets and Remote applets.

Local Applet
A LOCAL applet is the one which is stored on our computer system.when browser try to access
the applet, it is not necessary for our computer to be connected to The Internet.

Remote applets
Remote 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 applet
code 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 JVM


JDK (Java Development Kit)
Java Developer Kit contains tools needed to develop the Java programs, and JRE to run the
programs. The tools include compiler (javac.exe), Java application launcher (java.exe),
Appletviewer, etc…

Compiler converts java code into byte code. Java application launcher opens a JRE, loads the
class, and invokes its main method.

You need JDK, if at all you want to write your own programs, and to compile the m. For running
java 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.
JDK is mainly targeted for java development. I.e. You can create a Java file (with the help of
Java 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 not
contain 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

The Java 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), JRE needs to be installed on
the machine.

JVM (Java Virtual Machine)


As we all aware when we compile a Java file, output is not an 'exe' but it's a '.class' file. '.class'
file consists of Java byte codes which are understandable by JVM. Java Virtual Machine
interprets the byte code into the machine code depending upon the underlying operating
system and hardware combination. It is responsible for all the things like garbage collection,
array bounds checking, etc… JVM is platform dependent.

Topic : Java Page 1


Notes By NAGESH KUMAR Contact No: 09928088743
Nimbus Infocom
7, Daan Bari
Jawahar Nagar
Aura Of Excellence In Computer Education 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

The JVM is called "virtual" because it provides a machine interface that does not depend on the
underlying operating system and machine hardware architecture. This independence from
hardware 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
doesn’t mention how to implement the features, like how the garbage collection process works
is JVM dependent, Java spec doesn’t define any specific way to do this.

Getting User Input


In Java 1.0, the only way to perform console input was to use a byte stream, and older code
that 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 this
approach 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 and
maintain.
Java does not have a generalized console input method that parallels the standard C function
scanf( ) or C++ input operators.
In Java, console input is accomplished by reading from System.in. To obtain a character-based
stream that is attached to the console, you wrap System.in in a BufferedReader object, to
create a character stream. BuffereredReader supports a buffered input stream. Its most
commonly used constructor is shown here:

BufferedReader(Reader inputReader)

Here, inputReader is the stream that is linked to the instance of BufferedReader 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 to
System.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 console
through System.in.

Reading Characters
To read a character from a BufferedReader, use read( ). The version of read( ) that we will
be using is int read( ) throws IOException Each time that read( ) is called, it reads a character
from the input stream and returns it as an integer value. It returns –1 when the end of the
stream is encountered. As you can see, it can throw an IOException.
The following program demonstrates read( ) by reading characters from the console until the
user 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 2
Notes By NAGESH KUMAR Contact No: 09928088743
Nimbus Infocom
7, Daan Bari
Jawahar Nagar
Aura Of Excellence In Computer Education 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 characters
do
{
c = (char) br.read();
System.out.println(c);
} while(c != 'q');
}
}
Here is a sample run:
Enter characters, 'q' to quit.
123abcq
1
2
3
a
b
c
q
This output may look a little different from what you expected, because System.in is line
buffered, by default. This means that no input is actually passed to the program until you press
ENTER. 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 of readLine( ) that is a member of the
BufferedReader 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; the
program 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.in
BufferedReader 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 3


Notes By NAGESH KUMAR Contact No: 09928088743
Nimbus Infocom
7, Daan Bari
Jawahar Nagar
Aura Of Excellence In Computer Education 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 their heritage, 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-typed object-oriented programming, exception handling, scoped resource management, and
generic programming, in particular. It also added a standard library which includes generic containers
and algorithms.
• Java was created initially to support network computing. It relies on a virtual machine to be secure
and highly portable. 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
No backward compatibility with any previous
Compatible with C source code, except for a few
language. The syntax is however strongly influenced
corner cases.
by C/C++.
Write once run anywhere / everywhere (WORA /
Write once compile anywhere (WOCA)
WORE)
Allows procedural programming, object-oriented
Encourages an object oriented programming paradigm.
programming, and generic programming.
Call through the Java Native Interface and recently
Allows direct calls to native system libraries.
Java Native Access
Exposes low-level system facilities. Runs in a protected virtual machine.
Is reflective, allowing metaprogramming and dynamic
Only provides object types and type names.
code generation at runtime.
Has multiple binary compatibility standards Has a binary compatibility standard, allowing runtime
(commonly Microsoft and Itanium/GNU) check of correctness of libraries.
Optional automated bounds checking. (e.g. the at() Normally performs bounds checking. HotSpot can
method in vector and string containers) 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 limits and sizes of all primitive types on
Standardized types are available as typedefs all platforms.
(uint8_t, ..., uintptr_t).
Primitive and reference data types always passed by
Pointers, References, and pass by value are supported
value.
Explicit memory management, though third party Automatic garbage collection (can be triggered
frameworks exist to provide garbage collection. manually). Doesn't have the concept of Destructor and
Supports destructors. usage of finalize() is not recommended.
Supports only class and allocates them on the heap.
Supports class, struct, and union and can allocate them
Java SE 6 optimizes with escape analysis to allocate
on heap or stack
some objects on the stack.
Rigid type safety except for widening conversions.
Allows explicitly overriding types.
Autoboxing/Unboxing added in Java 1.5.
The C++ Standard Library has a much more limited The standard library has grown with each release. By
Topic : Java Page 4
Notes By NAGESH KUMAR Contact No: 09928088743
Nimbus Infocom
7, Daan Bari
Jawahar Nagar
Aura Of Excellence In Computer Education 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

version 1.6 the library included support for locales,


scope and functionality than the Java standard library logging, containers and iterators, algorithms, GUI
but includes: Language support, Diagnostics, General programming (but not using the system GUI), graphics,
Utilities, Strings, Locales, Containers, Algorithms, multi-threading, networking, platform security,
Iterators, Numerics, Input/Output and Standard C introspection, dynamic class loading, blocking and
Library. The Boost library offers much more non-blocking I/O, and provided interfaces or support
functionality including threads and network I/O. Users classes for XML, XSLT, MIDI, database connectivity,
must choose from a plethora of (mostly mutually naming services (e.g. LDAP), cryptography, security
incompatible) third-party libraries for GUI and other services (e.g. Kerberos), print services, and web
functionality. services. SWT offers an abstraction for platform
specific GUIs.
The meaning of operators is generally immutable,
Operator overloading for most operators however the + and += operators have been overloaded
for Strings.
Single inheritance only from classes, multiple from
Full multiple inheritance, including virtual inheritance.
interfaces.
Generics are used to achieve an analogous effect to C+
+ templates, however they do not translate from source
Compile time Templates
code to byte code due to the use of Type Erasure by the
compiler.
Function pointers, function objects, lambdas (in C+ No function pointer mechanism. Instead idioms such as
+0x) and interfaces Interfaces, Adapters and Listeners are extensively used.
No standard inline documentation mechanism. 3rd
Javadoc standard documentation
party software (e.g. Doxygen) exists.
final provides a limited version of const,
equivalent to type* const pointers for objects and
const keyword for defining immutable variables and
plain const of primitive types only. No const
member functions that do not change the object.
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
Is compiled into byte code for the JVM. Is dependent
(can be compiled for Windows, BSD, Linux, Mac OS
on the Java platform but the source code is typically
X, Solaris etc. without needing modification) and
written not to be dependent on operating system
written to take advantage of platform specific features.
specific features.
Is typically compiled into native machine code.

C++ is a powerful language designed for system programming. The Java language was designed to be simple
and easy to learn with a powerful cross-platform library. The Java standard 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 Language


Java 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 was
designed for handling set up boxes and devices. But later new features were added to it
and it was renamed as Java. Java became a general purpose language that had many
features to support it as the internet language. Few of the features that favors it to be an
internet language are:

Topic : Java Page 5


Notes By NAGESH KUMAR Contact No: 09928088743
Nimbus Infocom
7, Daan Bari
Jawahar Nagar
Aura Of Excellence In Computer Education 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 package jipxhtml 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 xml
document 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 6


Notes By NAGESH KUMAR Contact No: 09928088743

You might also like