Sunday, June 3, 2018

What is Java?




Java was originally a programming language invented by Sun Microsystems, by James Gosling. Today Oracle owns Sun, and therefore Java too. Java is thus Oracle's trademark. Over time Java has evolved into more than just a language. It is a full platform with lots of standard APIs, open source APIs, tools, a big developer community with millions of developers etc. It may be a bit unclear what all this means, but you will get a better feeling for it when you start learning more about Java, and start working with it.
When people talk about Java they often refer to several different parts of the total concept. That is because Java is more than just a programming language. For a beginner, all these different "meanings" can be confusing, so I will explain them briefly so you know what people are talking about. The most commonly concepts associated with Java are
I will explain these Java parts briefly in the sections below.

Java Language

First and foremost Java is a programming language. This means that there exists a Java language specification that explicitly tells what elements are part of the Java language itself. What the Java language is capable of doing, in other words.
It is the Java language itself that this tutorial trail is focused on.
Java files are stored in files suffixed with .java . These files are then compiled into Java byte code using the Java compiler, and the byte code is then executed using the Java Virtual Machine (JVM). The Java compiler and the JVM are part of the Java Development Kit.

Java Bytecode

Java programs written in the Java language are compiled into Java bytecode which can be executed by the Java Virtual Machine.
The Java bytecode is stored in binary .class files.

Java Virtual Machine

Java is an interpreted language. What does that mean? Well, the Java language is compiled into Java bytecode. This Java bytecode is then executed by the Java Virtual Machine.
The Java Virtual Machine is like a computer. It can execute Java bytecode just like a PC can execute assembler instructions.
The Java Virtual Machine is implemented for several different operating systems, like Windows, Mac OS, Linux, IBM mainframes, Solaris etc. Thus, if your Java program can run on a Java Virtual Machine on Windows, it can normally also run on a Java Virtual Machine on Mac OS or Linux. Sometimes there are a OS specific issues that make your applications behave differently, but most of the time they behave very much alike. Sun referred to this as "Write once, run anywhere".
The Java Virtual Machine is a program itself. You start up the JVM and tell it what Java code to execute. This is typically done via a command line interface (CLI), like e.g. bash, or the command line interface in Windows. On the command line you tell the JVM what Java class (bytecode) to execute.

Java APIs

The Java language enables you to package components written in the Java language into APIs (Application Programming Interfaces) which can be used by others in their Java applications. Java comes bundled with a lot such components. These components are known as the standard Java APIs . These APIs enable your Java programs to access the local file system, the network and many other things.
The standard Java APIs provide a lot of basic functionality which you would otherwise have had to program yourself. Thus, the APIs help you develop your applications faster.
The standard Java APIs are available to all Java applications. The standard Java APIs come bundled with the Java Runtime Environment (JRE) or with the Java SDK which also includes a JRE.

Java Runtime Environment (JRE)

The Java Runtime Environment (JRE) is the Java Virtual Machine and the standard Java APIs coming with Java Standard Edition (JSE). The JRE contains enough to execute a Java application, but not to compile it.

Java Software Development Kit (Java SDK)

The Java Software Development Kit (Java SDK) is the JRE plus the Java compiler, and a set of other tools.
If you need to develop Java programs you need the full Java SDK. The JRE is not enough then. Only the full Java SDK contains the Java compiler which turns your .java source files into byte code .class files.
Additionally, some Java servers may need some of the tools in the JDK to e.g. compile JSPs (Java Server Pages) into Java byte code. In that case it is not enough to run the server with the JRE. You must use the full Java SDK so the server has the extra tools from the Java SDK available.

Java Code Conventions

The Java Code Conventions are a set of conventions for how to format your Java code, and how to name classes, variables, files etc. Most of the time you do not have to follow these conventions, but most developers follow most of them.

Java Standard Edition (JSE)

Java has evolved into three different sets of APIs, or "profiles" as some like to call them:
  1. The Java Standard Edition for desktop and standalone server applications.
  2. The Java Enterprise Edition for developing and executing Java components that run embedded in a Java server.
  3. The Java Micro Edition for developing and executing Java applications on mobile phones and embedded devices.
The Java Standard Edition contains the basic Java APIs for standalone desktop and command line applications. There is both a JRE and JDK for the Java Standard Edition.

Java Enterprise Edition (JEE)

The Java Enterprise Edition contains a lot of extra tools and APIs for executing Java components inside a Java Enterprise Server. Examples of enterprise Java components are:
  • Servlets
  • Java Server Pages (JSP)
  • Java Server Faces (JSF)
  • Enterprise Java Beans (EJB)
  • Two-phase commit transactions
  • Java Message Service message queue APIs (JMS)
  • etc.

Java Application Servers

The Java Enterprise Edition is only a specification. Software vendors like IBM, Oracle etc. are free to implement this specification. And they have. Their implementations are usually called Java Application Servers, because the servers are capable of running Java applications, while offering a lot of standardized services to these Java applications.

Java Micro Edition

The Java Micro Edition is a version of Java targeted at small and embedded devices like PDAs, mobile phones etc.
Today (2015) the most popular Java platform to develop on for mobile phones is Google's Android platform. Android does not use the Java Micro Edition, by the way. It uses its own subset of Java combined with a lot of Android specific components (APIs).

Java Applets

A Java Applet is a Java program that is downloaded and executed inside a web browser. Thus, Java Applets can be part of a web application.
When Java was first released, Applets were Java's main selling point. But these days Java Applets have pretty much died out (except for the popular game Minecraft). HTML5 and JavaScript has taken over as the favorite way to execute code in the browser.
Today most Java developers develop on the server side, on Java application servers, or other server side platforms like Vert.x or the Play framework.

JavaFX

JavaFX is a RIA (Rich Internet Application) framework. It is like Java Applets but with a lot more features, and with a completely different GUI API. JavaFX was inspired by Flex (Flash) and Silverlight for .NET (Microsoft).

Java Developer Community

The Java Developer Community consists of all the many Java developers out there which participate in the debate about Java and its future. The Java developer community has also developed a lot of open source APIs and products.

Saturday, June 2, 2018

C++ vs Java Index Page

C++ vs Java difference
















Comparison IndexC++Java
Platform-independentC++ is platform-dependent.Java is platform-independent.
Mainly used forC++ is mainly used for system programming.Java is mainly used for application programming. It is widely used in window, web-based, enterprise and mobile applications.
GotoC++ supports goto statement.Java doesn't support goto statement.
Multiple inheritanceC++ supports multiple inheritance.Java doesn't support multiple inheritance through class. It can be achieved by interfaces in java.
Operator OverloadingC++ supports operator overloading.Java doesn't support operator overloading.
PointersC++ supports pointers. You can write pointer program in C++.Java supports pointer internally. But you can't write the pointer program in java. It means java has restricted pointer support in java.
Compiler and InterpreterC++ uses compiler only.Java uses compiler and interpreter both.
Call by Value and Call by referenceC++ supports both call by value and call by reference.Java supports call by value only. There is no call by reference in java.
Structure and UnionC++ supports structures and unions.Java doesn't support structures and unions.
Thread SupportC++ doesn't have built-in support for threads. It relies on third-party libraries for thread support.Java has built-in thread support.
Documentation commentC++ doesn't support documentation comment.Java supports documentation comment (/** ... */) to create documentation for java source code.
Virtual KeywordC++ supports virtual keyword so that we can decide whether or not override a function.Java has no virtual keyword. We can override all non-static methods by default. In other words, non-static methods are virtual by default.
unsigned right shift >>>C++ doesn't support >>> operator.Java supports unsigned right shift >>> operator that fills zero at the top for the negative numbers. For positive numbers, it works same like >> operator.
Inheritance TreeC++ creates a new inheritance tree always.Java uses single inheritance tree always because all classes are the child of Object class in java. Object class is the root of inheritance tree in java.

Comparison of static keyword in C++ and Java

Static keyword is used for almost same purpose in both C++ and Java. There are some differences though. This post covers similarities and differences of static keyword in C++ and Java.
Static Data Members: Like C++, static data members in Java are class members and shared among all objects. For example, in the following Java program, static variable count is used to count the number of objects created.
class Test {
    static int count = 0;
    Test() {
       count++;
    }   
    public static void main(String arr[]) {
       Test t1 = new Test();
       Test t2 = new Test();
       System.out.println("Total " + count + " objects created");       
    }
}
Output:
Total 2 objects created
Static Member Methods: Like C++, methods declared as static are class members and have following restrictions:
1) They can only call other static methods. For example, the following program fails in compilation. fun() is non-static and it is called in static main()
class Main {
    public static void main(String args[]) {  
        System.out.println(fun());
    }
    int fun() {
        return 20;
    }
}
2) They must only access static data.


3) They cannot access this or super . For example, the following program fails in compilation.
class Base {
    static int x = 0;      
}  
class Derived extends Base
{
   public static void fun() {
       System.out.println(super.x); // Compiler Error: non-static variable
                                  // cannot be referenced from a static context
   }  
}
Like C++, static data members and static methods can be accessed without creating an object. They can be accessed using class name. For example, in the following program, static data member count and static method fun() are accessed without any object.
class Test {
    static int count = 0;
    public static void fun() {
       System.out.println("Static fun() called");
    }   
}  
      
class Main
{
    public static void main(String arr[]) {
       System.out.println("Test.count = " + Test.count);       
       Test.fun();
    }
}
Static Block: Unlike C++, Java supports a special block, called static block (also called static clause) which can be used for static initialization of a class. This code inside static block is executed only once.
Static Local Variables: Unlike C++, Java doesn’t support static local variables. For example, the following Java program fails in compilation.
class Test {
   public static void main(String args[]) {
     System.out.println(fun());
   }
   static int fun()  {
     static int x= 10; //Compiler Error: Static local variables are not allowed
     return x--;
   }
}





Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.