Wednesday 29 June 2016

Java Basics Syntax with an Example




Java Basics Syntax:-A java program is a collection of objects that communicate via invoking each other methods.


Java Program:-
public class First
{
public static void main(String []args )
{
System.out.println(“Welcome  You”);    //print Welcome You
}
}


Lets looks how to save the file, compile and run the program. Please follow some step which define below:- 
1.       Firstly, open notepad in your computer and add the code in notepad. 
2.       In second step to save the file as First.java  ( i.e First is file name which same as your class name define in program and save with .java extension) 
3.       Open your command prompt window and go to the directory where you save the file. 
4.       Type:- c:\> javac First.java and press enter. If it is not show any error in window, it compile successfully. 
5.       Type :- c:\>java First   and press enter to run your program. 
6.       It show an output, Welcome You in command prompt window.


In above Java program, Keep some following important points in your mind:- 
1.       Case Sensitivity:- Java is a case sensitive which means identifier First and first  would have different meaning in java. 
2.       Class Name:- According to conventional rule, first letter of class name should be in upper letter.
For  Example:-  class First 
3.       Method Names :- All method first rule should be in lower case and if you use several words in the name of method, then inner word first  letter should be in upper case. 
For Example:-  public void showPicture( ) 
4.       Program File Name:- Program file name should exactly the class name when you saving file with .java extension in your computer. 
For Example:- Assume that your class name is First, then your program file name should exactly First.java 
5.       Public static void main(String []args)  :- java program processing starts from main() method  which is mandatory  in your  java program.

Sunday 26 June 2016

Top 9 Basic Questions of Java


Questions 1:- Why java program is platform independent ? Why not C and C++  program ?
Answer:- When we compile c source data, it generate the “native code” which can be understood  by current operating System, if Move to this to other operating System. It cannot be understood because ” Native code representation is change from operating system to operating system”. So, C and C++ Program is not platform independent.
In case of java source code, compilation you will get “ byte code firstly instead of native code”. When you run the byte code, it will be converted to native code and then it will be executed. But native code generated from the byte code is temporary and will not be stored in any file. If you want to run the java program in other operating system, just move the byte code and run again. When you run your byte code will be converted to native code again and will be executed. So, Java Program  is platform independent.

Question 2:- What is JDK ?
Answer:-  JDK stands for Java Development Kit which contains tools to compile and run a java program.

Question 3:- What  is JVM ?
Answer:-JVM is java run time environment which provides the necessary supports to run over java program.



Question 4:- What is Java Compile ?
Answer:- Java Compiler is single non java program which is used to verify the programmatically mistake in the source code and also convert the source code to bytecode.

Question 5:- What is Interpreter ?
Answer:- Java interpreter is single non java program which is used to convert byte code to native code and also to execute native code. 

Question 6:- What is JIT compiler ?
Answer:- JIT is the part of the Java Virtual Machine (JVM) that is used to speed up the execution time. JIT compiles parts of the byte code that have similar functionality at the same time, and hence reduces the amount of time needed for compilation. Here the term “compiler” refers to a translator from the instruction set of a Java virtual machine (JVM) to the instruction set of a specific CPU.

Question 7:- Which of the following statements are true ?
1.     Java compiler is platform independent .                  (False)
2.     Java interpreter is platform dependent.                    (True)
3.     Java program is platform independent.                    (True)
4.     JVM is platform dependent.                                     (True)
5.     C program is platform independent.                         (False)
6.     JDK platform dependent.                                         (True)
7.     JIT compiler is platform dependent.                        (True)

Question 8:-  Why we have to set the path ?
Answer:-  We need to set the path for executable file to access anywhere with in the operating system drives and folder. Similarly with class path same.

Question 9:- Why we need to use % path %  in the path setting.
Answer:- This is to append the current path to the existing path. If we are not using %path % then existing path will be replaced with new path. Similarly class path same.

Path sets for bin folder where .exe files available.
Class path sets for lib folder where jar file available.




Saturday 25 June 2016

OOPs in Java

OOPs in Java:-
Following are the four basic object oriented principles:-
1. Abstraction
2. Encapsulation
3. Inheritance
4. Polymorphism

1. Abstraction:- The process of providing the necessary attributes and operations, then hiding unrelated attributes and relations are called abstractions.

Example:-  Take  an entity called T.V. Remote, to use that entity, the main required things  are how many buttons are there and what are their functionality, how many  volts batteries are used. There  are many basics things: therefore the end user to use. The remote have something like internal functionality –when pressed the remote button perform a tasked which is hide from end users.

2. Encapsulation:- Encapsulation the  process of defining all the properties and operation of an object in an entity.
In Java:
1. You can call the entity as class   2.Variables when you are writing in the class  are properties of an object  and Methods are operation an objects.
3.Variables defines in the class. It should be used  by method which define in the class

3. Inheritance:- The Process of defining the new entity by using  existing entities, attributes and operations is called inheritance.
In Java:- We can defines as Follows
1. The process  of writing a new class by usng existing class is called inheritance.
2. Existing class is called Superclass or Base class or Parents Class
3. A newly created class is called subclass or derived class or child class.

4.Polymorphism:- The operations behaving different in different situation is called the polymorphism.

In case of the remote entities, the button with red colour will be do two operations.
Switch on tv
Switch -off tv

Monday 20 June 2016

History of Java

 

1. Overview of Java

Java is one of the world's most important and widely used computer languages, and it has held this distinction for many years. Unlike some other computer languages whose influence has weared with passage of time, while Java's has grown.
As of 2015, Java is one of the most popular programming languages in use, particularly for client-server web applications, with a reported 9 million developers using and working on it.

2. Creation of Java 

Java was developed by James Ghosling, Patrick Naughton, Mike Sheridan at Sun Microsystems Inc. in 1991. It took 18 months to develop the first working version.
The initial name was Oak but it was renamed to Java in 1995 as OAK was a registered trademark of another Tech company.

3. Evolution of Java

Java was initially launched as Java 1.0 but soon after its initial release, Java 1.1 was launched. Java 1.1 redefined event handling, new library elements were added.
In Java 1.2 Swing and Collection framework was added and suspend(), resume() and stop() methods were deprecated from Thread class.
No major changes were made into Java 1.3 but the next release that was Java 1.4 contained several important changes. Keyword assert, chained exceptions and channel based I/O System was introduced.
Java 1.5 was called J2SE 5, it added following major new features :
  • Generics
  • Annotations
  • Autoboxing and autounboxing
  • Enumerations
  • For-each Loop
  • Varargs
  • Static Import
  • Formatted I/O
  • Concurrency utilities

Next major release was Java SE 7 which included many new changes, like :
  • Now String can be used to control Switch statement.
  • Multi Catch Exception
  • try-with-resource statement
  • Binary Integer Literals
  • Underscore in numeric literals, etc.
And the latest addition to the lot is, Java SE 8, it was released on March 18, 2014.

4. Application of Java

Java is widely used in every corner of world and of human life. Java is not only used in softwares but is also widely used in designing hardware controlling software components. There are more than 930 million JRE downloads each year and 3 billion mobile phones run java.
Following are some other usage of Java :
  1. Developing Desktop Applications
  2. Web Applications like Linkedin.com, Snapdeal.com etc
  3. Mobile Operating System like Android
  4. Embedded Systems
  5. Robotics and games etc.