Showing posts with label Naseem. Show all posts
Showing posts with label Naseem. Show all posts

Thursday, December 5, 2013

Issues with the JDK, Eclipse Galileo and PATH Environment variable

Problems with the JDK and Eclipse:
"JDK Not found...." & "JNI Error..."
I had quite a lot of trouble fixing my Java JDK and Eclipse Galileo IDE. Thing was that I was trying to reuse my old installation of Eclipse (which being portable does not require a setup/installation) with the old JDK 1.6.0 Setup, I had saved. My old eclipse started throwing up strange problems when I tried working on new projects in my old workspace, even though the previous projects and files were working fine with the IDE.
I decided on updating my Java which gave me a new JRE 1.7 which existed with JDK 1.6.0 (Creating more path related confusions). This created more hassles with my system when I tried installing a new version of Eclipse IDE Kepler. The IDE started throwing "JDK not found" errors and my command prompt (Yes, I'm still stuck with Windows 7. I will build a dual boot with Linux Mint, as soon as I get the download finished.) also did not respond to "java" or "java -version" commands. So, I figured out that my JDK has been screwed.
Ineffective Solution:Capture
I tried all the fixes available from altering the "eclipse.ini" configuration file shipped with eclipse to point to my JDK using "-vm %JAVA_HOME%"\bin\" and other similar combinations. Then the system started throwing JNI Error of a missing .dll file from the jre in the client folder. One way was to link to its path the location in the configuration file (Messy! Don't do that! Well, unless you know what you're doing).
Solution:
Uninstalled and Reinstalled Java (JDK 1.7). [My suggestion; You should try CCleaner after uninstalls to clean and fix Windows Registry.] Set the PATH environment variable from:Capture 2
Advanced System Settings (From My Computer Properties after Right Clicking) > System Properties (Dialog) > Advanced (Tab) > Environment Variables (Button) > System Variables (Window) > New/Edit (Button below the window depending whether "path" or "PATH" variable exists or not) > Adding the path/address to "%JAVA_HOME%\bin". Then you may need to restart the system.
Capture3  Capture4Capture5
I downloaded the download available from Oracle with the latest Netbeans IDE bundled together. [Link] (For the JDK only try this Link.)
Did You Know: There are different JDKs available to use. They have the same standard libraries but, they also have special libraries bundled with them to be compatible with the other vendor services and tools. The two giants IBM and Oracle, there are Open Source versions too, like the one from GNU and OpenJDK; Courtesy of Sun Microsystems, which had released the Source Code as open source sometime, back in 2006.
Conclusion: My JDK, Eclipse Kepler and NetBeans IDE works like magic.
Other known Reasons for similar JDK and Eclipse Problems are incompatible softwares, like using 64 Bit JDK or IDE on a 32 Bit System. Here is a small note on it:
Working: 32 Bit OS + 32 Bit JDK + 32 Bit Eclipse IDE
Working: 64 Bit OS + 32 Bit JDK + 32 Bit Eclipse IDE
Working: 64 Bit OS + 64 Bit JDK + 64 Bit Eclipse IDE

Monday, October 21, 2013

Bibliophilia: Asimov, Milton and More...


Been reading some real hard-copy books now a days after a long long time. The last hard-copy book I read out of my college curriculum was "Mysterious Mr.Quin" by Agatha Christie, a collection of mystery and crime themed short stories with a mystical twist. That was way back in '09, I believe. Since then I read a few e-books, but, nothing beats the smell and touch of printed paper. The feel of a book in my hands actually starts background thought processes, I feel, within me that gives me an immersive experience. Ideas, imagination and links with existing knowledge is formed. Meanwhile reading a digitized e-book version is an ersatz; It maintains an elusive detachment and requires greater concentration and effort to grasp the text. I'll blog in another post on my recently read e-books.

  

I picked up two books from an airport bookstore on my way back to Patna from Delhi. The first was an earlier read book, "33 Strategies of War" by Robert Greene; A very good book which assimilates and distills 33 strategies of war from history. Superfluous with facts and beautifully informative side-notes running parallel stories, from history, in depth with relation to references in the main text. I had read this book earlier when in High School. I had borrowed it for almost a year from my elder cousin brother and had to return it with a lot of text unread, not understood or, now, forgotten. This time, I am working through it slowly and memorizing the narrated stories and strategies for longer retention. (Thanks to a couple of memorization tricks and techniques I've mastered. Though, I'll not be
able to memorize the text verbatim.) 

 

The second book I bought was "The Rest of The Robots" by Isaac Asimov, the classic science-fiction writer. His works mostly have a robot theme with a socio-philosophical premise. It is a collection of short stories by Asimov. There was an offer going that time of 3 books for the price of 2 by the publishers Harper Collins, but, I did not find any other intriguing book by Asimov or any other author that would've made a set of three. (The other book with multiple copies was I,Robot by Asimov which I had seen as a movie starring Will Smith.) Hence, I settled for this one only. 

I, a few minutes ago, completed it's 1st set of stories from it's three groups; "The Coming of The Robots". Novel and decently humorous, I'll rate them. A lot of fancy science buzz-words have been sprinkled, as was common in those days (I'm talking about the 1940s, people!), which does not quite impress or affect me as was it's intention for readers then. Maybe due to my exposure and understanding of a lot of modern day science and science-fiction, makes it taste a little bland. Still, the stories do give an entertaining experience, considering the time they were written in, and ignoring my encyclopaedic knowledge of science-fiction.

This book that I bought also combines introductions by Isaac Asimov, himself, which explains the themes and premise he has structured his stories upon. He refers to Frankenstein and Faust to have primarily forced his thoughts and story themes to go in the direction they took. I am very much aware and know of both Frankenstein and Faust but, personally have not read any of these works (other than in cartoon and comic variants, especially in DC Comics). Faust is primarily a supernatural, moral and horror themed story while Frankenstein is based in horror and rudimentary science.

Personally, I found the short, "Victory Unintentional", quite amusing considering people of the characteristics and mindset of the Jovians (Dwellers of Jupiter) do exist. Go read the story if you want to know. Here's a link to the book on Amazon. (And, that is because some good products are Fulfilled Amazon; which means they personally package, send/receive in case of returns for free and is eligible for cash on delivery. Meanwhile, Flipkart still sucks. Good luck paying extra 
while you could've saved it for some other book.) 

 

I've also picked up John Milton's poem-book, "Paradise Lost", which makes it a difficult read. (But, thankfully not as difficult as "You're not a Gadget".) Old style poem-prose with Biblical theme and cast of characters, unknown to the modern eastern reader, would make it an instant turn-off. Though my knowledge of the myths, supernatural and religious materials is great enough to create sensory overloads, the book still is a slow read. The prime reason I'm reading this is due to its protagonist. The protagonist of the story is Satan and the entire Biblical chain of events and theology is narrated and shown from his perspective which makes for an interesting read. Plus, it has some really fancy texts. Take this for instance;


A mind not to be changed by place or time. The mind is its own place, and in itself Can make a Heaven of Hell, a Hell of Heaven.
Then there is one really strong rebellious dialogue worth thought;
Better to reign in Hell than serve Heaven.
But, what a great/foolish/masochistic decision, I'd say!! Reminds me of the concluding conversation between Dean Winchester and Castiel in Supernatural TV Series Season 5 Episode 22: Swan Song. (I'd recommend you to see the series from the start but, you can also gather enough emotion for this thought provoking reply by watching only seasons 2/3 to 5). Owning a hard copy of Paradise Lost does make it good for underlining texts. So, here's the link; (Be forewarned! I don't know which themes does it touch as I've not read it entirely yet. Just gotten my feet wet and this is a freaking long poem running 280 pages and was initially published as a set of 10 books back in the year 1667, and you thought Harry Potter was unnecessarily long?) Finally, I've been skimming the various models in the book, "The Decision Book" by Mikael Krogerus and Roman Tschappeler, another non-fictional semi-technical book. Got it from Amazon, hardcover and all at only Rs149!! (One, of the reasons for my new allegiance to Amazon India.) Good book but, not for everyone. So, watch out and make sure it's worth your cash. For (a confused, a million thoughts & ideas a moment - brainstorm afflicted guy) me, it was totally worth it. Learned and tried out the first Eisenhower Matrix.
Books Discussed:
  1. 33 Strategies of War by Robert Greene (Non-Fiction, History, Strategy)
  2. The Rest of The Robots by Isaac Asimov (Science-Fiction, Classic, Robots)
  3. Paradise Lost by John Milton (Long Poem, Classic, Biblical)
Books Mentioned:
  1. The Mysterious Mr.Quin by Agatha Christie (Mystery, Crime, Enigma/Paranormal)
  2. Frankenstein by Mary Shelly (Science-Fiction, Horror) - I must read later.
  3. Faust by Johann Wolfgang Von Goethe (Supernatural, Horror ??)- I must read later.
  4. The Decision Book by Mikael Krogerus and Roman Tschappeler (Non-Fiction, Meta-thinking, Life, Mind)

Thursday, July 18, 2013

Now, I "Git" it.



Recently, I picked up two of “The Pragmatic Programmers” books, “New Programmer’s Survival Manual” by Josh Carter and “The Developer’s Code” by Ka Wai Cheung, and started skimming through them. A lot of the ideas, suggestions and lessons there was an eye opener for me. Barely 30-40 pages into both texts I was astonished to see how many vital skills and knowledge goes untaught in colleges (especially here in India).  No wonder, we are a cheap labor market for the lowest intellectual level of IT industry, which is in self-delusion of working on the next big thing, while we only do menial labor of code maintenance or simple web-design and the world is rapidly switching to mobile/cloud computing and augmented-reality.

One tool that I came to learn of is the Version Control System. Such a system is used to carefully keep all source-files and dependencies intact over the development cycle of the project. It logs all changes and can be used to “rollback” to previous development stages or versions, if required. It can also be used to “fork” a repository (the project directory containing everything relating to your project) which is another word for copying/cloning your project repository for sensitive changes or features that may otherwise break your previous tested and working code. This way you can test new code and features on existing project without ever messing up your original source-code.

I started learning Git and it was pretty simple and easy to learn, for me at least, as I’ve dabbled with some Bash Terminals on Ubuntu (Linux) and command line terminals don’t intimidate me as much as they used to. I had my humble beginning from Microsoft Visual Studio with Visual Basic 6.0.  Microsoft Visual Studio with its RAD (Rapid Application Development) IDE may have been easy to learn swiftly with simple drag and drop interface, auto-completion and other features. Actually, now, after a few minutes of recalling, I can say that I had the fortunate opportunity of playing with QBASIC and C, in my early school days.

But, here is a note of caution: RAD is not for a true programmer. Visual Studio may have it’s advantages but when something breaks (I am not talking about Bugs), you’ll have to return to the drawing board. Beware! You’ll become complacent, delusional and xenophobic. Trust me. I’ve been there. It is best to learn your craft with the smallest of tools no matter how crude or cumbersome they may seem to you. Once, you’ve built a full fledged “personal” project with them, congratulations, you’ve graduated! From “Personal Project” I mean, a problem or idea that you found independent of books/exercises and implemented it after your fair share of research and development. Then you can switch to whichever tool you want to use and use them.

Another disadvantage of RAD and IDEs are that it’ll never show you the internal system level implementations. How your files are stored or the system/hardware specific dependencies used by your project unbeknownst to you and when you migrate your project or deploy it somewhere else or on the web….Oh boy what a ruckus!

RAD is useful for simple and quick development of applications and systems to test your idea/product and prototype business models linked with that product. They can then be hacked to improve and converted to independent architecture/platforms like Java etc later on (only when you know what’s under the hood). I personally have never witnessed high performance or high scalable systems built with MS Studio. No, sir, I have not. Look around everywhere. They are either built on Open Source and/or custom built.

Returning to Git. Git was developed by Linus Torvalds and his Open Source buddies. I wont detail these unnecessary information that can be wikied. But, I’d like to add that Git has the additional advantage of being distributed and multiuser. It may have other features but, I won’t get  into its details.

Now, people, Let’s get our hands dirty!

Setup::

First, we’ll need to install Git on our systems as only a lucky few of you all would be fortunate enough to have it pre-installed on your system. If you’re running a flavor of Linux you may have it installed somewhere in there. Whatever, here’s the link to it’s setup and official site:

Tutorial::

Now that you’ve got the link to the Official Site. I presume you’d prefer the official guides rather than mine, so I’ll skip the hard part of hand crafting a tutorial and directly link you to a tutorial that I found very useful (especially for the Terminal literate):


No need to be intimidated by this command line tool, it’s available in a GUI friendly version, too. Still, some of you might want to learn the Terminal first and then start using Git, if you’ve got no prior experience with Command Line Terminals. Take another pearl of wisdom, Try the Terminal available with Linux and/or Mac OS X, not Windows. The Windows Command Prompt was never meant to be used as a powerful tool as Windows was originally constructed for the technologically impaired ordinary gentry and many developer tools were scorned upon.
If you’ve returned to this page after getting “Git”. Thank you very much. You didn’t abandon me while I was ranting on and on. A comment or a token of appreciation would work wonders for my aching back that strained, against this uncomfortable sofa, in order to illuminate you with such good ideas.

You must now try GitHub. I’ll leave the requisite research on your dependable Google search skills.

Monday, July 15, 2013

Javadoc: The Bible of Your Java Source Code

Today I'll be sermonizing on Java, my dear readers. I have observed since I began learning Java in my third semester of Computer Science Engineering undergraduate course that comments are a vital part of a program or rather the source code. But, never were we taught about good commenting standards and commenting conventions. Also, our exposure to the Javadocs was minimal. Our only interaction with the Javadoc was when the IDE (Netbeans or Eclipse or any other) would produce a small popup window with a summary about the keyword over which our mouse pointer was hovering.

It fills me with sadness that such vital skills of reading, navigating, understanding and producing Javadocs was never taught or even appreciated. Like some unspoken truth, we all kept mum and so did our teachers, that we’ll eventually learn it “on the job” or “later in life”. I seriously doubt about the many Indian, so called, software professionals knowledge on how to comment code correctly and generate usable Javadocs or read other programmer’s Javadocs. Any Java programmer worth his salt must have this essential skill of playing around with the Javadocs.

There are various commenting styles in the art of programming each style has a certain aim in mind. Some of the commenting styles can be roughly categorized as:
  • Explanatory/Verbose Commenting – Used by experts, teachers and trainers to explain in detail what each line of the code does. It is generally regarded as “How?” themed commenting. It is also used when a complicated piece of algorithm is implemented which cannot be understood without certain explanatory aid. This style is generally picked up by students from their teachers, but, is not good for day to day professional use. Most of what any programmer will code in life will be simple and easy to understand without any comments. The best code is self-explanatory without necessitating a single line of code.
  • Reasoning/Terse Commenting – Used by professionals in day to day coding, it involves adding comments only when a certain part of the code is not self-explanatory and departs from the ordinary trend of coding. For example the forking of a certain thread to handle background tasks etc. It is generally regarded as “Why?” themed commenting. In other words it is a minimalist approach to commenting. You comment only when it is most required.
  • Documentation CommentingUsed to generate documents or guide other programmers using your source-code either as an API or a Legacy code. It may detail hardware and software dependencies, performance issues, code vulnerability (Yeah, you’ll find in some legacy codes useless warning comments such as, “//DON’T TOUCH THIS CODE! EVERYTHING WILL BREAK. TALK TO BOB BEFORE EDITING THIS CLASS”, where Bob is someone who has left the company 15 years ago. Good luck with that, mate.) This commenting style is best seen in Open Source APIs, where you can seek help from Open Source communities which may take a longer time to resolve your issues and even third party licenced APIs, though they provide a paid support service to resolve your issues in the least time possible.
Note: No adherence to a single style is requisite. Often, a mix of all styles will be required to deliver a useable and malleable source-code.

Javadocs, ahoy!!

 

Javadoc is a documentation generator from Oracle Corporation for generating API documentation in HTML format from Java source code. (Yes. This line is ripped off from Wikipedia. Now, please, don’t label me as a plagiarist.)

Javadoc handles only a specific format of commenting within the Java source codes. It can be either generated by using the pre-bundled javadoc tool with the JDK or invoking it via any Java compatible IDE (I’ll be sticking with Eclipse in this blog. Go to hell, Netbeans! *Just joking! I know how many of you still depend on it and I can empathize with you.*).

I’ve attached the source-code of a simple java program (which I did not care to test run even once. Don’t bother compiling and running it. Our focus should be on commenting for Javadoc.) with screen shots of generating and using the related Javadocs of this project. [The screen-shots are available here only, as my paid internet data usage quota has expired and I am currently blogging at the speed of 3~4 Kbps. I promise to update the bundled project with screen shots after I get my internet connection recharged which is looking doubtful considering I have already paid for the recharge and the confirmation SMS or transaction SMS has not yet been received since today morning 8 AM or so.]

Now, let’s see. Step 1:

Select the Element you want to comment on. Like in the above screen grab, I’ve selected method Circle from class FigureStore.

 

Step 2:

Select the Generate Element Comment option from the drop down menu of Source button from the main menu.



Step 3:

Eclipse auto-generates the comments depending on the selected element. As here the selected method Circle has two parameters, the Radius as X and the Diameter as Y.


Step 4:

Now, edit the element comment as required. Try adding details as briefly as possible.

Step 5:

After you’ve added all the element comments you need to generate the Javadoc. For generating the Javadoc for your project, select it in the package explorer and the choose Generate Javadoc from the Project option in the main menu.

Step 6:


Now, you’ll see a dialog as shown in the above image. Make sure your project is selected as well as all of its components. The Javadoc tool is selected via the Configure button. The Javadoc tool is present in the “bin” directory of the JDK. Also, set the path of your doclet to a new “doc” directory of your project.


Step 7:

You can add a specific document title to your doclet and you may add any referenced/dependent jars and packages which mainly comprise of the JDK libraries. Then select Finish. (Yes, I don’t go any further with that alluring “Next” button.)



Step 8:

Now, sit back and relax for a few moments while the Javadoc is being generated. The time take for Javadoc generation is dependent on the number of Elemental Comments, program size, structure etc. Your Console should show something like this:

 


Alternate Method:


Here’s an alternate method to generate Javadocs. Right click on your project in the Package Explorer. Select “Export” from the drop down menu and a dialog will appear as shown below.

Select Javadoc from the Java directory and Bam! It’s done (It’ll take you to the Javadoc Generaton Dialog). 

What to expect from Javadocs?

You’ll see a new directory under your Project in your Package Explorer called “doc”. Exanded it’ll look like this;

The “index” html file is the start or main page of your Javadoc. Double click on it to open it inside Eclipse. A sample Javadoc is shown below;

 



Also, now you’ll be able to invoke small popup help windows for your project/package which can be used in other projects as well if the Javadoc is imported in there Project directories.
 

IMPORTANT END NOTE:
A good habit is to keep on making Element Comments while programming in order to keep the burden of commenting low. Once the size of the source code gets out of hand commenting becomes difficult and you’ll not be able to leverage the Javadoc prompts for other parts of your source-code.

Also, one must always try to keep deprecated (i.e discontinued) methods in future iterations and newer versions of the program/package in order to maintain backward compatibility.”

Sample Documents and Source Codes::

My Experiments with JUNG 2.0 (Java Universal Network/Graph Framework)

My first minor project was a major disaster. But, in hindsight I can salvage out some simple nifty tools from the graveyard of codes on my laptop. I had to settle for a simple "Simpletron: A Simulated Microprocessor in Java." (I've blogged about it earlier here.) All it took was firing one of our three team members and the remaining duo pair-programmed into the night.....or at least for a few hours until he too quit and went away to see a movie. We ended up showing this little nifty tool and anther tool which Chitransh had designed to go together with this one. I then finally completed and perfected Simpletron on my own.

Nexus Grapher was a tool to be added to a data-mining project which we failed to complete due to broken team dynamics and interaction, as well as, pressing deadlines. I coded this small tool from Open Source, JUNG 2.0 API. That's "Java Universal Network/Graph Framework" Version 2.0.

This project had a lot of potential and planned features that were never realized. Nexus - as we named it, was supposed to be a suite of various data mining tools which can be used on a directory full of web-pages (preferably from Wikipedia & news-sites) and text files etc documents.

Initially we planned to adopt Stanford NLP Parser to perform NER tagging (Named Entity Recognition - This link is a Wikipedia page). This would produce a Penn-treebank structure which would be parsed by a method of my nexus-grapher to generate a visible, click able, interactive graph of inter-relating facts and texts from across the webpages and texts saved in the directory.

Selecting a node with the label of a named entity would invoke another method that I wrote with my team-mate Harshdeep Sokhey which will open a window displaying a consolidated text file with (that label) related texts collected from all over the mined directory. (Like a dynamically generated Wikipedia page).

But, this consolidation and compaction method was in it's nascent state without much intelligent features of context aware auto-data updates (on comparison with recent file save) and even basic features like text-redundancy. All it could do was get paragraphs and lines, consisting of the keywords, from all over the directory and order them by file creation date.

The connecting edges of the graph was also meant to be click able to pull up a consolidated file with paragraphs of texts where both these named entities would appear simultaneously. Another feature we failed to implement. I tried switching to Apache Lucene but due to approaching dead-line I didn't have enough time to learn Lucene.

Currently, the nexus-grapher reads from a CSV of preselected named entities to generate the graph.

If you want to know more of my plans for "Nexus: An interactive data-mining & visualization suite." send me an email. If you're able to implement such a suite, very well, do inform me.

Directions/Code Walk through::
--------------------------------

This small tool is built with open source JUNG 2.0. My knowledge and expertise with it is... limited. If you encounter any troubles and have questions relating the graph and its subsequent visualization, please contact them. Here's a tutorial of JUNG 2.0, as a PDF, which I found handy and it should be enough for the Java noob to get his feet wet.


Before I get into the details of my Java project, let's first go over the basics of my C.S.V formatting and rules for, what I call, "nexusft"; nexus-format-textfile.

The first token of the C.S.V is the available roots that can be searched and all other succeeding tokens are it's children.

Now, onto Java! The project package is split into three classes:

1) naseemgraphexp2.java
2) ReadFile.java
3) search.java

"naseemgraphexp2.java" is the core class with a Main  method to run a simple graph visualization. The code is self-explanatory with comments.

A name (search-token) is sought from the user when the program runs and calls the readnexus() method. The searched nexusft file address is passed as a parameter for the class ReadFile.

This ReadFile returns the arraylist of lines of texts in the nexusft file which is tokenized and searched against the entered keywords. Only the first token of the C.S.V (if matched) is considered the root and all others are considered children. Else the method returns an error message.

The constructor method "naseemgraphexp2()" is where my iterative loop adds the tokens as vertices and their names as labels. Only the searched central/root node of the graph is connected to its relatives.

The rest of the code in the Main method is self-explanatory and JUNG specific, to build a graph and visualize it. The geniuses behind JUNG kept very clean and clear examples for me to hack with my shoddy programming skills. I've left behind some original code of JUNG examples, which has been commented, I know it's bad practice (I read in one of them, Pragmatic Programmer/Publishers book), but, it is there for all those who are new to JUNG 2.0, to see and realize the available features I did not use.

"ReadFile.java" is a straight forward file reading program to read and add each line of text into a String[] array which is returned to the calling method in naseemgraphexp2.java.

Finally, in "search.java" is the small program to tokenize each string that we previously stored in our String[] array to be matched with our search token. If a match is found, then a true Boolean is returned to  nexusgraphexp2.java's method "readnexus()" which then proceeds to tokenize this string to create nodes for the graph.

I hope, you find it useful despite this poor hacking. If you polish it and go onto implementing better features do e-mail me and credit me for this shoddy hack.

Your,
Md.Naseem Ashraf
iam.legend.n@gmail.com

Source Available at:


https://docs.google.com/file/d/0B4e1TZA7mwrNVTYyTk9fOGVuT1E/edit?usp=sharing

Screen Shot:

 

 

 

Creative Commons License

This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States License.