Posts

Showing posts from January, 2017

Java , Java 8 and RxJava

Image
Hello programmers...!!!.Today we'll have our conversation on something "Advanced".You know Java.You know Java ...,5,6,7.But what on earth is Java 8 and RxJava. Java 8,as the name suggests,the 8th update of the super awesome Java language.The problem is RxJava...something new right??  Okay without further delay we'll discuss about the topic. As I already said Java 8 is the latest revolutionary release of Java. There are many useful and awesome new features included in Java 8 which make our life easier and less complicated. Following you can identify some of the main changes which have taken place in the latest release. Lamda Expressions(Oracle we don't need this.We have Python) Reapeating annotations Improvements in Collection class Performance improvement for HashMap Integration of Stream API to the Collections API New Stream API New Date/Time API Nashron new Javascript engine (Rhino to Nashron) Method references Default Methods Improved type Interfac...

Strings , I/O and formatting (Part-5 File I/O)

Image
Let's start coding on what we have learnt in the previous post. File f=new File("me.txt"); System.out.println(f.exists()); Here we created a File object and checked for the presence of the file using f.exists() method.If you don't have a me.txt inside the project folder this gives false as the output and if you do have  true as the output.Let's move on and create a new file. boolean a = f.createNewFile(); System.out.println(a+" "+f.exists()); Here we created a new file and check whether the process is successfully finished and the file is created.Note that createNewFile() creates a new file if it doesn't already exists.If the file exists you get false as the output from the above method. One thing to remember is that you have to put the file operation codes inside a try catch block as the operations declare checked exceptions.Alright...!!now we'll start writing text to files. File f=new File("me.txt"); FileWriter...

Strings , I/O and formatting (Part-4 StringBuffer and StringBuilder,File I/O)

Image
In the previous post we have discussed about some basic facts about StringBuffer and StringBuilder classes.At the end we have instantiated a StringBuffer object,applied some changes and logged the output and saw the differences between String and StringBuffer classes. Same rules apply to the StringBuilder class. StringBuilder a=new StringBuilder("hasitha"); a.append(" is a good boy"); System.out.println(a); Prints out " Hasitha is a good boy ".Now you are completely aware about how StringBuffer and StringBuilder classes behave when handling strings.Let's study some important methods in these classes.You have already have an idea about the append method.Note that append is a synchronized method for StringBuffer class.As in the previous post I am going to provide you the link for all the methods in StringBuffer and StringBuilder class.(Self study is the best....!!!!) StringBuffer https://docs.oracle.com/javase/7/docs/api/java/lang/StringB...

Strings , I/O and formatting (Part-3 StringBuffer and StringBuilder)

Image
I know you are an expert in Java string class now. But when handling an extremely dynamic environment which needs lots of modifications in a string and it's characters we need to use some additional techniques. StringBuffer and StringBuilder come to our help in these situations. As we discussed earlier strings are immutable objects.So when you change or modify string variables there is a tendency that you leave traces of used string objects in the memory which causes a memory overload or a memory leak.We can reduce this risk to a great extent using StringBuffer and StringBuilder in programming . A general use of StringBuffer and StringBuilder class is to handle File I/O .There you have to deal with some ever-changing and large streams which need a unique method of memory handling and memory management. StringBuffer and StringBuilder can handle this large amounts of characters as blocks,pass one block and reuse the used memory portion again without allocating a new space...

Strings , I/O and formatting (Part-2)

Image
Welcome to the second part of Strings,IO and formatting in Java.In the previous post we have discussed about some interesting facts in Java String class.In this post we'll further talk about string class.When we talk about programming languages,one of their key goal is to make the language more memory efficient and reliable.As strings are 16-bit unicode characters when an application grows it's very common for string literals to occupy large amounts of program's memory.So to address this issue JVM sets a special area of memory called " String constant pool ".When the compiler encounters a string it first check the string constant pool to check whether an identical string already exist for the string.If found it points out the string to the identical object without creating a new object.Sounds interesting right...!!!!So what's the difference between following two methods.Below you get a fine illustration on how string constant pool comes in handy in memory ma...