Powered By Blogger

Monday 30 November 2015

DEVELOPERS INDEED(INTEL XDK)






Hi readers, I am extremely happy you are looking at this right now. From the header I can confidently ascertain that  you are either a software developer, programmer, coder, software engineer or what not. If you are none of those listed up there, you are probably a lover of technology.

My subject today is focused on the PRESTIGIOUS INTEL XDK. Well, I raised my eyebrows as to this new development. I as a growing software developer personally dislike writing codes with IDEs except in rare cases where the environment requires that I do. For example, developing Android applications requires that I use have eclipse installed with the neccesary plugins or that I do with an the Android sdk.Another instance is developing for Windows mobile, one needs the Visual Studio sdk (That's as far as I can go, not a fan anyway).

It bothers me when I see young developers like me (not me) writing Java, PHP, html, programs in Eclipse, InteliJ, Netbeans and every other SDK they can lay their hands on. However, I get booed when they find me do my thing on a text editor that gives me crazy stress.

WHY?
SDKs make you get through bugs as easily as possible, and also places a very large opaque and ridiculous wall just in-front of your eyes, restricting you from digesting vital informations. I personally code Java using a very beautiful text-editor (Sublime_Text). I like to do that because I tend to take note of specific details while I code and on the long run I can write as long as 50 lines of code to perform interesting tasks and then pop up my cmd.exe and launch my app with no errors. That was amazing.

So, here is my point, Keep calm and Code on. No shortcuts. It actually pays off. Use the XDKs if you have to, don't jus make them a lifestyle until you are well grounded.

Look at some examples:
James Goslin, creator of Java and Computer Science graduate. He probably never handled an IDE while designing and building Java. 

Linus Tovarld, creator of Linux O.S (2% of the whole thing tho). He did this without these tools we all clamour about.

I get your point, of course life gets better, easier and funner and I'm not saying don't use IDEs, Just set a standard. That's all.

Sorry about all these arrangements, I'm still an amatuer blogger or let's say, an hobbyist. Enjoy

Tuesday 28 July 2015

FRESH, INTERESTING AND AMAZING UPDATE IN JAVA 8

HI GUYS

It's been a minute, (a while). I've been pretty busy doing a few things you do not need to know. However, this write-up explains how to read from files. This is a new update on the Java8 jdk and it's really an amazing  development.

Java 8 has added a new method called lines() in Files class which can be used to read a file line by line in Java. The beauty of this method is that it reads all lines from a file as Stream of String, which is populated lazily as the stream is consumed. So, if you have a huge file and you only read first 100 lines then rest of the lines will not be loaded into memory, which results in better performance. This is slightly different than Files.readAllLines() method (which reads all lines into a List) because this method reads the file lazily, only when a terminal operation is called on Stream e.g. forEach(), count() etc. By using count() method you can actually count number of lines in files or number of empty lines by filtering empty lines. In fact, you can do a lot more than just reading content from file, you can filter them on some criterion e.g. filter lines which are not starting with a specific word, filter lines whose length is greater than 100, trim all lines to remove leading and trailing space, convert each lines into uppercase or lowercase etc. In short, you can use different methods from java.util.stream.Streams class to process lines read from file before printing them or returning them to caller. It's not just lambda expression, which is introduced in Java 8, there are many more goodies like this which are hidden behind aura of big features like lambdas and streams. You can read Java SE 8 for really impatient or Java 8 in Action to learn more about such hidden gems.

How to Read File line by line in Java 8

In this short example, I have discussed three ways to read a text file line by line in Java 1.8. My first example is about the classical approach of reading file line by line using BufferedReader. You can also use Scanner in place of BufferedReader if you are using Java 1.5 but you can see that its not smooth. You need to first create a FileReader to read file, which uses platform's default character encoding for converting bytes to character. Than, you need to wrap that inside BufferedReader to take advantage of in memory buffering and readLine() method of BufferedReader class. This method can be used to read file line by line, it returns null if there is no more lines to read. If you also want to count total number of lines or want to display line numbers along with each line, you can use a count variable as shown in our first example.  You can see, almost 9 to 10 lines of code is required to read a file line by line prior to Java 8.


There are couple of ways to read file line by line in Java 8 e.g. by using Files.readAllLines() method, which returns a List of String, which are nothing but lines from File. There are two overloaded version of this method, one which accepts a character encoding and other which uses UTF-8 charset. Only problem with this method is that its not lazy like the next method, I am going to show you guys, but it also has an inherent advantage, it ensures that file is closed when all bytes have been read or an I/O error, or other runtime exception is occurred. You can see this Java 8 tutorial to see this method in action.


Better way to read a text file line by line in Java 8 is by using Files.lines() method which take advantage of Stream API introduced in Java 8. This method is lazy and only reads lines when some terminal operation is performed on Stream e.g. when you call forEach() method to display lines from file or call count() method to calculate total number of lines form file. This method also comes in two overloaded version, one which accept a given character encoding and other which by default uses UTF-8 encoding to convert bytes to character from file. Only disadvantage of this method is that it doesn't ensure that file is closed once all lines are read. The returned stream by this method encapsulates a Reader and if you don't want to rely on operating system for disposing file handlers, you make sure to call this method inside try-catch, try-finally or try-with-resource block to ensure that close() method is called once stream operation is completed. I have not wrapped code inside try-with-resource statement to improve readability but that is must if you are doing it for production code.

HERE IS A CODE EXAMPLE.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;


/**
 * Java Program to demonstrate how to read a file line by line in Java 8
 * @author Javin Paul
 */
public class Java8FileReader {

    public static void main(String args[]) throws IOException {
        
        // reading a file line by line before Java 8
        FileReader fr = new FileReader("manifest.mf");
        BufferedReader bufr = new BufferedReader(fr);
        
        int count = 1;
        String line = bufr.readLine();
        System.out.println("Old way of reading file line by line in Java : ");
        while(line != null){
            System.out.println(count + " : " + line);
            line = bufr.readLine(); count++;
        }
        
        bufr.close();
        
        // reading file line by line in Java 8
        System.out.println("Reading file line by line using Files.lines() in Java 8");
        Files.lines(Paths.get("manifest.mf")).forEach(System.out::println);
        
        // You can do even better, you can read all lines
        // trim them and filter out all empty lines
        // before printing as shown in following example 
        System.out.println("Doing more things than just reading file using Java 8 Streams");
        Files.lines(new File("manifest.mf").toPath())
                .map(s -> s.trim())
                .filter(s -> !s.isEmpty())
                .forEach(System.out::println);
        
        // You can also filter line using String methods
        // e.g. print only lines which starts with "
        System.out.println("Printing lines which startswith );
        Files.lines(Paths.get("build.xml"))
                .map(s -> s.trim())
                .filter(s -> s.startsWith("))
                .forEach(System.out::println);
    }


}

Friday 16 January 2015

IF YOU WILL DIE TOMORROW

I had the habit of giving these excuses
1. I have a bad computer
2. My computer has no electricity backup
3. I was not able to get it done
4.I tried all I can....

In my heart I really want to be consented to, and I feel like, "DON'T YOU JUST GET???" I tried, I just could not make it up. I always experienced an heavy throat while this happened, that tears were almost coming out of my *butts >lol<.. This was because I was sure I did try a lot BUT not enough to get the work done. So, what's the point in trying so hard when eventually you could not get the Job done. I call that crap (I've been in several craps of such anyway).

There was this one thing I discovered one thing |LAZE|. That was it. Your spirit wants it but your body can't help you get it done. You need to begin to listen less to your body else you'll get nothing done.

REMEMBER:

The reason you're trying to get it done is because it's worth it, If it's worth a try, then it's worth getting done.