Difference Between Java SE and Java EE

Since the long time, Java developers have relied on both of these platforms to do the desired tasks through the language. Many newbie developers find it hard to understand the difference between Java SE and Java EE, and often end up considering them an entirely different programming languages… perhaps because they’ve learned a different language in the past which had no funny sounding distinctions within the language. If you’ve been reading my blog, then you know that I’ve been writing on Java, thus it makes sense to cover the commonly asked topic.

In this article, I will try to highlight the difference between Java SE and Java EE.

What is Java SE?

It is the name of the Java platform which provides the core tools.When Java was released, its first version was simply called “Java”, but when the 4th version was released in 1998, it was renamed as J2SE 1.2, wherein “J2” represents the Java 2, which then further replaced with Java SE as the previous name caused the confusion as to why J2SE had versions like 1.x, for instance, people assumed that J2SE 1.6 is an entirely different version. In Java SE, you are provided with the necessary tools to compile the Java programs with the help of different APIs, which is then run through the JVM (Java Virtual Machine). Apart from simple building tools, it also has GUI libraries / framework for building sophisticated GUI powered applications.

In the Java community, Java SE is also known as “Core Java” unofficially. According to the official site: “When most people think of the Java programming language, they think of the Java SE API. Java SE’s API provides the core functionality of the Java programming language. It defines everything from the basic types and objects of the Java programming language to high-level classes that are used for networking, security, database access, graphical user interface (GUI) development, and XML parsing.”. Its latest version is Java 8.

What is Java EE?

It is the super-set of Java SE, meaning it has all the features of Java EE. It is the Enterprise Edition, which basically means that it has all the features that are specifically added for the development of giant Enterprise applications. The cool thing about Java EE is that you do not need to compile your Java code to a stand-alone executable, as the platforms provide the built-in environment to compile / run the code without the need of a stand-alone executable. This results in extremely fast software development cycle. Java EE has a web framework based upon Servlets (i.e., a class used to extend the capabilities of servers). Apart from it, JSP (Java Server Pages) is provided which is a template language that compiles from JSP to a Java Servlets where it can be run by the container (the environment of Java EE). Other features include JPA, JDBC, etc.

Through Java EE, you can develop web server applications, although you need Java EE compatible servers like GlassFish, JBoss, WildFly, etc., so Java EE is more of a “platform” than simple tools. According to the official site: “The Java EE platform is built on top of the Java SE platform. The Java EE platform provides an API and runtime environment for developing and running large-scale, multi-tiered, scalable, reliable, and secure network applications.”

In Java SE, the applications that you write can run as stand-alone Java programs or as Applets. In Java EE, you can still run the program as stand-alone, but it provides the facility to run the program within the Java EE container.

…And what about Java ME and JavaFX?

Java ME was designed for applications which run on resource constrained devices (small scale devices) like cell phones, for example games.
JavaFX is a platform for building robust GUI applications. It is actually intended to replace Swing as the standard GUI library for Java SE, however, both will be included for the foreseeable future.

The 5 Best IDE for Java

When we learn a programming language, we are tempted to start wondering the tools (including the best IDE) we are going to use for writing the code. Some programmers download the text editors which provide enough satisfaction to them due to their simplicity plus often text editors are specifically designed for writing code, while the other newbie programmers download the IDE (Integrated Development Environment) which provides all the tools required for compiling the code for a single or many programming languages.

As Java is a language with huge libraries, it makes sense to write programs through an IDE. Several vendors in the past have provided many IDEs. Some of them became popular, others remain in the shadows. Following are the carefully selected IDEs that I think are one of the best, if not the best available for writing programs in Java:

1) Eclipse

Eclipse has been the part of the Java community for a very long-time, and it’s probably considered the most extensive IDE for Java. Thanks to its plugin system, you can easily integrate new functionalities with just a click. It also provides auto-update system, which notifies you when new updates are available. Though Eclipse, you can create applications for several platforms, including desktop, web, mobile and enterprise. Along with tools to compile / run Java code, it also supports various other features including the integration with Maven, a nice-looking XML editor, Git client, CVS client, and most importantly: Windows Builder.

Windows Builder supports designing the GUI through the different tools, which can help you in designing the powerful GUI for your software. It is essentially a SWT and Swing Designer. The cool thing about it is that you do not need to use it to compile the code, as the code that it generates can be compiled with normal Java libraries.

2) NetBeans

It is an open-source IDE for Java which is written in Java itself. It provides the development of Java SE, JavaFX, Java ME, web, EJB and mobile application out-of-the-box. Like Eclipse, it is modular in design and provide the plugins feature, you can extend the functionality easily through third-party plugins. Although, NetBeans was developed for building Java code, it now also supports C/C++, PHP, HTML, etc. natively, and any language can be added through plugin. Thus, this IDE is recommended for those Java developers who might want to learn other programming languages as well, so they won’t need to change the IDE (in case they love the IDE!).

3) IntelliJ IDEA Community Edition

This IDE was designed for Android app development, Scala, Groovy, Java SE and Java programming. It is extremely lightweight and provided only minimalist features, including JUnit testing, TestNG, debugging, code inspections, code completion, support for multiple refactoring. But, as it’s a Community edition, meaning you need to buy the full version to unlock the remaining features.

4) Enide Studio 2015

It is a tool suite which is available from the Eclipse plugin store and from the main website. It is a component of Nodeclipse which is a set of third-party developer solutions for Eclipse for programming in JavaScript, CoffeeScript with focus on Node.js. You can either install the plugin if you have Eclipse already installed, or you can download the Enide Studio directly from the website.

5) Android Studio

This is platform from Google which was originally designed to develop Android applications, however, it can be used for other programming languages as well. Before its arrival, Eclipse was considered a standard IDE for Android / Java development. With its arrival, it is now regarded as the best platform for Android / Java development due to the support from Google which updates its features regularly.

Conclusion

There is no such thing as the “best” IDE, as the choice depends on the needs of the user. For most, a simple text editor is enough, as they don’t need to code completion and other bloating features which slow down the development process.

Beginner Introduction to Java — the “Programming Language of 2015”

 In the last article, I have highlighted the TIOBE Index’s positions, where Java got the 1st position. Believing the importance of the aforementioned measure of the programming languages popularity and the fact that I promised the readers to focus more on the Java this year, I have decided to write an introductory tutorial on the Java programming language. The whole purpose of this tutorial is to have a friendly easy-to-read guide that can be later referenced by the experienced programmers to their friends who have recently started programming, so they would be reading this guide without resorting to a complex introduction.

Java was developed specifically for the object-oriented programming language. To enforce this paradigm, the Java developers made sure to not support any feature that usually resides in other programming paradigms (i.e., procedural, functional, etc.), thus discouraging the use of other programming styles. It was originally developed by James Gosling when he worked at Sun Microsystems (which is now owned by the Oracle Corporation). It was released as the core component of the Java platform. Before its release, C++ was very popular due its then recently introduced object-oriented features (i.e., classes, inheritance, etc.). Java was specifically designed for running on a virtual-machine, because the developers thought that the code written in it should be compatible to every platform and not just a specific platform where the code is originally written. In C++, when you compile a code, then the executable file can only be run in a particular format where it was compiled. Now, let’s talk about the Java Virtual Machine (JVM).

What is Java Virtual Machine? (JVM)

JVM is a virtual machine that was designed to run the Java bytecode — the instructions that are translated from the Java code by the Java compiler — in the platform where it is installed on the drive. The motivation for its construction is to support the cross-compatibility between different platforms (i.e., Windows, Linux, MacOS, etc.). The arrival of JVM made the language both a compiled language and an interpreted language, because: 1) The Java code (mostly written in .java format) is first “compiled” by the Java compiler into the Java bytecode (mostly written in .class format), then 2) The JVM interprets the bytecode (by translating it to the machine instructions of the platform) to run the program. Thus, this is a two-step process when you desire to compile / run a program written in Java.

Installing the Java Platform

Before getting your hands dirty, you need to first install the Java Platform (JDK + JRE) in order to compile / run the program written in Java.

Under Windows

 By following the instructions below, you would be able to install the Java platform on Windows:
  1. Go to the site to download Java SDK.
  2. Install the SDK once the download is completed.
  3. Go to the “Properties” of “Computer” or “My Computer”, then go to the “Environmental Variables” and then “Advanced System Settings”
  4. Edit the “Path” by adding the destination of the folder where the SDK is installed to the variable value (see the image below).
  5. Open the “cmd” and type “java” to test the installation.
downloading-the-sdk
Downloading the SDK
environmental-variable
Environmental Variables
testing-installation
Testing the installation through “cmd”

Under Linux

Most Linux distributions come with Java pre-installed, so you simply need to open the terminal of your distribution, and write “java” to test the installation. In case it isn’t installed, then you can install by running the following command:
Now, let’s write a “Hello world” program in Java.

Hello Java!

Ok, I cheated: We are going to write a “Hello Java!” program instead of the traditional “Hello World” program! In Java, we need to define a class in order to do anything. Following is the code of the Java program that simply prints “Hello Java!” to the console:

Here, I defined a (public) class “Main” which contains “main” method which has the code to print “Hello Java!”. This code should be saved in a file “Main.java”, because the name of the public class and the file name (excluding .java) should be same according to the syntax rules.Once you have saved the code in “Main.java”, then you need to open command line from the directory of the source file (or change the directory of your command line to the required directory) and then run the following command to compile the code:

Here, the “javac” is a tool to compile the source code. Once the source code is compiled, it creates a Java bytecode file (with .class format) which is called a class of its source file. To run the class file, you use “java” tool (note that I omitted the .class). This will print “Hello Java!” to the console screen:

Beyond Hello Java!

Now that you’ve learned the basic “Hello Java!” program, you can read the other tutorials to learn more about this awesome language! If you find it cumbersome to compile / run Java code through command-line, then you can use the IDE (Integrated Development Environment) for Java.

Summary

This article was an introductory tutorial on the Java programming language. Consider it a good start into the complex field of Java programming language where you need to learn / study at every stages!

If you have any question, then you can ask in the comments section below!

Java popularity rises to the top – Awarded “Programming Language of 2015” by TIOBE Index

Java programming language has been around since 20 years, when it first Beta version was released in 1995, which then followed by the official release of JDK 1.0 in 1996. Due to popularity of newly emerged languages (in its era) providing the similar features yet vast in feature-set — often fixing the bugs of old languages, programmers speculated long-ago that Java would lose its popularity and will soon be remembered by the people through the reading of history on programming languages. But, behold: the famous programming language popularity measure TIOBE programming community index has confirmed (through their findings of different programming languages searched by users on different search engines, such as, Google, Yahoo!, Wikipedia, etc.) that Java has risen to the top and beaten every programming language, including the languages of similar flavors (i.e., OOP languages like C#) and other languages (C, Python, PHP, etc.), proving that not only the language is less likely to die sooner, but provide enough applications for other purpose (web, desktop, etc.) due to its massive improvement in the feature-set… thanks to the recent release of JDK 8.0 (including its updates) in 2014-2015.

In January 2015, Java’s position was 2nd, but due to its rapid increase in the ratings within a year, it reached the 1st position, thus get awarded as “Programming Language of 2015”. TIOBE has a long history of awarding programming languages every year based on its rise in popularity with how much margin. As Java got a rapid rise in ratings, it makes perfect sense to call it “Programming Language of 2015”, thus enforcing the likelihood of a increase in its usage in the current year for different kinds of applications.

It would be intriguing for you to see C programming language at the 2nd position, which remained in the 1st position for the long-time despite the fact that there are countless other programming languages. The reason for C high popularity is due to the fact that it is still used as a beginning language in schools (thus students search it on search engines) and its use can be extensively found in developing other programming languages / libraries, including the programming in embedded systems and even the operating systems (i.e., Linux) that are written entirely in C.

What can we learn from it?

Even though, the TIOBE Index may have flaws in its measure of popularity of programming languages, it nevertheless shows the greater focus on the development of Java, its strong user-base and huge collection of libraries, which tell us to focus on it and learn more about it, which would probably help us in getting more jobs in programming. As our motto of this website is to make you happy (and smile!) when you do programming / coding, we will therefore focus extensively on Java tutorials from now on, assuring our readers that by visiting / reading our blog, they can have a good understanding / insight on the languages to make them capable to face every challenges in software niche.

Functions / Methods in Java and C#

When we hear a term “Function” our mind create the image of an option or technology in a program that do something, so when we use the function, a program does a particular job. A function is simply a combination of several tasks written beautifully within a single label through a proper organization rules. In programming languages, a function is used to hold several lines of code that does something, such as, adding the two integers together, displaying a text on a console screen, etc. Through the use of function, you can cut the multiple lines of codes and paste into a function with a name (i.e., a name through which you will remember it) and then call (use) it whenever you need the functionality in your program without duplicating the same code throughout the program, thus FUNCTIONS REDUCES THE SIZE OF THE CODE.

In OOP languages (i.e., C# or Java), a function is implemented as a static method, which means that you need to declare a class first in order to use it, unlike in non-OOP programming languages (like C) where a function exists by itself. In C# and Java, a function is a part of an object and is defined in a class and every executed instruction is performed in the context of a method. So, for example, when we call “System.out.prinln()” (in Java) or “Console.WriteLine()” (in C#), we are actually calling a function which simply creates a line to the console, thus a function is named as “method” in OOP.

In this tutorial, I will teach you how you can implement functions in C# and Java to make your programming life more joyful!

Static Methods

As I said earlier, In OOP languages, we define functions as static methods. They are those methods which doesn’t change the state of a class (thus they are named ‘static’). It make sense that functions are implemented as static methods, because in functions we are interested in executing some arbitrary and we are not interested in changing the object’s state.

The syntax for defining a static method in a class is same for both C# and Java. It is as follows:

Considering this syntax, we can very easily define our function. Let’s define a function for adding two numbers, we can do so as follows:

You can see that it’s trivial to define a function, but then the task that our function does is trivial as well. Let’s define another function for calculating factorial:

We can use our functions in a program as follows:

C#

Java

Static Classes

Static classes are those classes whose only one instance is available to a program. These classes don’t need to be instantiated. It is useful feature in those cases where you know that an instance of a class that doesn’t need to be passed to other classes, but can be easily used without instantiating. A static class is a class which can only contain static members, and therefore cannot be instantiated. One of its examples is “GameSettings” for storing different settings in our game. We can define such class as follows:

The following is the syntax for using static method in a class:

Now we can use our static class in a program as follows:

C#

Java

Note that you can not use non-static members in static methods.

Conclusion

As you can see, Static Class can be used as a convenient container for a sets of methods that only run on input parameters and doesn’t modify the state of an object. In the .NET Framework Class Library, the static System.Math class contains methods that perform mathematical operations like ‘cos’, ‘sin’ etc., without any requirement to store or retrieve data that is unique to a particular instance of the Math class, thus they don’t need instantiation to operate.

Functions are best suited for trivial tasks, especially when some task is duplicated several times in your program; hence you can simply create a static method in a class and call it whenever you need it. In which cases are you going to use functions?

Classes in Object Oriented Programming (C# and Java)

 In Object-Oriented Programming (OOP), there are two types of programming: class-based programming and prototype-based programming. Class is the most important concept in OOP, especially in class-based OOP (which is the dominant programming style in C#, Java, C++ etc.). It is a way to store properties and attributes of any object in a user-defined type, such as a car, dog, man etc. Think of it as a blueprint where you store all the information and then execute the operation according to the structure. In OOP, we manipulate different objects to perform something, which means that programming in OOP will force you to focus on data and not so much on logic and we are interested to know what the data holds. Basically, you would start with creating the structures first and the logic second.

We need an object or instance of class to manipulate itself and the other objects, which is created through a given class. You might have already heard of data encapsulation when talking about OOP. Class provides the support for data encapsulation by supporting various ways to hide data from a user, thus the user will be able to use only those features that you intended. The created instance (or object) not only holds a logic (code, procedures, etc.), but also a state, and thus can be manipulated by other objects.

In this tutorial, I will teach you the basics of Class in OOP using Java and C# as examples. Let’s get started!

Understanding the syntax

The syntax for declaring a class is same in both Java and C#.

As I mentioned earlier that a class is used to hold data, so it wouldn’t to create a class without a data!A class can hold members (i.e., variables) and methods (i.e., functions in a class that process the data). Following is the syntax to define variables/methods in a class:

Where:

  • access modifier = keywords that limits the access of a member/method, i.e., public, private and protected
  • return type = data type that is returned from a function
  • member name = any variable name

So for example, if we want to create a class for our object “Player”, we can do so as follows:

Here you can see that I defined properties and functions of player in our class “Player”. You can define as many members or methods you want, there is virtually no limit, though older computers will take much memory. Similarly, we can define other classes too:

Understanding public, private and protected

They are the access modifiers for telling a compiler whether it should allow any member/method of a class to be accessible within its class or in other classes too. ‘public’ makes a member/method available to other classes, while ‘private’ makes it available only within the class where it is declared. ‘protected’ makes it available within the class and derived class – which is a bit hard to explain, as it involves the concept of inheritance that I will teach you in later tutorials.

(Note: In C#, there is an another access modifier called “Internal” which limits the access of member/method to current assembly)

Creating an instance of a class

Recall that I said, you need to create an instance of a class in order to use it in your awesome program. The simple formula to create an instance of a class is as follows:

Using the formula, we can easily create an instance of a class in our program:

In our class, we could also declare “state” as protected because there is no inheritance involved in our program, so the results would be the same; that is, you wouldn’t be able to access “state” in your “Main” function.

Conclusion

You can now see how easy it is to use the feature of classes in your OOP programs. A class is arguably the best way to store data to easily manipulate various states in a program.

If you have any additional questions, then you can ask in the comments section below!

Static Keyword in Java

One of the commonly used keyword in Java is the static keyword, which is a non-access modifier that can be applied to a method, variable, class nested within another class and an initialization block. It is used to define a class as one whose object cannot be modified (or manipulated), or it can be used to declare a method in a class that can be only called (or provoked) within the class, or it can be used for variables (in a class) to make them static, which means the values of those variables won’t be changed.
Static keyword cannot be applied to a class that is not nested, constructor, interfaces, Method Local Inner Class (different than nested classes), Inner Class methods, Instance Variables and Local Variables.
When we attach static with the variable / method in a class, then it only belongs to the class. The static variable gets memory only once in the class area at the time of class loading. It is used to refer to the common property of a class that will be the same for every instance of the class. It is useful in situations where you want some variable or method to remain static so that it can’t be changed by any instance of the class.

Static variable / methods can be used without having any instance of the class. You can use the class directly to invoke a static method or static variable.

 
You can see that I didn’t create an instance of the class Person to use static variable age. Let’s study the static keyword rules!

Static Keyword Rules

As I mentioned earlier, static keyword can be applied to a variable, method, class nested within a class and an initialization block. Let’s see the meaning behind those words.
  • Methods that are marked static belong to the class rather than to any particular instance. 
  • Static method/variables can be used without creating any instance of the class. 
  • If there are instances, a static variable of a class will be shared by all instances of that class, which means that there will be only one copy no matter what.
  • A static method can’t access non-static variable, and it cannot directly invoke non-static method (But it can invoke/access method/variable via instances). This is the most important rule that should be kept in mind.

Incrementing the static counter

You can create a static variable (of int) and set it to 0. Since, it’s static in nature, it is initialized only for the first time. Now, whenever a method in a class increments the static variable, the count will change with increment, and the value would be the same in every instance of the class. This is powerful when you need to create some variables that shouldn’t be defaulted to zero every time you create new instances. For instance, let’s create a program that counts the number of instances of a class.


Converting Infix to Postfix in Java

When you enter a simple arithmetic operation, such as, “2+4”, you can see that there is “+” operator in between two integers. This operator is called binary operator, because it is between TWO data types.

Programming languages have a precedence rules for computing the operators. For instance, “*” operator is generally computed first to “+” operator, i.e., “2+4*5” will yield “22” as a result rather than “30”.

Note, however, there is an ambiguity when you try to understand the statement, as to whether the compiler will compute “*” operator earlier than “+” operator. To make it unambiguous, we often use brackets to emphasize which operator we want to be computed first.

In our example, “2+4*5”, you can see that we are using operators between digits. This is an infix expression, where you must use brackets to decrease ambiguity in your expressions. This is how we are accustomed to writing expressions in standard mathematical notation.

In a Postfix expression, a binary operator is applied to the two immediately preceding operands. A unary operator is applied to the one immediately preceding operand. “45*2-“.

Notice that the operands in a postfix expression occur in the same order as in the corresponding infix expression. Only the position of the operators is changed

Why the need to convert Infix to Postfix? 
Infix and Postfix (the third notation is Prefix which we won’t discuss in this guide) notations are two different but equivalent ways of writing expressions. The best thing about postfix is that the order in which
operators are applied is always unambiguous.

Implementation in Java

1) Implementing Stack Class (Optional)

Stack (LIFO) is a suitable holder for storing characters of given string of an expression, because it simply provides “push” and “pop” for adding the element to the top and retrieving the last element respectively. Stack is a sub-class of Vector (ArrayList in Java). It guarantees the rule of LIFO (Last In First Out), unlike Vector, which is quite flexible and where the elements can be added / retrieved between the list.

Even though, Java already provides Stack implementation in its standard library (java.util.Stack), it is useful to understand the implementation of Stack. This is optional, and you can use the standard class instead (more on that later).

2) Creating getOperator and getParenthesis Function
Since, we need to determine which character in a given string is an operator or a parenthesis, it would be better to create a separate function for them.

4) Creating IntToPost class
Now we will create a separate class that will take the input expression, and will have the method to convert it to Postfix expression.

3) Finishing
Now, let’s test our program to see if we implemented our program correctly.

Conclusion

In this tutorial, I have showed you how you can convert Infix to Postfix in Java programming language. This tutorial was supposed to be a beginner friendly guide with an emphasis on users trying to learn the core programming. If you have any question, then feel free to ask in the comments section below!