Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Monday, 21 November 2016

First Java Program

 

Let 's create the hello java program:

class  HelloJava
{
public static void main(String args[])
{
System.out.println("Hello Java Java");
}
}

save it by HelloJava.java//you can save it other name but it is good

To Compile: javac  HelloJava.java

To Run: java  HelloJava

Output : Hello Java Java


👉: If you make a java class as a public class, you have to save it as the class name only, you cannot save it to other names than a class name.


For example:


public class  HelloJava

{
public static void main(String args[])
{
System.out.println("Hello Java Java");
}
}

you have to save it by HelloJava.java

To Compile: javac  HelloJava.java
To Run: java  HelloJava

Output : Hello Java Java


Understanding first java program

  • class keyword is used to declare a class in java.
  • public is an access modifier, it is visible to all. we will learn in later.
  • static is a keyword if we declare any method as static, it is known as a static method. it saves a memory.
  • void is the return type of the method, it means it doesn't return any value.
  • main represents the startup of the program.
  • String args[] it is used for command line argument.
  • System.out.println() is used print statement in java programs.




Steps to write, compile and run the program in java:

To see clear image, click on image

  • To write the program in java open notepad by start menu->All Programs->Accessories->notepad and write a java program.

java program

as displayed in the above diagram, write a java program in notepad and save it as HelloJava.java.

  • After writing and saving first java program, To compile and run this program you need to open command prompt go start menu->All Programs->Accessories->command prompt

How to run java from cmd


  • To compile and run java program you have to go current directory where you save java file i.e HelloJava.java (we saved this file in C:\java new) and then type javac HelloJava.java for compiling and then enter and then type java HelloJava for running java program.

There are some other ways, we can write a java program .

(1) We can change the sequence of modifiers in the main method.

  • static public void main(String args[])

For example:

class Simple

{
static public void main(String args[])
{
System.out.println("hello java");
}
}

output: hello java


(2) We can change subscript notation in java in the main method.

  • public static void main(String[] args)

For example:

class Simple
{
public static void main(String[] args)
{
System.out.println("how are you");
}
}

output: how are you


  • public static void main(String []args)


For example:

class Simple
{
public static void main(String []args)
{
System.out.println("I am good");
}
}

output: I am good


  • public static void main(String args[])


For example:

class Simple
{
public static void main(String args[])
{
System.out.println("Thank you");
}
}

output: Thank you

(3) We can use 3 ellipses(dots) in the main method.

  • public static void main(String...s)


For example:

class Simple
{
public static void main(String...s)
{
System.out.println("3 ellipses ...");
}
}

output: 3 ellipses ...


We can apply semicolon (;) at the end of a class in java program. It is optional.

For example:

class Simple

{
public static void main(String []args)
{
System.out.println("we can apply semicolon in java");
}
};

output: we can apply semicolon in java



There are some valid java main method which we can declare

  1. public static void main(String[] args)
  2. public static void main(String args[])
  3. public static void main(String args[])
  4. public static void main(String...s)
  5. static public void main(String []args)
  6. public static final void main(String []args)
  7. final public static final void main(String []args)
  8. final strictfp public static final void main(String []args)

There are some invalid java main method which we can't declare 

  1. static void main(String[] args)
  2. public void main(String[] args)
  3. public void static main(String[] args)
Share:

Friday, 18 November 2016

Java Path


The path is required to be set for using tools such as javac(for compiling java), java(for running java), javap, javah, jar, appletviewer, which are used in java programming language. Path is used to define where the system can find the executable(.exe) files e.g java.exe, javac.exe, It is a location of bin files(binary executable files). javac, java, javap, all these tools are available in bin folder so we set path upto bin folder.


There are 2 ways to set path in java:

  1. Temporary path.
  2. Permanent path.

(1)  How to set temporary path of JDK in windows

  • copy the path of jdk/bin directory after installing jdk e.g (C:Program Files\Java \jdk1.8.0_20\bin)
  • open command prompt 
  • and write command on command prompt set path=paste the path.
For example:

set path=C:Program Files\Java \jdk1.8.0_20\bin;


We can see in figure below:


Temporary path in java

(2) How to set permanent path of JDK in windows


Go to MyComputer icon and right click go to properties ->advanced system settings->environment variables->new tab on user variables->write path in variable name box->paste path of bin folder in variable value->ok->ok.


Setting permanent path in java
Permanent Path: (1)  Go to My Computer Properties

Setting permanent path in java
Permanent Path: (2) Go to Advanced system settings

Setting permanent path in java
Permanent Path: (3) Go to environment variables


Setting permanent path in java
Permanent Path: (4) click new button (User variables box)


Setting permanent path in java
Permanent Path: (5)  Type "path" word in variable name box and paste the path of bin folder in variable value box 
(6) Ok
(7) Ok



Java Source File declaration rules

A java file is a plain text file containing java source code and having '.java' extension. The '.java' extension means that the file is java source file. These java source file contains source code for class, interface, annotation, enumeration.

There are some rules associated with java source file
  • There can be only one public class per java source code file.
  • If there is a public class in java source file, the name of the file must match the name of the public class e.g public class First {   } must be in source code file name First.java, you can't try other name like one.java, this is wrong source file name if class is declared as public .
  • If the class is a part of package, the 'package' statement must be the first line in source code file, before any import statements that may be present.
  • If there are 'import' statements, they must go between the 'package' statements and class declaration. If there is not package statements, then the 'import' statement must be the first line in the source code file. If there are no 'package and import' statements in java source file then class must be the first line .
  • A file can have more than one non public class.
  • Files with non public classes can have a name that does not match any of the classes in the file.


src.zip file in java

src.zip file means java source file and these src(source) file contains all the '.java' files. you can extract src.zip file, If you want to see all '.java files or java source files'.
  • Go to C:\Program Files\Java\jdk1.8.0_20
  • Extract src.zip file

Share:

Thursday, 17 November 2016

jdk download

 

JDK(Java Development Kit)

Here we will learn how to write the first program of java. Before running the first program of java we have to install the java software (java development kit in short called JDK, latest version of jdk is 1.8).

Java development kit contains the software and tools needed to compile, debug and run applications that you have written using java. Java Development Kit has as its primary components a collection of programming tools, including javac, jar etc.


 Java development kit basically used to develop and execute a java program. JDK contains JRE and other development tools. Java development kit is the official development kit for the java programming language. It includes a documentation generator (Javadoc). It includes an interpreter/loader (java). Java development kit is also used to develop an applets applications. Without JDK you cannot run your java applications.

for executing any java program, you need to

  1. Download the JDK 1.5, 1.6, 1.7, 1.8 what you want but the latest version of JDK is 1.8.you can download JDK 1.8 from oracle websiteand then install the JDK on your Personal Computer or Laptop.
  2. set the path of JDK.
  3. create the java program.
  4. compile and run the java program.
jdk software download


Java IDE and Editors

Here many java's IDE (Integrated Development Environment) and text editors are available.

After downloading, installing and set the path of java, you can run your java program in different-2 IDE or text editors. Let's take a look

What is IDE?

An Integrated Development Environment (IDE) is a software application that provides the comprehensive program for software development. Typically an IDE contains code editor, a compiler or interpreter and the debugger that the developer accesses through a single graphical user interface (GUI).

An IDE is an all-in-one software which not only lets you edit or compile your code but also manages resources, provides deployments and lets you use debugging features for your whole project.

Notepad: Notepad is text editor which is provided by the Microsoft company. It is a simple text editor, We can edit or type our java program or code in notepad and then After saving our java source code in a specific folder or directory we can compile it and run it from the command prompt.

Notepad++: We can write java program in notepad++ also. Notepad++ is the very good text editor and it is quite light and notepad++ recognizes the syntax of about 40 programming languages like java, c, c++, html etc.

Eclipse: Eclipse is a very good and open-source IDE. It was made in java so it is cross-platform. Eclipse is not just for a java but it is also used for C++ and php languages. Eclipse IDE is available for Windows, Mac, Linux.

Netbeans: Netbeans is also a very good and open-source IDE. It has a built-in GUI builder for those you like R.A.D. Netbeans is a cross-platform IDE. Netbeans is available for Windows, Mac, and Linux operating systems.

JDeveloper: Jdeveloper is a free Integrated Development Environment (IDE) and it is released by oracle. It comes in 2 editions, a Studio edition which has a fully loaded tool set for creating a program in java and java edition. It is cross-platform.
Share:

Wednesday, 16 November 2016

Features of Java


There are many features of java.
Java Features
  • Simple
  • Object-oriented
  • Platform-Independent
  • Secured
  • Multi-threaded
  • Architecture Neutral
  • Compiled and Interpreted
  • High performance
  • Distributed
  • Dynamic
  • Robust
  • Portable 
  • Networked

  • Simple:  Java is very simple language because the syntax is based on c++ so easier for programmer learn it after c++. There are no explicit pointers in java which reduce the complexity of java language. There is automatic garbage collection in java which destroys all the unused or unreferenced objects automatically, which is performed by the JVM (Java Virtual Machine). Java has Rich set of API (Application Protocol Interface).


       The basic concept of oops is:
  • Object
  • Class
  • Polymorphism
  • Inheritance
  • Abstraction
  • Encapsulation

  • Platform-Independent: Java is platform-independent language because java program can be run on the different-2 operating system. Java code can be compiled by the compiler and converted into bytecode. this bytecode is platform independent.

  • Secured: Java is secure because there is no explicit pointer in java and second is java programs run in their own environment called jvm. Java is more secure language compare to other languages because in this language all code is covered in bytecode after compilation which is not readable by any person. 

  • Multi-threaded: Java supports multi-threaded concept so in java, we can easily handle multiple requests simultaneously.  

  • Architecture-neutral: Java is not tied to a specific machine or operating system architecture. Machine-independent i.e java is independent of hardware. Architectural neutral means the programs were written on one platform and can run on any other platform without having to rewrite and recompile the java program. In other words, it follows 'write once run anywhere' approach. Java programs are compiled into the byte-code format which does not depend on any machine architecture but can be easily translated into a specific machine by a Java virtual machine for that machine.

  • Compiled and Interpreted: Java supports cross-platform code through the use of code java bytecode, Bytecode can be interpreted on any platform by jvm. Java is both compiled and Interpreted.

  • High Performance: Bytecodes are highly optimized, JVM can execute them much faster. Java supports multi-threading concept because by using multi-threading you can handle multiple tasks at the same time or execute multiple tasks simultaneously which will improve the performance. 
 
  • Distributed: Java was designed with the distributed environment. Java can be transmitted, run over the internet.

  • Dynamic: Java programs carry with them a substantial amount of run-time type information that is used to verify and resolve accesses to objects at run-time. 

  • Robust: Robust simply means strong. Java uses strong memory management. Java encourages error-free programming by being strictly typed and performing run-time checks. There is automatic garbage collection in java which is performed by jvm.

  • Portable: Java is portable because of this byte-code, we may carry the java bytecode to any platform.

  • Networked: Java mainly designed for web-based applications. J2EE or JEE is used to developing web-based or networked based applications.

Read More:



Note: In above features, there are many concepts we will learn in later like garbage collection, oops, multi-threading etc.

Share:

Tuesday, 15 November 2016

History of Java

 

Java History

The history of java starts from Green Team.Green Team at Sun Microsystems, Java team members also known as "Green Team" and initiated a revolutionary task to develop a language for digital devices such as set-top boxes, televisions.etc.

Currently java is used in mobile devices, internet programming, games, enterprise applications, etc.
  • James Gosling, Mike Sheridan, and Patrick Naughton initiated the
    java language project in June 1991.

    James Gosling
    James Gosling
  • Originally designed for a small embedded system in electronics appliances like set-top boxes etc.
  • Firstly, it was called " Greentalk " by James Gosling.
  • After that, it was called Oak.
  • In 1995.Oak was renamed as " java".
  • Originally developed by James Gosling at Sun Microsystems (which now subsidiary of Oracle Corporation) and released in 1995.


There are 3 categories of java

  • J2SE or JSE (Java 2 Standard Edition or Java Standard Edition)
  • J2EE or JEE (Java 2 Enterprise Edition or Java Enterprise Edition)
  • J2ME or JME (Java 2 Micro Edition or Java Micro Edition)
J2SE or JSE

It is used for developing client side application.

J2EE or JEE

It is used for developing server side application.

J2ME or JME

It is used for developing a mobile application.

History of java versions

There are many java versions that have been released. The current version of java is java 8.

(1) JDK alpha and beta (1995)

(2) JDK 1.0 (23 January 1996)

JDK 1.0 version is called  "Oak" and It is released on 23 january, 1996.

(3) JDK 1.1 (19 February 1997)

JDK 1.1 is released on 19 February 1997. 

Features:
  • JDBC (Java Database Connectivity)
  • Inner Classes
  • RMI (Remote Method Invocation) 
  • Java Beans
  • Reflection (Introspection only)

(4) J2SE 1.2 (8 December 1998)

J2SE 1.2 code named "playground" and it is released on 8 December 1998. This version is mostly called java 2.

 Features: 
  • Collection framework
  • Just In Time(JIT) compiler
  • Policy tool
  • Java foundation classes
  • Java 2D class libraries 
  • Java String memory map for constants
  • Java plug-in 
  • Jar signer for signing Java Archive file (JAR)
  • Audio support in applets
  • Scrollable result set, BLOB, CLOB, user defined types, batch update in JDBC.

(5) J2SE 1.3 (8 May 2000)

J2SE 1.3 released on 8 May 2000 and code name "Kestrel".

Features:
  • Jar Indexing
  • Java Sound
  • A big list of enhancements in almost all the java area

(6) J2SE 1.4 (6 February, 2002)

J2SE 1.4 code name "Merlin" and It is released on 6 February, 2002. 

Features:
  • XML processing
  • Java print
  • JDBC 3.0
  • Logging API
  • Java Web start
  • Assertions
  • Chained Exceptions
  • Preferences API
  • Regular Expressions 
  • Image I/O API
  • IPv6 Support

(7) J2SE 5.0 (30 September, 2004)

J2SE 5.0 code name "Tiger" and It is released on 30 September 2004 .

Features: 
  • Generics
  • Autoboxing/Unboxing
  • Annotations
  • Enhanced For loop
  • Instrumentation
  • Type safe Enums
  • Varargs
  • Static Import

(8) JAVA SE 6 (11 December 2006)

JAVA SE 6 code name "Mustang" and It is released on 11 December 2006. 

Features:
  • Scripting language support
  • JDBC 4.0
  • java compiler API
  • Integrated Web Services
  • Pluggable  Annotations
  • Java GSS, Native PKI, LDAP support

(9) JAVA SE 7 (28 July 2011)

JAVA SE 7 code name "Dolphin" and It is released on 28 July 2011.

Features:
  • Multiple Exception Handling
  • Try with resource
  • String in switch statement
  • Support for Dynamic language
  • Binary literals underscore in literals

(10) JAVA SE 8 (18 March 2014)

Java SE 8 released on 18 March 2014.

Features:
  • Lambda expressions
  • Pipelines and streams
  • Date and time API
  • Default Method
  • Type Annotation, etc.

Note:  JDK(java development kit)
           J2SE(java 2 standard edition (old version))
           JAVA SE(java standard edition(new version)).

Share:

Monday, 14 November 2016

What is Java

 Java

Java is a high level, object-oriented, platform-independent, secure, dynamic, multithreaded programming language. Java is also a platform. Java programming language is used to develop different types of software applications. Java programming language is used as a software platform to run the java application.
Java Images

Java programming language is a very simple programming language and easy to understand and easy to use. Java programming language is very interesting language to learn.


Platform: A platform is a basic hardware(computer) and software(operating system) on which software applications can be run. Since Java has its own runtime environment(JRE) and API, It is called platform.




Where is java used?

According to the sun, 3 billion devices run java. There are many devices where java is currently used. these are 
  • A desktop application such as acrobat reader, media players, antivirus, etc.
  • Web applications such as irctc.co.in.
  • Scientific applications.
  • Game development.
  • Enterprise applications such as banking application, Insurance applications.
  • Mobile applications.
  • Embedded devices.
  • Robotics.
  • Smart card.


Types of java application

you can create different types of applications using java programming language.

(1) Desktop Application

It is also known as standalone application or window based application. An application that we need to install an application on every machine such as antivirus, media players, games etc. Abstract Window Toolkit(AWT), Swing and JavaFX technologies are used to create desktop applications or window based applications. AWT contains a number of pre-defined components such as menu, button, list. Swing provides certain advanced components such as a tree, tables, scroll panes, tabbed panel, and lists. JavaFX is a combination of graphics and media packages, provides 3D graphics features etc.

(2) Web Application

An application that executes on the server side and makes dynamic web pages, is called web application. We can create web applications using servlet, java server page(JSP), struts, spring technologies. Servlet, JSP, Struts based web applications are popular on various government projects. Many of government projects like healthcare, education, insurance and several other departments have their web applications built in java. Java is also used in eCommerce web applications using open-source eCommerce platform such as Broadleaf.


(3) Scientific Application

Java is also used in scientific applications. Java is the better choice of many software developers for writing application involving scientific calculation and mathematical operations, because java programming is very fast, secure, maintainable, portable language. 

(4) Enterprise Application

An application that is distributed in nature such as banking application. EJB technologies are used for this application.

(5) Mobile Application 

An application that is created for mobile devices. Java Micro Edition(J2ME or Java ME ) are used to create mobile applications. Micro edition is a cross-platform framework to build applications that run across all java supported devices like smartphones and features phones. Currently, Android is used for creating mobile applications.


(6) Embedded 

Java is used in embedded devices. Several devices such as blue-ray disk player, SIM cards, utility meters and televisions use embedded java technologies.

(7) Software tools

Java is used many useful software and development tools which are written and developed in java. e.g Netbeans IDE, Eclipse, IntelliJ Idea etc.

Here we discussed what is java, where we can use java, etc. Now we will learn in next chapter History of java, Features of java, How to download jdk(java), etc.

Share:

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate