Learn Java to have Permanent Job or These 15 Languages

There are thousands of programming languages, but some are far more popular than others.

When a company goes out to find new programming talent, they're looking for people familiar with the languages and systems they already use - even as newer languages like Apple Swift or Google Go start to make a splash.

Here are the programming languages you should learn if you always want to have a job, as suggested by the popular TIOBE Index , the Redmonk Programming Language Rankings, and the annual Stack Overflow developer survey.

  1. Java
  2. C
  3. Python
  4. PHP
  5. Visual Basic
  6. Javascript
  7. R
  8. Go
  9. Ruby
  10. Groovy
  11. Objective-C
  12. Perl
  13. Pascal
  14. Delphi Object Pascal
  15. Swift
  16. MATLAB

Executing Shell Command From Java Program


Shell commands can be executed from within Java programs by using exec() method of Runtime class.

See example below:
try {
    Process process = Runtime.getRuntime().exec("your-command");
} catch (IOException e) {
    e.printStackTrace();
}

Output of the executed command can also be read as
Process proc = Runtime.getRuntime().exec("your-command");


BufferedReader stdInput = new BufferedReader(new

     InputStreamReader(proc.getInputStream()));


BufferedReader stdError = new BufferedReader(new

     InputStreamReader(proc.getErrorStream()));


System.out.println("Standard Output:\n");

String s = null;

while ((s = stdInput.readLine()) != null) {

    System.out.println(s);

}

System.out.println("Standard Error:\n");

while ((s = stdError.readLine()) != null) {

    System.out.println(s);

}

Private Methods In Interfaces In Java 9



Java SE 9 is nearing its release date. At this time we have a fair idea about new features in Java 9. One of the major enhancements is the introduction of Private Methods in Interfaces. Initially, it might be confusing to understand requirement of private methods in an Interface, but let's try to understand it step by step.

Pre Java 8 Era

In pre Java 8 era, Interfaces were only skeletons to define class structure. They were not allowed to have definition for any method.
public interface DBManager{

      String USER_NAME = "xyz";

      String PASSWORD = "*********";


      void save(Employee obj);

      void save(Department obj);

}
This created a situation, where, if we had single behavior for a method, we had to repeat same piece of code in each implementing class. This resulted in lot of redundant code. Another solution was, to use Abstract Class instead of an Interface. This approach had its own obvious problems.

Default Methods in Java 8

Java 8 solved this problem by allowing Interfaces to have default implementation for a method, these were called default methods. A default method had to be marked with default keyword. We can choose not to provide implementation of default methods in implementing Classes.
public interface DBManager{

      String USER_NAME = "xyz";

      String PASSWORD = "*********";


      default void save(Employee obj){

  //1. create connection

  //2. save object.

  //3. close connection

      }
  

      default void save(Department obj){

  //1. create connection

  //2. save object.

  //3. close connection

      }

}
This is a great solution to problems of Java 7 and earlier. But it came with its own drawback. What if we have multiple default methods and there is a code redundancy between these methods? Of course, we can extract the redundant code to a separate default method. But then that method becomes public and can be accessed directly by external classes, instead of being accessed through initial default methods.


Private Methods in Java 9

Private methods in Interfaces in Java 9, come as a required solution to problem of code redundancy in default methods in Java 8.
public interface DBManager{


      String USER_NAME = "xyz";

      String PASSWORD = "*********";


      default void save(Employee obj){

  saveToDb(obj, Employee.class);

      }


      default void save(Department obj){

  saveToDb(obj, Department.class);

      }


     private void saveToDb(Object obj, Class type){

  //1. create connection

  //2. save object with type.

  //3. close connection
     }


}


Now in Java 9, we can extract common code between default methods of an Interface into a private method. The Private Methods of an Interface are not accessible out side an Interface, neither are they inherited by implementing classes.

I hope I have been able to explain the feature and use of Private Methods in Interfaces in Java 9.

Please leave your feedback in comments below.


New Features of Java 9



Java 9 upgrade is almost ready. Early access builds are already out in the wild, with general availability expected in September 2017.

Today we have a very clear picture of what to expect from Java 9 release. If Java 8 was a major release of lambdas, streams and API changes, then Java 9 is all about modules, jshell, and a collection of under the hood and API updates.

Let take a quick look at some of the major features in Java 9.

1. Java 9 Module System

One of the big changes of Java 9 is the Module System. Oracle Corp is going to introduce their Jigsaw Project.

Project Jigsaw’s goal is to make Java modular and break the JRE to inter-operable components.

Modular source code is the first out of 4 steps towards Jigsaw and will not change the actual structure of the JRE and JDK. The purpose of this step is to reorganize the JDK source code into modules, enhance the build system to compile modules, and enforce module boundaries at build time.

Before Java SE 9 versions there is no notion of explicit dependencies between different parts (JAR files) of a system. Every public class can be accessed by any other public class on the classpath, leading to inadvertent usage of classes that weren't meant to be public API. Also, the classpath itself is problematic, how do you know if there are duplicate entries? The module system addresses both issues.

Modular JAR files contain an additional module descriptor. In module descriptor, `requires` statements expresses dependency on other modules. Additionally, `exports` statements control which packages are accessible to other modules, rest all are encapsulated in the module by default.
module MyModule {

  exports com.actigence.finance;

  requires employee;

}

2. Private Methods in Interface

Java 8 allowed Default and Static methods in an Interface. Now Java 9, allows definition of private methods, to avoid redundant code and allow more re-usability.
public interface Employee{

  private Long id(){

    // Method implementation goes here.

  }

  private static void hostedEvents(){

    // Method implementation goes here.

  }

}

3. Improved Process APIs

It has always been a pain to work with OS processes. Java 9 has added some new classes and methods to make it easy to manage and control OS processes.
System.out.println("Current Process Id: = " + ProcessHandle.current().getPid());

4. JShell - Java 9 REPL

REPL stands for Read Evaluate Print Loop. Many languages already feature an interactive Read-Eval-Print-Loop, and Java now joins this club. You can launch JShell from the console and directly start typing and executing Java code. JShell makes a good tool to explore APIs and try out language features.
G:\>jshell

|  Welcome to JShell -- Version 9-ea

|  For an introduction type: /help intro


jshell> int x = 10

x ==> 10


jshell> System.out.println("X value = " + x )

X value = 10

These are few of the Java 9  features that will change the way you code in Java.

Stay tuned for more Java 9 updates.

Please leave your feedback in comments section.


What are variables in SASS?

Sass Variables allow you to define a value once and use it in multiple places. Variables begin with dollar signs and are set like CSS properties. You can change the value of the variable in one place, and all instances where it is used will be updated.

When defining a variable we store in it a value, which often reoccur in the CSS like a palette color, a font stack or the whole specs for a cool box-shadow. Also, mostly the variables are defined at a fixed location, like top of the SASS file or in a dedicated separate file. This makes it easy to locate and change the values, instead of searching through the entire stylesheet.

Below you can see a simple example, where variables are used to define font, color and shadow.

SCSS file:
$title-font: normal 24px/1.5 'Open Sans', sans-serif;
$title-color: #F44336;
$box-shadow-bottom-only: 0 2px 1px 0 rgba(0, 0, 0, 0.2);

h1.title {
  font: $title-font;
  color: $title-color;
}

div.container {
  color: $title-color;
  background: #fff;
  width: 100%;
  box-shadow: $box-shadow-bottom-only;
}
Output CSS file after compilation
h1.title {
  font: normal 24px/1.5 "Open Sans", sans-serif;
  color: #F44336; 
}

div.container {
  color: #F44336;
  background: #fff;
  width: 100%;
  box-shadow: 0 2px 1px 0 rgba(0, 0, 0, 0.2);
}
SASS variables make it extremely easy to organize your stylesheet and make updates.

GrooveUI allows you to create multiple themes, by setting separate values of SASS variables for each theme. New themes can be created using GrooveUI website and values updated in real time.

Creating Dynamic CSS

While creating a SaaS (Software as a Service) software, a major goal is to allow users to have their own branding on the SaaS software. This specifically means, allowing the users to customize colors and images of the software.

Whenever faced with this problem, we start hunting for 'dynamic CSS'. We look for options where we can set values in our CSS stylesheets like colors and image at run-time. However, native CSS technology does not support setting values dynamically. So we come across pre-compilers like SASS and LESS. These pre-compilers support features like variables and rules, but again they do not allow you to change these values at run-time. These pre-compilers are mostly meant to improve organization of your stylesheets and make them easy to maintain.

A software that could allow us to set CSS values from database and reflect those changes in real time (of course without any website downtime or re-compilation) would be an ideal solution.

This is where GrooveUI comes to rescue. GrooveUI is a hosted service that allows you to create multiple themes and control them in real time. So basically you can create multiple themes for your website, specify different CSS values and changes take effect in real time. Also, all this without you having to make any changes to your website, after first setup.

How does GrooveUI work?

The developers of GrooveUI have done the heavy lifting for you, and created a service that allows you to store your CSS variables in database and use them to recreate stylessheets at run time, while taking care of performance issues.

GrooveUI uses industry approved SASS format for stylesheets. All you have to do is upload your SASS files to GrooveUI CDN (only SASS files, other files like HTML and JS are not required) and connect to GrooveUI CDN to access compiled CSS. That's it, now you can use GrooveUI website to create new themes and manage them individually.

You can access different themes by specify theme name in 'theme' parameter on your website URL or adding different domains or sub-domains to you GrooveUI account and configuring default theme for them.

GrooveUI gives you truly dynamic CSS and allows you to convert your SaaS software to while labelled offering in minutes.

What is GrooveUI?

GrooveUI is a web service that allows you to easily convert your website into a white labelled offering. GrooveUI allows you to create and apply new website themes in real time. You can manage stylesheet and images of you website on the fly. GrooveUI helps you to convert your SaaS (Software as a Service) software into a white labelled software in minutes.


GrooveUI is built over industry trusted SASS(Syntactically Awesome StyleSheets) stylesheets. You only have to upload your SASS files to GrooveUI CDN (not other files) and connect your website to retrieve compiled CSS files from GrooveUI CDN. GrooveUI extracts all the SASS variables from your files and gives you a nice UI to update their values. You can create multiple themes and specify different values for each SASS variable based on Theme.

Themes are accessed by specifying 'theme' parameter in your website URL. You can also configure multiple domains and sub-domain and set default theme for each of them. In that case, when you access your website from a configured domain, your website will be rendered using default theme.

GrooveUI helps you create truly dynamic CSS.

SASS with GrooveUI

SASS stands for Syntactically Awesome StyleSheets. Sass is a CSS pre-processor with syntax advancements. Style sheets created in SASS syntax are processed by the SASS compiler, and turned into regular CSS style sheets.
It allows you to easily manage complex CSS files by using variables, nested rules, mixins, inline imports, and more, all with a fully CSS-compatible syntax. Sass helps keep large stylesheets well-organized, and get small stylesheets up and running quickly, particularly with the help of the Compass style library.
One of the most powerful features of SASS is the use of variables. Example, instead of repeating the value of your sites primary color at multiple places, you could define a variable for primary color and then use that throughout your stylesheet. SASS compiler will replace the value of variable with actual value while generating CSS.
One feature which is left wanting, is the ability to dynamically update these variables, say from database values. This is where GrooveUI comes in to picture.
GrooveUI is an online service that allows you to set SASS variables dynamically. It allows you to have multiple active theme and access those themes through different domain or using URL parameters.
You only need to upload your SASS files to GrooveUI CDN and connect your website to GrooveUI CDN for retrieving the compiled CSS. That’s it. Now using GrooveUI website you can create new themes and define individual values for SASS variables. No changes are required on your website. You can control both CSS and Images.

Client based website branding




More than often we are faced with situation where we have to show our website in Client Branding.This may require showing different logo for each client, showing website in different color themes etc.

One simple solution is to run separate instances of our website for each Client. This easily becomes a maintenance nightmare if all the clients are share the same code base. Also, in a SaaS based platform this might not be possible or even economical.

Another solution is to use scripting techniques like Javascript or PHP to update our CSS code and image links at run time. Though this is feasible but it makes UI code dependent on server side teams which might not be very optimal. Also, it introduces a performance bottleneck.

A new tool that I have come across is GrooveUI. It's an online tool that allows the users to easily create multiple themes for a website and show same website in different themes based on URL from which a website is being accessed. No code changes are required for creating new themes.

One needs to connect to GrooveUI CDN to deliver there CSS and Image files. GrooveUI provides visual interface to add CSS files and Images, create new themes, change CSS attributes and Images.

Though GrooveUI is a paid service, but they offers a Free account that should be sufficient for smaller websites.

Visit there Documentation to get more information.

Microsoft Excel FV function in Java

FV, one of the financial functions, calculates the future value of an investment based on a constant interest rate. You can use FV with either periodic, constant payments, or a single lump sum payment.

Syntax
FV(rate,nper,pmt,[pv],[type])
The syntax has the following arguments:

Rate:- Required. The interest rate per period.
Nper:- Required. The total number of payment periods in an annuity.
Pmt:- Required. The payment made each period; it cannot change over the life of the annuity. Typically, pmt contains principal and interest but no other fees or taxes. If pmt is omitted, you must include the pv argument.
Pv:- Optional. The present value, or the lump-sum amount that a series of future payments is worth right now. If pv is omitted, it is assumed to be 0 (zero), and you must include the pmt argument.
Type:- Optional. The number 0 or 1 and indicates when payments are due. If type is omitted, it is assumed to be 0.
           0 - At the end of the period
           1 - At the beginning of the period

The Java equivalent function is:


static public double fv(double r, int nper, double pmt, double pv, int type) {        double fv = -(pv * Math.pow(1 + r, nper) + pmt * (1 + r * type) * (Math.pow(1 + r, nper) - 1) / r);        return fv;    }

A high precision version using BigDecimal will be:


static public BigDecimal fv(BigDecimal intRate, int nper, BigDecimal pmt, BigDecimal pv, int type) {        BigDecimal fvPositive = (pv.multiply((ONE.add(intRate)).pow(nper)))                .add(pmt                        .multiply(ONE.add(intRate.multiply(BigDecimal.valueOf(type))))                        .multiply(((ONE.add(intRate)).pow(nper)).subtract(ONE))                        .divide(intRate, DECIMAL_SCALE, DECIMAL_ROUNDING_MODE)                );        return fvPositive.negate();    }

Full source code can be found at: ExcelFunctions.java

Mircrosoft Excel PPMT function in Java

Basic Description

The Excel PPMT function calculates the payment on the principal, during a specific period of a loan or investment that is paid in constant periodic payments, with a constant interest rate.

The syntax of the function is:
PPMT( rate, per, nper, pv, [fv], [type] )
Where the arguments are as follows:

rate - The interest rate, per period.
per - The period for which the payment on the principal is to be calculated (must be an integer between 1 and nper).
nper - The number of periods over which the loan or investment is to be paid.
pv - The present value of the loan / investment.
[fv] - An optional argument that specifies the future value of the loan / investment, at the end of nper payments. If omitted, [fv] takes on the default value of 0.
[type] - An optional argument that specifies whether the payment is made at the start or the end of the period.
             The [type] argument can have the value 0 or 1, meaning:
                   0   -   The payment is made at the end of the period;
                   1   -   The payment is made at the start of the period.
             If the [type] argument is omitted, it takes on the default value of 0 (denoting payments made at the end of the period).

The function can be represented in Java as:


static public double ppmt(double r, int per, int nper, double pv, double fv, int type) {        return pmt(r, nper, pv, fv, type) - ipmt(r, per, nper, pv, fv, type);    }

Full source code can be found at: ExcelFunctions.java

Microsoft Excel IPMT function in Java

Basic Description

The Excel IPMT function calculates the interest payment, during a specific period of a loan or investment that is paid in constant periodic payments, with a constant interest rate.

The syntax of the function is:
IPMT( rate, per, nper, pv, [fv], [type] )
Where the arguments are as follows:

rate - The interest rate, per period.
per - The period for which the interest payment is to be calculated (must be an integer between 1 and nper).
nper - The number of periods over which the loan or investment is to be paid.
pv - The present value of the loan / investment.
[fv] - An optional argument that specifies the future value of the loan / investment, at the end of nper payments. If omitted, [fv] takes on the default value of 0.
[type] - An optional argument that defines whether the payment is made at the start or the end of the period.
            The [type] argument can have the value 0 or 1, meaning:
            0 - The payment is made at the end of the period;
            1 - The payment is made at the start of the period.

            If the [type] argument is omitted, it takes on the default value of 0 (denoting payments made at the end of the period).

In Java this can be represented with following function:


static public double ipmt(double r, int per, int nper, double pv, double fv, int type) {        double ipmt = fv(r, per - 1, pmt(r, nper, pv, fv, type), pv, type) * r;        if (type == 1) ipmt /= (1 + r);        return ipmt;    }

A high precision function using BigDecimal is:


static public BigDecimal ipmt(BigDecimal intRate, int per, int nper, BigDecimal pv, BigDecimal fv, int type) {        BigDecimal ipmt = fv(intRate, per - 1, pmt(intRate, nper, pv, fv, type), pv, type).multiply(intRate);        if (type == 1) {            ipmt = ipmt.divide(BigDecimal.ONE.add(intRate), DECIMAL_SCALE, DECIMAL_ROUNDING_MODE);        }        return ipmt;    }

Full source code can be found at: ExcelFunctions.java

Microsoft Excel PMT function in Java

PMT, one of the financial functions, calculates the payment for a loan based on constant payments and a constant interest rate.

Syntax:
PMT(rate, nper, pv, [fv], [type])


The PMT function syntax has the following arguments:
  • Rate:- Required. The interest rate for the loan.
  • Nper:- Required. The total number of payments for the loan.
  • Pv:- Required. The present value, or the total amount that a series of future payments is worth now; also known as the principal.
  • Fv:- Optional. The future value, or a cash balance you want to attain after the last payment is made. If fv is omitted, it is assumed to be 0 (zero), that is, the future value of a loan is 0.
  • Type:- Optional. The number 0 (zero) or 1 and indicates when payments are due.

This can be represented in Java function as:

static public double pmt(double r, int nper, double pv, double fv, int type) {        double pmt = -r * (pv * Math.pow(1 + r, nper) + fv) / ((1 + r * type) * (Math.pow(1 + r, nper) - 1));        return pmt;    }


A high precision implementation using BigDecimal values is given as:

static public BigDecimal pmt(BigDecimal intRate, int nper, BigDecimal pv, BigDecimal fv, int type) {        BigDecimal numerator = intRate.multiply(((pv.multiply(ONE.add(intRate).pow(nper))).add(fv)));        BigDecimal denominator = (ONE.add(intRate.multiply(BigDecimal.valueOf(type)))).multiply(((ONE.add(intRate)).pow(nper)).subtract(ONE));        return numerator.divide(denominator, DECIMAL_SCALE, DECIMAL_ROUNDING_MODE).negate();    }

Source code can be found at: ExcelFunctions.java