Monday 24 March 2014

Implementing your first Java program


Implementation of java program involve the following steps:-

  • Creating the program
  • Compiling the program
  • Run the program
  • Creating the program:-To create the java program your can use text editor(like Notepad in windows).Open your text editor which you are going to use and type the following code in that:-
  • class MN
    {
     public static void main(String arg[])
     {
      System.out.println("Hello and Welcome to java programming");
     }
    }

    Save the file with MN.java (MN should be the name of file as the class name is name is MN)Name as in this screen short
    • Explanation:- 
      • Class Declaration:-The first line
        class MN
        
        This line declares a class .It is the first step to object-oriented programming.We know that Java is Object Oriented Programming ,so everything is is inside the class (class Name is MN here ).The keyword class is used to declare a class.

      • Opening Brace:-the braces { } are used to group the class definition.
        class MN
        {
        
        }
        
      • Main line-The line
        public static void main(String args[])
        
        In this line main is a method ,like we have in C and C++ main().In every Java application there must be main()method .Because it is the starting point of program execution by the interpreter.A Java program have only one main() method.With main() method there are other keywords are used explanation of them are as following:-
        public The keyword public is a access specifier that declares the main method accessible to outer classes this is because the Java program execution is started by the Operating System so main method is accessible to the Operating system.
        static The keyword static declares the main() method as one that belog to the entire class not a part of the object of the class,main method is declared as static so that Java interpreter can use the main method before any object is created of that (here MN) class in which the main is written.
        void The type modifier void states that the main() method will not return any value to the Operating system
        String args[] This is a parameter that is passed to the main() method ,at this movement just remember that it will hold the values that we will pass to the program when we will run the program
      • Output Line-The line
        System.out.println("Hello and Welcome to java programming");
        
        This is Similer to the printf() statement in C and C<< in C++.Similarly in Java System.out.println() is available.Because Java is truly Object Oriented Programming Language. So in this statement System is a class ,out is static member of System class and println() is a method of member out.

Saturday 15 March 2014

Introduction to Java


Java is a general purpose object oriented programming language.We can develop two types of Java programs that are:-

  • Standalone applications
  • Web applets

  • Standalone applications:-Standalone applications are programs written in Java to carry out certain tasks on a standalone local Desktop Computer.The programs can be develop to do task on a local computer (like Calculator you use in your Operating System,Notepad can be developed in Java,Yahoo Facebook messenger etc).These Standalone application can do communication with the Internet also to do needful tasks. A good Example of Java standalone application is ThinkFree that is written in Java.It is just one example there are so many applications that are written in java and the advantage that these applications get is platform independent,means these are written once and can be run on any operating system that may be Windows,MAC,Linux etc.So the programs that we will develop in upcoming posts will be developed only once and without any change you will be able to run them on any operating system with any hardware lying below operating system.Developing a Java application involve following steps:-
    • Write The source-code in a file and store that with .java extension.
    • Compile the source-code file into byte code using javac compiler.(steps to install the JDK that has java compiler)
    • Execute the bytecode program using java Interpreter.

  • Web applets:-Java applets are small Java programs developed for internet applications .You may play online games that are mostly Java applets that run in your browser (downloaded through internet),you may notice some websites that have animations running and you interact with that animations that are all java applet programs that are written in Java.So we will see how to develop them in upcoming post.

Note:-These above types of programs types are developed using just J2SE that is Java 2 Standard Edition.Java has a wide range of other tools that are J2EE that are used to develop Enterprise applications.J2ME for mobile application development.

Tuesday 11 March 2014

How to install and configure java(JDK) environment to develop programs?


Before going to start installation of java(JDK) ,I will suggest you that please check your system configuration and match that ,would your system is fulfilling the minimum requirements required to run java.I am pasting the link of ORACLE website were the minimum and maximum requirements are  available,I am not writing them here because these requirements change time to time.So here is the link:-


Installation Guide and System requirements on Oracle website:-
http://docs.oracle.com/javase/7/docs/webnotes/install/

Windows Requirements:-
http://docs.oracle.com/javase/7/docs/webnotes/install/windows/windows-system-requirements.html


So if your system fulfill the  hardware and software requirements then you can go to following steps of installation:-


  1. Download the java(JDK) form the Oracle website as per your Operating system,link of Oracle website for JDK is :-http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html    .This link when pasted the JDK7 was latest one development kit.
  2. Here I am using Windows 64 bit OS machine so I am downloading the Windows x64.After downloading the JDK you will get one file with extension .EXE(because I am using Windows OS,you have to download as per your OS),so double click on this setup file:-

Thursday 6 March 2014

What is JDK?

JDK is a Java Development Kit ,that is a collection of tools that are used for developing and running Java Programs. JDK include the following:-

  • javac(java compiler)
  • appletviewer (used to view the applet programs)
  • javap(java disassembler)
  • javadoc(java HTML document creator)
  • javah(for C header file uses)
  • java(java interpreter)
  • jdb(java debugger)
Brief Description about the tools:-
  • javac:- java compiler is used to compile the java source code to bytecode(.class files are generated).It translate the java source code that is written by the programmer ,to bytecode that become input for the java interpreter. Syntax:-
                          javac <SourceFileName>.java
  • appletviewer:-It is used to run the applet programs and see the output of the applets ,it help to test that ,is the applet is running as per the internal coding or not.you do not need any browser to run the applet you can use the appletviewer tools to run applet.
                appletviewer <SourceFileName>.html
  • javap:-Java disassembler enables the programmer to convert the byte code files into a program description like package, protected, and public fields and methods of the classes
  • javadoc:-It create HTML formatted documentation form the java source code files.The developers use the comments ,doc tags and annotations in the programs which are the converted to HTML document for reference in future .
  • javah:-javah produces C header files and C source files from the java class files ,so that native method implementation can be done.
  • java:-java interpreter tools is used to  generate the machine code from the .class file,the end code generated by the java tool will be understandable by the machine hardware and output will be displayed to the user.
JDK tools used in java application development

Java Features



The main reason to develop a new language called Java ,was to offer solutions to those problems which are not possible to solve using existing languages(like using C ,C++),some of these problems were portability,reliability,distributional,compact etc.So there are some features of Java that make it popular in the market of general purpose stand-alone application development:-

  • Compiled and Interpreted Language:-We can search any language ,and it can be seen that a language it either compiled or interpreted.But Java is the combination of both,that is why Java is platform independent .Java code is first compiled (using compiler)and source code  is translated to byte code instructions .These byte code instructions are not machine independent,so they are interpreted (using interpreter) to machine code, that is directly executed by the machine ,on which java program is running.So java is both compiled and interpreted language.
  • Object Oriented Language:-Java is truly object oriented language ,in this everything is an Object ,everything is written the objects and classes(even main method is written in class that is not possible in C++ like language).Java has a extensive set of classes ,that are arranged in different packages.We can import (like we include in C++)them in our program and can use their functionality.
  • Platform Independent and Portable Language:-One of the reason Java is popular today is its feature of portability ,means Java programs can be moved from one computer to another computer any ware and any time , without any change in source code . Changes and up-gradations in the Operating Systems,in processors,in any other resources will not force any changes in the Java programs.That is why it is the first choice for software development.You may see the Applet programs running on your web browser when you open any website(advertisement or some popup) ,that are written in Java programming language ,and they are written only once ,when any person open the website that Applet programming run on the person's computer,what ever processor,operating systems he\she has.So java is platform independent and portable language.
  • Simple and Familiar Language :-Java code syntax has similarity with other languages like C ,C++.So the C++ developers can easy learn Java programming language and can start developing java programs.But there are some features which of C++ which are not supported by Java ,that are:-
    •  Pointer are not supported by Java.
    • Pre-processor  header files are not supported by Java.
    • goto statement is not supported by Java.
    • Operator overloading is  not supported by Java.multiple inheritance is not supported by java etc 
          So if your are a C++ developer and going to start with Java then you should keep in mind the                      difference in features and other thing which are not common in C++ and Java.

  • Robust and Secure Language:-Java is a robust language .It provide so many protection in code generation and execution to ensure the reliability.It has strict compile and run time checking of data types.Java has internal garbage collection mechanism that relieve the programmer from all memory management problems.Java has implementation to check all the exceptions and errors that may be risky while execution and it show all the errors and exception warning before execution.
               When it comes the point of secure language ,then it is clear cut answer is that Java does not have           pointer so the viruses and threats can not get access to the memory locations where data reside ,so              Java is a secure language.
  • Multitheaded Supported Language:-Java language support multithreaded  programming ,means you can create different threads for different tasks in your Java applications which will give better experience to end your in terms of faster results ,so your application will have better productivity ,if your will use Java mulithredded programming.But keep in mind that you should have complete knowledge about how to use multithreading  in your application.
  • Native method support:-Java support native methods means your can use the C++ written functions in Java programs ,this helps the programmers to use the already written code in the application development.
  • Ease of Development:-Java  has many features like Generics,Auto-boxing,Un-boxing,Annotations, Static import of packages etc ,these features reduce the overhead of the programmers and make the development easy.These also reduce the time of coding and application development can be go in next phase like testing phase .
  • Monitoring and Manageability APIs:-Java has a large no. of APIs one of them in JVM Monitoring and Management APIs  like JMX to monitor and manage Java applications.There are other tools like jconsole, jps,  jstats etc,these tools facilitate the management and monitoring tasks.