Latest Entries »

Java constructors

We created a rather peculiar variable obj in our last tutorial(The infamous”hello world”).
Greetings obj = new Greetings();
Lets break it down.
Greetings obj- its is just a variable declaration.Its like declaring any other variable.
This variable is called an instance variable(we,ll talk about that in the post about variables..here just let it be.)
For example int x;
But in this case the variable is of type Greetings.FYI classes in java are like data types so it is valid to make arrays and variable of a class type.
new Greetings(); is creation of a new object. new is a java keyword,used to create memory space for objects.
Constructors are used to initialize all the class variables.So, you don’t output a null variable or operate a null variable(this is one of the reasonable reason ,they exist).
Greetings() is the constructor of the class Greetings.When an new keyword is found by the java compiler it immediately allocates space for it in the memory and calls the constructor to the object.
Constructor is a method that has the same name as the class.It does not return.
For eg-int Greetings() is not a valid constructor declaration.The correct one is Greetings(){};
Even if you don’t provide for a constructor in your code java will provide a default constructor for you, initializing all your instance variables to their default values i.e int variable to 0, Boolean to false and char to null. It is always a good programming practice to provide a no parameter constructor.
Now,constructor is just like any other method. That means they can be overridden.
for eg- a constructor can be defined as Greetings(int x ,int y);
Our class Greetings can now be defined as-
public class Greetings { String greet ; //class variable
Greetings(){}; //no parameter constructor
Greetings(String s) { /** this constructor accepts a string and assigns it to the class variable greet */
greet = s ;
}
void displayGreeting(){
System.out.println(greet);
Constructors can also call other constrictors. this keyword is used to do so. this(x,y) calls its fellow constructor that accepts two variables.
This pretty much concludes our discussion about constructors.This is almost everything you need to know about constructors…Watch out for the next tutorial..See you next time 😀

So, i am back after a long long break..actually was busy with some stuff,my new novel and some more projects.

Though a lot of programming tutorials will start out with some dazzling stats and boring history about the language.  I’d rather take a straight route and start with an actual program.

So, lets begin.please refer to the comment and the text that follows the code( i assume that you know a bit of c or c++)


public class GreetingTest { // a class declaration..will come to it later
/**same old main function for c programmers only its called a method though its hard to recognize.*/
public static void main(String args[]) {

Greetings obj = new Greetings();// object declaration and creation
obj.displayGreetings ; /**method call to an object method named displayGreetings..*/
}
}
public class Greetings { // another class declaration :P
Greetings(){};//contructor defination
void displayGreetings() { // method defination
System.out.println("hello cruel world");/*same as cout and printf of c++ and c...only its a bit different and a bit too long*/
}
}

Ok, i know this an awkward code,but don’t be dazed cause its not that trivial(though I know it is:P)
We, know that java is a bit cranky and object oriented so it does everything with a difference..so we’ll learn it in other more deep posts..

OOP for beginners

As the software development caught more pace and found more applicability programs became more complex. The problem was, as the logic became more intense, managing programs became a real issue. Many software engineering techniques were invented and deployed but the issue was far from being solved. The most widely use modular programming which laid emphasis on functions rather than data itself couldn’t solve the problem. And then a new revolution was taking birth in the MIT labs(yes,those geeks again). The called it object oriented programming(OOP,i know it’s a weird name). Here they constructed a new approach to software development. They kept data at the heart of software development and built the programs around it. Lets understand some basic OOP concepts…

There are four basic OOP concepts(though there are more,but we’ll take them later).

  • Inheritance
  • Polymorphism
  • Data abstraction
  • Data encapsulation

Inheritance-

It is the process by which one object acquires the properties of another object.

This is important because it supports the concept of hierarchical classification.

As mentioned earlier, most knowledge is made manageable by hierarchical (that is, top-down) classifications.

If you describe the world in an objective way you must define everything according to its own set of stats I.e size ,weight etc. Animals for example also have certain behavioral aspects; they eat, breathe, and sleep. This description of attributes and behavior is the class (group) definition for animals. If you wanted to describe a more specific class of animals, such as mammals, they would have more specific attributes, such as type of teeth, and mammary glands. This is known as a subclass of animals, where animals are referred to as mammals’ superclass. Since mammals are simply more precisely specified animals, they inherit all of the attributes from animals. A deeply inherited subclass inherits all of the attributes from each of its ancestors in the class hierarchy. So inheritance in programming is analogous to familiar definition of inheritance.

Polymorphism

is a feature that allows one interface to be used for a general class of actions. The specific action is determined by the exact nature of the situation. Consider a stack (which is a last-in, first-out list). You might have a program that requires three types of stacks. One stack is used for integer values, one for floating-point values, and one for characters. The algorithm that implements each stack is the same, even though the data being stored differs. In a non– object-oriented language, you would be required to create three different sets of stack routines, with each set using different names. For example abs is a function that give absolute values. In java(OOP language) uses the same name for any kind of input data type but in C there are 5 or more abs functions for every input data type like fabs for floating-point number.

Ok I think its enough for this post next two we’ll take up in the next post

Lets leave programming for some time and learn about a beautiful art of story telling..

1.What is the Hook of your Story?

The most important aspect of fiction writing is a hook.Your hook should be like an anchor in the ocean,you may move away from it but too far and you’ll have to bounce back!
Write down the genre of your story on a page,then pick up the most important one.Remember it is upto you to decide what your story is.
2.Dont Write Long Introductions!
Prologues are a common part of novels since they started.It gives the readers a basic idea about what is in the book,before they turn the pages!But most of the readers skip that part.
One,because it flattens the excitement,two because it just adds to the bulk.You can get over this problem by writing an interesting prologue.Like telling about the features readers won’t find in the book or giving meanings of some concepts which arent defined in the book.
Like J.Tolkien wrote the appendix for The Lord of the Rings which made the readers clear about Elvish tongue and how few words have to be pronounced!
3.Who is the Hero?
This is another important thing to note while you are writing.Many novels have multiple characters,but the acclaimed ones are which show atleast one above all.Sometimes people write dark novels,in that case it is okay to have many heroes and the readers always end up with discussions about who really was the hero! So you have to be strict about the former or latter based upon the genre of your novel.Another rage among new artists is Anti-Hero.Well its good to have one,but in the end remember as you write think of your anti-hero as the hero.Whether he does good deeds or bad,he is smarter than the rest and he wins in the end!
4.Do not use Half-Knowledge
Most fiction writers are mislead by the very word FICTION.They think they can use their imagination on every aspect of their work.But that is wrong,if something exists and you manipulate how it looks,your readers maybe infuriated.It altogether doesn’t make any sense to write something about which you have little knowledge.Do research on the subject if it is indeed necessary for you to write the thing.For Example-Paulo Coelho has every minute information about the topics he mentions and he willingly discusses it with the readers and thats what fascinates the subject!
5.Avoid GOT!
Novice writers are often led into writing the word got.It is a very common verb which can be used almost universally.But,more you use the word,the more readers conclude that you are not a professional.
for example,
this sentence is what most writers would tend to write:-
I GOT on Horseback within ten Minutes after I GOT your Letter.When I GOT to Canterbury,I GOT a Chaise for the Town.But I GOT wet before I GOT to Canterbury ad I HAVE GOT such a Cold as I shall not be able tto GET rid of in a Hurry.
The better version of this sentence would be:-
I MOUNTED my Horse within ten minutes after I RECIEVED your Letter:as soon as I ARRIVE at Canterbury,I ENGAGED a Post Chaise for Town.I was wet through before I REACHED Canterbury and I have taken such a Cold as I shall not be easily CURED!
6.Depiction of Persons and Surroundings!
Most of the writers these days proceed in their work keeping in mind that one day a movie would be based on it.Thus they start giving minute details about the persons and surroundings.Some can do it very well but some are stuck up doing the same.For example Ayn Rand has used a very brilliant writing technique in The Fountainhead to describe the persons,she concentrates less on the environment on the other hand JRR Tolkien in The Lord of the Rings creates a scenery first and then minutely describes the character.Most of the writers are confused which trend to follow and thus they end up doing both of them.Thats not right,you should have your own ways since your first novel.Always be a trendsetter.Also do not describe the persons again and again,the readers are intelligent enough to remember the picture once drawn!
7.About Dialogues!
The writers read on various websites that repetitions aren’t good for a book,think of more and more words for each situation.That is correct but in case of dialogues SAID is the only word that should be used most of the times.Most writers end up using different verbs for different dialogues.That is okay upto some stretch but not beyond that.Don’t start digging up the thesauras for synonyms of said.Because then ifyou have a very good dialogue on an it ends with a word like she asserted.The reader would feel angry about opening a dictionary in the middle of an interesting scene!
8.How to Start?
This is the most common debate,even amongst non writers.It should have been in the starting but as most of you know a lot about this topic so I keep it at 8th.From when we were kids our teachers have been telling us to start a story,essay or anything by a phrase or a scene that catches the attention of the reader immediately.Same is the case with novels,keep your most disturbing chapter on the top.Like if your novel is about a fight between two groups,do not start with the conditions which led to the scufffle,rather start with the fighting scene,tell the readers what is happening on the field.Then later give the descriptions!

Now the last 2 points would look naive to many,but they are important
9.Give Time!
Now as the title suggests its about giving ample time to your novel.There are a lot of disturbing factors once you sit to write,like a call from a friend for usual chatting,your mom asked you a favour,a cousin came to meet you at your house,all these are important too but amongst all this give the time your book deserves.Once you are in a flow,don’t let anyone disturb you,because that is the moment when you write your best!
10.Use a Pen!
This point may confuse many of you,but this is true.Writing your chapters with a pen is lot different than typing them into your laptop.One reason is that you may lose the files in your Computer and then have to brag about it.But the main reason is when you write with a pen,your brain synchronises with your pen and regards it as an extension of your hand.As it thinks,it compells the pen to write.Whereas you lose ideas when you open your fingers to type,the neurons are shaked and they loose the signal.So always prefer a pen and notebook!

HTML5-An introduction

While browsing the INTERNET each one of us must have stumbled upon an article about the latest web war html5vs flash. Though most of us might not have spared a second on it the fact that the way we develop online applications and websites is going to change if the new HTML5 standard is fully implemented. Lets understand all about HTML5 and examine if its worth the hype or its just a flash in the pan.

The first draft of HTML 5 appeared on January 22, 2008, and it has been under revision ever since.

Technically speaking HTML5 is the latest version of the HTML specification, but it’s commonly used to refer to the combination of three technologies together: HTML5, CSS3 (the latest version of Cascading Style Sheets), and JavaScript. Together, they are known as the HTML5 stack. HTML – the markup language, CSS determines how it is rendered, and JavaScript is the programming language. All three of them provide a user experience similar to that of flash and silverlight. It allows programmers to build sophisticated web sites that behave more like downloaded applications. So HTML5 stands in direct line of fire from flash and silverlight.

HTML5 supports the following features:

  1. Offline data storage, meaning users can access web sites developed in it without being connected to the internet
  2. Drag and drop functionality
  3. Document editing (i.e. Google Docs)
  4. Built-in video
  5. Geolocation – the ability to identify the real-world location of a computer on the Internet.

The most exciting new induction to html existing standard is encapsulation of Canvas within the language. Canvas provides designers a rich API to render 2D, that goes beyond images and boxes available earlier. Web designers can now use the whole page for to build interactive artistic expressions without the need of flash and silverlight. This would decrease the dependence on various plug-ins- in name atleast.

Offline Storage: Web Apps Take the Next Step:

HTML5 takes offline web applications to a new height. The fact that we cant stay online almost all the time evidently felt like on airplanes etc. The local storage api can now be used to allow a web application to function until connectivity is restored. Indeed, with the spread of web applications, this storage, in its current incarnation referred to as DOM storage, is a requirement now and has been broken out of its HTML5 roots in order to streamline its real world implementation.

Modern browsers are starting to implement this HTML5 feature, and the current model of text based key and value storage is expected to grow into a universal structured data storage as the standard matures. This would greatly expand the usefulness of web applications, and in this author’s opinion it could single handedly make the current model of patching desktop programs obsolete as it would automatically update itself as a connection was restored. Exciting indeed.

With html5 the development process has also been made a bit more neat. With inclusion of tags like <nav>-element represents a section of a page containing primary navigation links to other pages or to parts within the page.

<article>-element represents an independent section of a document, page, or site. This could be a forum post, a magazine or newspaper article, a blog entry, a user-submitted comment, or any other independent item of content.

And also <header> and <footer> tags that meant same as their name. These tags come handy in creating a neat code and help make more accessible api for css and javascript.

Understanding XHTML

About a decade ago  the world wide web was facing a serious problem(a problem the world still faces though).Let’s see if you can spot it. A study says that almost 99% websites in the world have atleast 1 bad line of code. Yea thats it broken HTML problem. The fact the browsers have been fiercely forgiving and have allowed almost every bad coding practice to flourish. Examples-you write your code without the title tag.The html documentation states that the document is not complete without a title tag but still the browser displays the document without an error message. Although the HTML gurus(the people who form HTML documentation) tried to correct this issue by exporting current standards to a new evolving  technology- XML(another markup language – with a difference though). One great thing about XML was its non forgiving nature i.e if a code didn’t match the standard an error message is displayed instead of the document.

W3c though maybe this new technology can fix the existing violations of there long cherished standard- they renamed it XHTML.

XHTML is almost similar to HTML4 but with a new fix. It is reformulated  in XML(you dint get it!!).

A THING ABOUT XML-XML i s a language which lays rules  to form other markup language. You can call XML as a standard for writing other markup languages.

So XHTML appeared on the scene. It said that the header must contain a line i.e CONTENT-TYPE: application/xhtml+xml. For browser to render it the way XHTML should be render(the non forgiving HTML way). This meant now everything was fine(thats wat w3c thought). No piece of code will the displayed and web world will again be as sweet as it was.But the dreams were broken.And it was just 1 line in its documentation which helped find developers a loophole in the entire new HTML.

It said that it is alright to code your document in XHTML but you can surely use the prevailent  content-type: text/html, so even if you right your code with XHTML rules its still will be rendered in the old forgiving way i.e  write your doctype for XHTML snas the content-type: application/XHTML-XML and you are good to go. So everything from your lower case tags to every tag that is closed is a labor done in vain.

So, XHTML was a step in right direction but with bad foot…;)

HTML5

One of the most exciting new technology I see on the horizon is HTML5 stack. At first its a bit confusing and hard to understand.I guess here on this blog we will disect this technology and tell you about it. Most of the next post will be about HTML5  and HTML5 stack.

Some links

Some websites you refer to :

http://dev.w3.org/html5/spec/Overview.html

http://html5demos.com/

http://html5.org/

http://www.html5rocks.com/

To test your browser compatibly check out this website

http://www.html5test.com/

Head start a website!!

First template

Template

After gaining a Basic understanding of what Html is , we will now learn how to make web pages using Html.
As mentioned earlier Html works on three basic concepts –
1.Tags
2.Attributes
3.Elements ( which consists of the above two )

An Html code is written in any text editor for eg. Notepad is the most common editor used to write a Html Code
It is saved with the extension .html or .htm and the code is not case-sensitive.
Before learning to write any codes in Html it is important to know that any Html document consists of Two Parts
1.The Head section <head></head>
2.The Body Section <body></body>

To write a Html document we start by firstly specifing that the document contains Html code
This is done by writing the code in between a paired tag , which is <html> </html>
whenever we write </tag> it specifies that the effects of the tag comes at an end at that position.

THE HEAD SECTION or HEAD ELEMENT
The Head elements can provide meta information , tell the browser where to find stylesheets,give the title of the
document and much more.
The tags specified in this section always lie between the <head></head> tags
All the tags that fall under this section have little effect on the bulk of the data that you want to display on your website.Although Html contains a large

number of tags , the ones specified below will help you in developing a website with relative ease.

1.Meta Tag
The <meta> tag is a Singular tag (that means that in Html there is no need to close the tag, however in Xhtml it must be properly

closed). This tag is used to give metadata about the HTML document i.e
it is used to give descriptions , keywords for search engines,author etc.For eg.

<html>
<head>
<meta name=”Description” content=”Dropbox tutorial” />
</head>
</html>

2.Title tag
This is a paired tag(<title></title>). This tag defines the title of the document in the browser toolbar and also

provides the title of the page in search-engine results

<html>
<head>
<title> Drop Box </title>
</head>
</html>

– this will provide the document with the title “Drop Box” which will be
visible on the browser toolbar.

3.Script and Style tag
These tags are used to introduce Javascript and CSS (Cascading Style Sheets) into a HTML document to

make it more dynamic an provide a better user interface.These tags will be better explained later on

The head tag doesnt have any attributes of its own but is just used to specify the tags mentioned above. These tags

can only be used in the Head section and not anywhere else in the document.

THE BODY SECTION
The bdoy element contains various tags to display and manipulate the Data to be displayed on the webpag such as introduce
images, insert hyperlinks, modify text, lists etc.
The tags specified in this section lie in between the <body></body> tag. Unlike the head element, the <body> tag has a
number of attributes.
The data manupilation can take place in literally hundreds of ways , that is why we will give different posts to talk in detail
about the important ones like the Lists, images, tables etc.
Some important Body tag attributes are discussed below-

1.BGCOLOR

This attribute is used to give a background color to your document or table backgrounds
There are two ways in specifying the color for your document. The first and most simple one is to just write the
name of the color eg. red . However this doesnt provide you with a lot of color variation. For this purpose the bgcolor
attribute can also be specified by writing # followed by a six digit/character code.There’s 216 “true colors” with hexidecimal.
The colors are made out of hex-pairs for red, blue, and green. Examples: #99FFCC, #33AA44.

<table bgcolor=”lime” border=”1″><tr>
<td>A lime colored table background using color names.</td>
</tr></table>

<table bgcolor=”#ff0000″ border=”1″><tr>
<td>A red colored table background using hexadecimal values “#FF0000″.</td>
</tr></table>

<table bgcolor=”rgb(0, 0, 255)” border=”1″><tr>
<td>A blue colored table background using RGB values “rgb(0, 0, 255)”.</td>
</tr></table>

2.Background Image

This attribute is used to give a background image to the page or a particular cell of a table
It has a further attribute norepeat that prevents the image from being repeated if it does not fit the browser window

<body background=”abc.jpg” norepeat=”norepeat”>

The next post will give a overview of the Font and image tag along with the different types of lists

The server-side client side paradox

The most frustrating and confusing thing about web development is the question which language handles what?

The client-side languages brings in the fun (they make INTERNET a happening place),the interactivity to the websites. From flashing headlines to rollover images to constantly refreshing news. They do it all for you! Client-side side languages include- CSS,Javascript,vb-script and Java-applets. But there is a down side to all this flash and jitter(yes, what shines is not gold all the time).Client-side programming is stung by not one but a number of bugs , cross browser compatibility,ignorant non-upgrading users and rather more stubborn browser makers. To add to all this client-side languages don’t have the right to access the server nor they can write to the clients system. The fact that browsers , there makers and users have made web a very uncertain place. Nothing is sure, you spend half of your intellect making the best product of your life ,everything is going good but there is a great probability that your product may not work for users on there systems. These languages are a great help to customize your website and save you from a lot of headache(but the headache they bring with them is rather more painful).With the existence of these highly applicable languages ,there exists(co-exists) a world full of font tags and bg colors. The fact that browser compatibility has made masters of this universe to stay away from these technologies. Websites like yahoo and amazon still don’t use these technologies more openly or courageously. Though small and lesser known sites have accepted them with open arms and use them. My personal take on this is that these languages should phase out the older(and there upgrades) languages and these languages must replace them.

Server-side scripting is where the glamor the lies. People that make Internet a personalized place. Where every user has an unique identity of his own ,specially customized page. Server-side scripts are like invisible heroes ,they lie some where between the server and the client. Filling in spaces and mediating. Server-side Web scripting is mostly about connecting Web sites to back end servers, such as databases.

They perform to basic functions-

  1. Web pages can be assembled from back end-server output.

  1. Customer-entered information can be acted upon.

Server-side scripts though slow down performance as when ever you have to do something you have to go back to the server. Internet speeds have still not reached the mark where server-side scripts could load something and the user will not know. Every time when a script asks for a page, the user has to wait(sometimes the wait seems to be never ending).This downsides the server-side languages to completely take over the INTERNET scripting space.

Conclusion-Use client-side language to handle immediate events. Use server-side technologies to tackle mare complex situations