Sunday 31 May 2020

मन बावरे


तुम्ही "ती सध्या काय करते" हा चित्रपट पाहिला आहे का हो? असेलच आणि आवडला पण असेल. पण तुम्हाला माहिती की अशाच विषयावरचा "96" नावाचा एक तामिळ चित्रपट पण आहे? नाही? काही दिवसांपूर्वी मला पण माहीत नव्हता. त्याचं झालं असं, युट्युब वर आपण व्हिडीओ बघतो त्यामध्ये आपल्याला ते युट्युब इतर व्हिडीओ पण सुचवत असतं. एकदा मला "लाईफ ऑफ राम" अशा एका गाण्याची लिंक आली. मला फोटोग्राफीची आवड असल्यामुळे हातात कॅमेरा घेतलेली एक व्यक्ती गाण्यात दिसली आणि उत्सुकता चाळवली गेली. ते गाणं मी बघितलं.  अप्रतिम छायाचित्रण आहे त्या गाण्याचं! एका फोटोग्राफरचं काम इतकं सुंदर टिपलंय त्या गाण्यात, "मला पण हे करायचंय, मी तिथे जाणार, मी पण असा फोटो काढणार" असं इतके वेळा होतं ते गाणं बघताना. खाली इंग्रजी अनुवाद येतो त्यामुळे भाषा कळली नाही तरी तसा फरक पडत नाही.  गाणं आवडलं म्हणून चित्रपटाविषयी जरा वाचलं आणि बघावासा वाटला. अनायासे हिंदीमधे अनुवाद केलेला उपलब्ध आहे युट्युब वर तो डाउनलोड केला आणि बघितला. 

इतका नितांत सुंदर चित्रपट आहे! खूपच छान! जरूर बघा.  खासकरून आजच्या काळात जिथे प्रेमाच्या कल्पना बदलत चालल्यात. वासनामय प्रेम काय, ऍसिडफेक काय, आत्महत्या काय, नैराश्य काय, प्रेम असं नसावं आणि नसतंच.   खरं प्रेम कसं असू शकतं आणि ते आपल्याला किती समजूतदार बनवू शकतं हे या चित्रपटात खूप छान मांडलं आहे. पण हिंदी अनुवादीत चित्रपटात सगळी गाणी छाटून टाकली आहेत कारण त्यांना गाण्याचं  भाषांतर जमलं नसावं. पण त्यामुळे  काही गाणी जी त्या चित्रपटाचा आत्मा आहेत ती नाहीयेत त्यात. असंच एक गाणं - "थाबंगले". 

खूप अप्रतिम गाणं आहे, कथेच्या दृष्टीने. शाळेत प्रेमात पडलेली दोघे जण इतक्या वर्षांनी परत भेटलेत, तिचं लग्न झालंय, त्याने केलं नाही, भेटल्यावर ती परदेशात परत चाललीये, परत कधी येणार माहीत नाही. दोघांच्याही मनात अजूनही एकमेकांविषयी ओढ आहे पण त्या दोघांनाही माहिती आहे की  त्यांचं एकत्र येणं शक्य नाही, त्यांना त्यांच्या आयुष्यात परत जाणं भाग आहे. तो तिला विमानतळावर सोडायला चाललाय आणि हे गाणं येतं.  अप्रतिम संगीत, सुंदर गायन, सहजसुंदर अभिनय आणि शहराचं अप्रतिम छायाचित्रण याचा सुंदर मिलाफ असलेलं हे गाणं आहे. तुम्ही जर चित्रपट आधी बघितलात आणि नंतर हे गाणं पाहिलंत तर हे गाणं आपल्याला त्यांच्यात अधिकच गुंतवून ठेवतं.  

आता मूळ मुद्दा... झालं काय तर हे गाणं माझ्या डोक्यात अडकलं पण भाषा तामिळ असल्यामुळे गुणगुणता येईना. तेव्हा विचार आला की हे आपण मराठीत रुपांतरीत केलं तर?  तसा प्रयत्न करत गेलो आणि सुचत गेलं. जे सुचलं ते गाण्याचं शब्दशः भाषांतर नाहीए पण चित्रपटाचं सार मात्र नक्की आहे त्यात.  तर मला सुचलेली ती कविता / गाणं इथे मांडत आहे.  गाण्यातल्या ओळींचा क्रम कायम ठेवायला काही ओळी परत परत लिहीत आहे, व्हिडीओ बघता बघता ओळी वाचल्यास जास्त संदर्भ लागेल - 

ती-
मन बावरे, भोळे खरे,
हळव्या क्षणी उमलुनी खुलते, 
आनंदते, कधी स्पंदते, 
नकळत मग दुसऱ्या मनाशी जुळते...

तो-

मन बावरे, भोळे खरे,
हळव्या क्षणी उमलुनी खुलते, 
आनंदते, कधी स्पंदते, 
नकळत मग दुसऱ्या मनाशी जुळते...

दोघे-

झुरते किती तू नसताना,
कधी तुला का जाणवते,
धागे आपुले जुळले ना परी,
अव्यक्त काही अंतरी उरते...

ती-

मन बावरे, भोळे खरे,
हळव्या क्षणी उमलुनी खुलते, 
आनंदते, कधी स्पंदते, 
नकळत मग दुसऱ्या मनाशी जुळते, 


तो-

का भेटीची, वेळ सरते,
वाळू जशी की निसटते,
तू सोडून जाताना,
आयुष्य माझे थबकते...

दोघे-

प्रेमाचा अर्थ शोधताना,
सोबत मला तू करशील ना,
एक  जन्म  घेऊ या असा,
तेव्हा, 
तुझे माझे नाते परिपूर्ण होऊदे...

तो -

मन बावरे, भोळे खरे,
हळव्या क्षणी उमलुनी खुलते,

ती- 

आनंदते, कधी स्पंदते, 
नकळत मग दुसऱ्या मनाशी जुळते..


गाणं  चालीत चपखलपणे बसतं फक्त थोडा प्रयत्न करावा लागेल.  दुसऱ्या एखाद्या भाषेच्या गाण्याचं मराठीत रुपांतरीत करायचा हा माझा पहिलाच प्रयत्न आहे, कसं वाटलं नक्की सांगा....


Friday 24 April 2020

Dream or Reality?





Today is 31st day of lock-down and it's very difficult to believe what has happened in all these days.  Is this a reality or just a dream?  A question that also used to trouble Mr. Cobb in the movie Inception.  So he used to spin his totem to check that time to time.  Today I also tried to check it with a floppy as my totem(My new photography skills are helping me to take such shots) 

I mean look around you.  We live in a city called Mumbai, a city that never sleeps, but majority of the people(except the ones who are in essential services) are at home.  The Mumbai Local trains are considered to be the life line of the city and no signs of them running over these days. Recently somewhere in Mumbai peacocks  were  spotted.  We have realized that we can live without any hotel food. The Himalayan ranges are visible from a village in Haryana.  Ganga river's purity has increased drastically.  Ozone layer of the Earth is increasing. So many developed nations having high-class medical facilities are dependent on India for one medicine which is the need of hour!  All these sounds unbelievable isn't it?  Hence I felt let me check by spinning the totem.  As expected,  the totem fell down.  




Some say that the nature is healing itself.  Yes, its true that over these years we have caused immense damage to our mother nature and we have crossed all our limits.  The actual cause of the whole thing - COVID-19, is actually a flue like disease and it is not as deadly as other diseases.  But our life-style has damaged our immune system and health so much that we are not able to win it.  Its high time that we should understand our limits and change our lifestyle.  Nature has been so kind to us that it is silently healing itself for our benefit, we should respect it. For the time being - we can stay at home, take care of ourselves and be thankful to the people who are working relentlessly for us out there.   Let's just pray and hope that the world recovers from this pandemic soon. 


Wednesday 30 October 2019

तो मी नव्हेच ..

"पुसणार  कुणी असेल अश्रू
तर डोळे भरून यायला अर्थ आहे, 
कुणाचे डोळे भरणार नसतील तर 
मरण सुद्धा  व्यर्थ आहे..."

किती सुंदर आहेत ना या ओळी, खऱ्या अर्थाने चारोळी! आठवतंय का कुणाच्या आहेत? अहो, वाचल्या असतील तर नक्की आठवतील. आम्ही कॉलेज मध्ये असतानाच्या काळात या खूप प्रसिद्ध झाल्या होत्या. चंद्रशेखर गोखले हे त्या कवीचं नाव. त्यांचा तेव्हा " मी माझा" हा चारोळी संग्रह खूपच गाजला होता. जीवनातलं सार "शेर" सारखं चारोळीत मांडायची कल्पना या कवीला सुचली त्याला सलाम! 

आत्ता हे लिहिण्यास कारण की, मी जेव्हा या वाचल्या होत्या अर्थातच मलाही खूप आवडल्या होत्या आणि आजही लक्षात आहेत. पण एक प्रयत्न म्हणून तेव्हा मी या संग्रहातल्या काही चारोळींवर वात्रटिका लिहिण्याचा प्रयत्न केला होता. त्या आज मी तुमच्या समोर मांडू इच्छितो. आशा करतो की तुम्हाला आवडतील, माझ्या नाही आवडल्या तर निदान मूळ चारोळी तरी वाचाल त्या निमित्ताने !  मूळ चारोळी "उद्गारवाचक" चिन्हात दिली आहे त्या खाली माझी वात्रटिका आहे. त्यांच्या संग्रहाचं नाव होतं "मी माझा", माझ्या संग्रहाचं नाव असेल तो मी नव्हेच ..

१. 
"इथे प्रत्येकजण आपापल्या घरात
अन प्रत्येकाचं दार बंद आहे,
तरी एकोप्यावर बोलणं हा
प्रत्येकाचा छंद आहे..."
---
इथे प्रत्येकजण आपापल्या घरात
अन प्रत्येकाचं तोंड बंद आहे,
कारण व्हाट्सऍप आणि फेसबुक
प्रत्येकाच्या मोबाईल वर चालू आहे... 

२. 
"ठाऊक असतं तुझं येणं अशक्य आहे
तरी मन तुझी वाट पहाणं सोडत नाही,
मीही म्हणतो जाऊ दे
मी त्याचं मन मोडत नाही..."
----
ठाऊक असतं तुझं मला स्वीकारणं अशक्य आहे,
कारण मी तुझ्या लायक नाही,
म्हणूनच म्हणतो - जाऊ दे
मी "त्या"चं तंगडं मोडत नाही...


३.
"तुझ्यावर रागावणं हा
तुला आठवण्याचा बहाणा आहे,
तू आलास की तो ही जातो
तसा माझा राग शहाणा आहे..."
----
तुला टाळणं हा तुलाच 
वाचवण्याचा एक बहाणा आहे,
कारण तू आलास की तो ही येतो
तसा माझा बाप शहाणा आहे...

४. 
"मला वाटलंच होतं मला पाहिल्यावर
तू मागे वळून पाहशील,
वळून पाहण्याइतकी तू
नक्कीच माझी राहशील..."
---
मला वाटलंच होतं मला पाहिल्यावर
तू मागे वळून येशील,
बस मध्ये काढलेल्या तिकिटाचे ५ रुपये
निर्दयपणे परत करशील...

५. 
"सगळीच वादळं मी 
खिडकीत बसून पाहिली,
पण परवाच्या वादळात
माझीच खिडकी वाहिली"
----
सगळ्यांची तावदानं
मी खेळताना फोडली,
पण परवाच्या खेळात
माझ्याच घरची फुटली...

६. 
"वाळकं पान गळताना सांगतं
वसंत आता येणार आहे,
तो ओरडतच येतो
मी आता जाणार आहे..."
---
पांढरा केस उगवताना सांगतो
म्हातारपण आता येणार आहे,
त्याला काळं केलं तर म्हणतो
अरे तुझा दात पण आता पडणार आहे...

७.
"पावसाचा एक थेंब चुकून
माझ्या खोलीत येऊन पडला,
आणि बाहेरचा पाऊस पाहून 
मुक्यानेच रडला.."
-----
पावसाचा एक थेंब चुकून
माझ्या खोलीत येऊन पडला,
पण त्यावरून पाय घसरून
शेजारचा बाळू पडला...

८. 
"घराभोवती कुंपण हवं
म्हणजे आपलं जग ठरवता येतं,
बाहेर बरबटलेलं असलं तरी
आपल्यापुरतं सारवता येतं..."
----
घराभोवती कुंपण हवं
म्हणजे आपलं जग ठरवता येतं,
कुंपण थोडं छोटं असलं तरी चालेल
कारण शेजारच्या घरात डोकावता येतं...

९. 
"माळरानावर पाखरं 
दाटीदाटीनं जमायची,
बुजगावणी मग वेडी
त्यांच्या संगतीत रमायची..."
----
माळरानावर पाखरं 
दाटीदाटीनं जमायची,
इतकी हुषार झालीयेत की
जाताना बुजगावण्यावर शिटायची...

१०.
"अडकलेला पतंग आधी 
काढायला निघतात,
निघत नाही म्हटल्यावर 
फाडायला निघतात..."
----
हरवलेली चप्पल आधी
शोधायला निघतात,
मिळत नाही कळलं की
दुसऱ्याची घालून जातात...

११.
'गावाच्या वेशीवर
मारुतीला बसवलेला,
दर शनिवारी नारळ देऊन
बिचाऱ्याला फसवलेला..."
----
शेजारच्या नाक्यावर 
स्टॉल टाकलेला,
महिन्याच्या हफत्यावर
कसाबसा टिकवलेला...

१२.
"सरपणासाठी तोडलेल्या ओंडक्याला
एकदा पालवी फुटली,
त्यालाच कळेना ही 
जगायची जिद्द कुठली..."
-----
ओठावरच्या मोकळ्या जागेत
एकदाची पालवी फुटली,
तेव्हा मला कळलं की माझी 
बालपणीची हद्द संपली...

१३. 
"खूपदा माझा एकलेपणा
माझ्याशी बोलका होतो,
मग कुणी एक शब्द जरी बोलला
तर त्याचाही गलका होतो..."
-----
खूपदा माझा हावरेपणा 
मला खूप चेतावतो,
मग दुसऱ्या दिवशीच्या सकाळ नंतरच
मी थोडासा हलका होतो..

१४.
"काट्याला फक्त बोचणंच माहीत
त्यात त्याचा दोष नाही,
हे मी जाणलं म्हणूनच 
माझा तुझ्यावर रोष नाही.."
---
टाचणीला फक्त टोचणं माहीत
त्यात तिचा काही दोष नाही,
मला ती दिसली नाही त्यामुळे
आता चोळण्याशिवाय गत्यंतर नाही...

१५. 
"भर दुपारी सावली
झाडाखाली धावली"
---
भर रात्री चंद्र 
अंधाराला घाबरला,
आणि ढगांच्या मागे
लपून बसला....

१६.
"परवा एक पाखरू रानात
आपलं घरटं शोधत राहिलं,
कसं सांगू त्याला त्याचं
घरटं मी पडताना पाहिलं..."
----
परवा एक लेकरू बागेत
कुणाला तरी शोधताना मी पाहिलं,
कसं सांगू त्याला त्याचं पाखरू
मी दुसऱ्याबरोबर फिरताना दिसलं...

१७. 
"तुझं आवडणंही मला
किती सहन करावं लागतं,
उर भरून श्वास घेऊन  
पुन्हा गुदमरावं लागतं..."
---
तुझं आवडणंही मला
किती सहन करावं लागतं,
तुझी होते चंगळ पण मला माझं पाकीट 
सारखं रिकामं करावं लागतं..

१८.
"अळवाच्या पानावर कसं
पाणी स्वतःला सावरून बसतं,
मोत्यासारख्या दिसण्याच्या नादात
वहाणंच हरवून बसतं..."
-----
मंत्रिपदाच्या खुर्चीवर कसा
मंत्री स्वतःला सावरून बसतो,
खुर्ची टिकवण्याचा नादात
नेतेपण हरवून बसतो...

१९.
"इमारत बनायला वेळ लागत नाही
घर बनायला वेळ लागतो,
घरासाठी दोन जीवांचा 
खरा खुरा मेळ लागतो..."
----
इमारत बनायला वेळ लागत नाही
घर बनायला वेळ लागतो,
घरासाठी कमीत कमी 
वीस लाखांचा बॅलन्स लागतो...

आवडल्याच तर आपला अभिप्राय नक्की द्या, कारण  

वाचणार कुणी असेल तर 
ब्लॉग लिहायला अर्थ आहे,
आणि वाचून फॉरवर्ड करायला ही
 तसा तो वर्थ आहे.. 😉😃🙏

Monday 19 August 2019

Black Hole

Have you heard of a black hole? Yes, I am talking about the black hole that you find in space.  I am sure you must have some idea of it.  

As per wiki - A black hole is a region of space-time exhibiting gravitational acceleration so strong that nothing—no particles or even light—can escape from it.The boundary of the region from which no escape is possible is called the event horizon. To a distant observer, clocks near a black hole would appear to tick more slowly. We don't surely know what happens to the objects that go through a black hole.

You must be wandering why I am talking about black holes today and what I have got to do with it(or to this subject).  By the way, I am a Physics Graduate and Relativity used to be one of my favorite subjects in TY.  Its really amazing that the scientists have proved(as we know it so far) some of the theories which are so complex.  The concepts like twin paradox, black hole are so fascinating yet baffling.  Still we haven't understood everything about it.  

Coming back to black holes.  Few years of ago, I happened to see a movie called Interstellar.  I was literally on the edge of the seat in an IMAX theater especially that Black Hole travel scene.  Do you remember how the black hole looked in the movie? It looked something like this.  Its called Gargantua!



Off late, I have developed interest in photography and I take lots of photos.  Yesterday I captured a photo like this(I have used Snapseed for blurring and frames) - 


Obviously, that's not a black hole.  That's tube-light reflected in my camera lens. But the light has literally been bent as if it has reached event horizon.  Don't you feel that the image in the center of this photo looks like that Gargantua black hole?  I feel that there is similarity between black hole of a space and black hole of a camera lens!  

Black hole of camera lens also captures light, pulls everything that is around into it. A 3-D view in front of it gets converted to a 2-D image. The time seems to be stopped in that image. Doesn't it deform the space-time?  We know a little bit extra for sure what happens to the objects that pass through this black hole. The scene gets converted to a "photo" which is so powerful that just by looking at it, it can "time-travel" you in just a fraction of a second! 

I hope you followed what I wanted to say. Anyways, Happy World Photography Day! Keep clicking!


Friday 16 August 2019

e. g.

You must have come across this term many times and you all must be aware of this term which means "for example". Technically its an abbreviation of "exempli gratia" in Latin. In the field of teaching, examples play a very important role. Many difficult concepts can be cleared with good examples. I also tend to give lots of examples during my lectures and students enjoy them a lot. I try to avoid to give examples given in the book and I always like to give my own examples. Sometimes they come to mind spontaneously or sometimes I have to think a lot. Recently I gave an example while teaching a topic called "Learning" in AI. Its just demonstrates how one can involve students to understand concepts like these with real life examples.



I was teaching Decision Tree and I got bored to take same examples of tennis-play or reptile-mammal which you find on internet. So I decided to take an example based on students' "taste" in photography. I decided that I would have 10 students to contribute training data and 4 students for test data. I asked them simple questions - whether they like scenery, whether they like photo with people, whether they like color/bnw photos. I recorded their answers in spreadsheet which I kept it open in front of them. I got the following responses -
No alt text provided for this image
Now that everyone got an idea of what students like in photography, I decided to show some sample photographs and ask the students to rate them. While doing so, I asked test data students(s11 to s14) to go out of the class for some time. I displayed two photos(p1 and p2) to first five students(s1 to s5) and next two photos(p3 & p4) to next five students(s6 to s10) and asked them to rate on a scale between 1(minimum) to 10(maximum). During this process, students s11 to s14 were completely clueless what is happening in the class. The ratings of the students are as follows -
No alt text provided for this image
After getting these ratings, I asked all the students to do a prediction based on these sample ratings for the students who were outside the class. Students by doing some analysis(like average), predicted the ratings that the outside students would give to these photos. There were differences of opinions among the students hence I recorded all the answers. They predicted the following -
No alt text provided for this image
Now the excitement reached at its peak as students realized what would be my next move! It was time to call the four students inside the class to give their answers who were wondering what must be happening in the class(Thank God that they didn't run away). I called them inside the class, told them that they would be shown photos which they have to rate. I kept our predictions hidden from them. The rest of the class were on the edge of their 'benches"! The students from s11 to s14 rated the photos like these -
No alt text provided for this image
There were lots of "Yes"s and "Ohh"s after these students gave their answers. The students who gave their answers didn't realize why there was so much excitement in the class. Finally it was the time to compare what was predicted by the class and how many answers actually matched.
No alt text provided for this image
The students who just gave answers were surprised to see that their answers were predicted correctly by the class! One answer didn't match at all. So that is when I introduced the concepts of bias, under-fitting and over-fitting. I also told them that what we did is a regression tree in which we predict numbers.

That day in the morning I was completely clueless of what I would be doing in the class. But after the lecture, I felt happy and excited! Somewhere I had read -

“Tell me and I forget, teach me and I may remember, involve me and I learn."

Its so true. Hope I would be able to do it many times!

Saturday 20 July 2019

Understanding Framework : Servlet Framework

Over period of time, the software industry is using lot of frameworks such as Servlet, Spring, Hybernate etc. This article will cover some of the basic concepts of framework.  It will also explore basics of servlet framework.

About Library functions

Many of us must have written C programs while taking first few steps towards the field of programming.  We all used to write a statement # include <stdio.h>…. This statement is used to include the contents of a library file called stdio.h. And we also know the fact that we include that file as it contains definitions of printf(…) & scanf(..) functions which are written by designers of C. These are called as library functions.  Thus when we use such library functions what we are doing is 

· We are reusing the code written by the designers of C
· The overall flow of execution of program is decided by us(the programmers)

The only function that designers of C have fixed is main() function.  Otherwise it will be difficult for C compiler to know the start point of a program containing many functions.

About Framework

Software designers have been developing different types of applications over period of years.  But there are many processes/modules that are common and everybody has to spend the efforts to code them.  So there was a need to free the programmers from writing these similar modules.  This would also help them to focus on the business logic of the actual application.  For example, C# designers get Toolbox containing lots of GUI controls which can be dragged on to forms.  printf/scanf functions of C, controls in toolbox etc are examples of reusable code.  Sometimes there can be similarities in the overall design and overall flow of the applications.  The ideas implemented by good designers and their experience can be used by others.  This is the main concept behind framework.  

Framework represents a set of modules that consists of reusable design of a specific software subsystem.  It specifies the overall architecture of the application and its flow.  To provide application specific software, it can be changed/extended by programmer’s code.   With respect to frameworks, an important term called “Inversion of Control” is used.  We have already discussed that the modules in the framework can be extended by programmer to contain application specific code and the flow of application is predetermined.  Generally, programmers call the code written by designers.  Here, designers of the framework call the code written by programmers.  This is called as Inversion of control.    It is also called as Hollywood Principle (“Don’t call us, we will call you”).  When framework is used, developers get following benefits-

· Less time in developing/designing, coding  and debugging,
· Reduces the cost,
· Minimizes the risk,
· Increases flexibility

Framework also has certain disadvantages –

· Since the design is predetermined, programmers may have to write functions with particular names/calling conventions.  Thus they lose creative freedom.  
· Once the design of the framework is decided, it cannot be changed in new versions of it as applications which are built using older version will fail to work.  

Understanding Servlet Framework

Introduction to Servlets

Servlet is a Java-based technology used for server-side programming in developing web applications.  Servlet and its related technologies(such as JSP)  is used for almost a decade.  It is also based on the concept of framework. Servlets are managed by Servlet Container which is a program that runs inside Web Server.  A servlet can be written for n number of web applications. But there are common tasks that servlet container has to do for each servlet while processing client requests.  They are as follows –
· Server needs to determine the lifespan of servlet program in memory
· Server needs to determine whether to load the program for each request or just once and execute it using multi-threading approach
· Creating request, response, configuration, session objects
· Communicate with other servlets if required

Since they have to be carried out for all the servlets, the servlet designers must have decided to provide these services to the servlets automatically so that the servlet programmers can spend more time on business logic of the application.  

About Servlets

Servlets are based on an interface called as Servlet.  This interface contains mainly three methods – init, service and destroy that control the life cycle of every servlet.  init method is called when the servlet is first loaded in the memory.  service method is called for every client.  destroy method is called only once, when the servlet is removed from the memory.

There are two main implementations to this interface  - GenericServlet and HttpServletServlet.  A GenericServlet is used for writing protocol independent servlets.  That means, a servlet should be executed using any other protocol such as FTP.  But such type of servlets are not used to that extent. The other class is HttpServlet that makes use of HTTP and this is used more often.  

When we have to write servlet programs, we write subclass of either GenericServlet or HttpServlet.  If we create a subclass of GenericServlet, then we override service( ) function.  If we create a subclass of HttpServlet, then we override doget( )/doPost( ) function.  The servlet objects are managed by servlet-container whose role is to provide all the services to servlets as mentioned above.  Our servlets act like components which are managed by servlet container(Component-Container Architecture).  

While writing servlets, we may come across various questions such as –

1. If servlet object is created, where do I specify class name?
2. If servlet interface contains service function, then how come doGet/doPost functions are overridden?
3. Generally object is created using  a statement like - ClassName ob = new ClassName( );
Where this statement is written? Since the functions are not static, that means object is definitely created.  But who creates the object? In fact how the statement could be written when designers don’t even know the name of classes that are being written today?
4. Why we don’t write a constructor in servlets?

Let me explain answers to all these questions using an example. Before cars were invented, man must have thought of something that moves which would help him travel faster.  Let us define an interface Movable -

interface Movable
// like servlet interface
{
    public void start();
    public void move();
    public void stop();
}

This idea was implemented by automobiles.  Let us represent it by a class AutoMobile –

abstract class AutoMobile implements Movable
//like generic servlet
{
    public void start()
    {
        System.out.println("Automobile  starts…");
    }
    public void stop()
    {
        System.out.println("Automobile stops…");
    }
    abstract public void move(); //still don’t know how to move
}

This is a general idea.  But we need a proper vehicle.  A man invented 2-wheelers. Let us represent it by a class called TwoWheeler -

class TwoWheeler extends AutoMobile
//userdefined subclass of generic servlet
{
    public void move()
    {
        System.out.println("Ride a two-wheeler...");
    }
}

This class can be instantiated and its move function can be called.  Then 4-wheelers were designed.  So let us define a class FourWheeler.  Also let is redefine move( ) operation by drive ( ) operation as drive will be a more better name for 4-wheelers.  

abstract class FourWheeler extends AutoMobile
//like HttpServlet
{
    public void move() //like service function
    {
   drive();//called inside move
    }
    abstract public void drive(); // like doGet/doPost function
}

After so many years, we see different types of 4-wheelers on road such as cars, trucks etc. Let us represent them using classes –

class Car extends FourWheeler
//like user-defined subclass of HttpServlet
{
    public void drive()
    {
        System.out.println(" Driving a car...");
    }
}

Let us see how these objects are created and called –

import java.io.*;
public class MovableDemo
// type of code which could be used by servlet container to create and execute servlet objects
{
    public static void main(String[] args) throws Exception
    {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("What you want to move?:");

        String classname = br.readLine();//specify the name of class

        //in servlets, class name is mentioned generally in URL
        Class c = Class.forName(classname);
        Movable m = (Movable) c.newInstance();
        m.start();
        m.move();
        m.stop();
    }
}

This code tells you how objects of Movable type can be created and called.  If you have written JDBC programs, then you must have used Class.forName ( ).  It is used to load the class specified as argument in String form.   newInstance() function of class Class is used to instantiate the specified class.  Thus while coding MovableDemo class, it is not known what class name will be given by user.  User defines a new class, compiles and makes if available to MovableDemo. As the class is instantiated only using name, it will only call blank constructor.  Since new classname( ) approach of creating object can’t be used, it is not possible to call overloaded constructors.  Hence user can provide initialization code only in start (in servlets, init) function.  In applets as well, we have to provide initialization code in init method.  Why? Because we don’t create object of applet class.  

The way of using Movable objects is predetermined, first start, then move and then stop. We just have to write our code in these functions.  In servlets, sevlet container decides the flow of execution(that is, first init, service and then destroy).  Classes AutoMobile & FourWheeler(like GenericServlet & HttpServlet), are abstract as they contain abstract functions.  Hence they can’t be directly instantiated.  It is necessary to create subclasses of them.  

If a new type of four-wheeler is invented, it can also be executed using similar approach.  For example-

class Truck extends FourWheeler
//user-defined subclass of fourwheeler
{
    public void drive()
    {
        System.out.println(" Drive a truck...");
    }
}

This also can be executed using above approach.  Thus the designers of servlet are able to call functions of your class that you are writing today

मन बावरे

तुम्ही "ती सध्या काय करते" हा चित्रपट पाहिला आहे का हो? असेलच आणि आवडला पण असेल. पण तुम्हाला माहिती की अशाच विषयावरचा "96...