Java Notes
Java Notes
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 name from Oak to Java.
Java Example
Let's have a quick look at Java programming example. A detailed description of Hello
Java example is available in next page.
Simple.java
1. class Simple{
2. public static void main(String args[]){
3. System.out.println("Hello Java");
4. }
5. }
Application
According to Sun, 3 billion devices run Java. There are many devices where Java is
currently used. Some of them are as follows:
1) Standalone Application
2) Web Application
An application that runs on the server side and creates a dynamic page is called a
web application. Currently, Servlet, JSP, Struts, Spring, Hibernate, JSF, etc.
technologies are used for creating web applications in Java.
3) Enterprise Application
4) Mobile Application
4) JavaFX
Prerequisite
To learn Java, you must have the basic knowledge of C/C++ programming language.
Audience
Our Java programming tutorial is designed to help beginners and professionals.
Features of Java
The primary objective of Java programming language creation was to make it
portable, simple and secure programming language. Apart from this, there are also
some excellent features which play an important role in the popularity of this
language. The features of Java are also known as Java buzzwords.
A list of the most important features of the Java language is given below.
1. Simple
2. Object-Oriented
3. Portable
4. Platform independent
5. Secured
6. Robust
7. Architecture neutral
8. Interpreted
9. High Performance
10. Multithreaded
11. Distributed
12. Dynami
Object-oriented
Java is an object-oriented programming language. Everything in Java is an object.
Object-oriented means we organize our software as a combination of different types
of objects that incorporate both data and behavior.
1. Object
2. Class
3. Inheritance
4. Polymorphism
5. Abstraction
6. Encapsulation
C++ vs Java
There are many differences and similarities between the C++ programming language
and Java. A list of top differences between C++ and Java are given below:
C++ Java
Comparison
Index
Mainly used C++ is mainly used for Java is mainly used for
for system programming. application programming. It is
widely used in Windows-based,
web-based, enterprise, and
mobile applications.
Design Goal C++ was designed for Java was designed and created
systems and applications as an interpreter for printing
programming. It was an systems but later extended as a
extension of the C support network computing. It
programming language. was designed to be easy to use
and accessible to a broader
audience.
Compiler and C++ uses compiler only. C+ Java uses both compiler and
Interpreter + is compiled and run using interpreter. Java source code is
the compiler which converts converted into bytecode at
source code into machine compilation time. The interpreter
code so, C++ is platform executes this bytecode at
dependent. runtime and produces output.
Java is interpreted that is why it
is platform-independent.
Call by Value C++ supports both call by Java supports call by value only.
and Call by value and call by reference. There is no call by reference in
reference java.
Structure and C++ supports structures and Java doesn't support structures
Union unions. and unions.
Thread C++ doesn't have built-in Java has built-in thread support.
Support support for threads. It relies
on third-party libraries for
thread support.
Polymorphism
If one task is performed in different ways, it is known as polymorphism. For example:
to convince the customer differently, to draw something, for example, shape,
triangle, rectangle, etc.
Another example can be to speak something; for example, a cat speaks meow, dog
barks woof, etc.
Abstraction
Hiding internal details and showing functionality is known as abstraction. For example
phone call, we don't know the internal processing.
Encapsulation
Binding (or wrapping) code and data together into a single unit are known as
encapsulation. For example, a capsule, it is wrapped with different medicines.
A java class is the example of encapsulation. Java bean is the fully encapsulated class
because all the data members are private here.
JAVA PROGRAMS:
1.
1. class FibonacciExample1{
2. public static void main(String args[])
3. {
4. int n1=0,n2=1,n3,i,count=10;
5. System.out.print(n1+" "+n2);//printing 0 and 1
6.
7. for(i=2;i<count;++i)//loop starts from 2 because 0 and 1 are already printed
8. {
9. n3=n1+n2;
10. System.out.print(" "+n3);
11. n1=n2;
12. n2=n3;
13. }
14.
15. }}
String :
String Buffering:
String Building :
Java Naming Conventions