What is an academic essay
Monday, August 24, 2020
Saturday, August 22, 2020
The Painted Door Theme Essay
James Sinclair Ross was a Canadian investor just as a creator. He was most notable for his short stories set on the Canadian prairies. In Rossââ¬â¢ short story The Painted Door, Ann and her significant other John live on a homestead in Saskatchewan during the 1800s. While a blizzard is drawing nearer, John leaves for his fatherââ¬â¢s ranch to enable him to take care of the errands, leaving Ann without anyone else in the tempest. The topic of The Painted Door is disconnection prompts mindlessness and hopelessness. This can be found in the portrayal of Ann all through the story, the segregated setting of their homestead, and the imagery of the storm.Throughout The Painted Door Ann battles with an internal clash because of her sentiments of disengagement. These feelings are not just present due to the secluded setting wherein the story happens, yet in addition because of the forlornness brought about by the separation among her and John in their marriage. John centers around his w ork a great deal a lot for her loving and their relational abilities have gotten not exactly palatable. As she watches out at the land she starts to feel forlorn, and those feelings just increment as John disregards her to fight her still, small voice when he goes to his fatherââ¬â¢s farm.When Steven, Johnââ¬â¢s dear companion, shows up to play a card game and to stay with her, Ann starts to contrast him with John to decide the better man. Ann contemplates Steven as she keeps an eye on the fire and mentions objective facts, for example, ââ¬Å"His hair was dim and trim, his young lips bended delicate and full. While John, she made the examination quickly, was pudgy, overwhelming jowled, and stooped. (page 204)â⬠Her examinations of the two men in a to and fro design viably show how tangled Ann is as she is trapped in a fight between her psyche and her heart.Her portrayals of Steven cause him to give off an impression of being increasingly appealing and a respectable man, while John is the man she wedded, yet experiences experienced issues speaking with. As Ann thinks about the two men, she utilizes Stevenââ¬â¢s positive ascribes and Johnââ¬â¢s defects to persuade herself that Steven is a superior man. Her thinking prompts her silly decision to go behind John's back with Steven, which can be viewed as an explanation behind Johnââ¬â¢s passing when he went out during the tempest with no goal of returning subsequent to getting the two of them.Annââ¬â¢s seclusion prompted her creation an unreasonable choice that destroyed her marriage and will make her be much progressively desolate and hopeless without John, the man she adores. The setting of The Painted Door is portrayed so that it improves the sentiments of disconnection and hopelessness in the story. Certain symbolism is utilized to make clear pictures in the readerââ¬â¢s brain to rouse feelings of dejection. The setting is frequently portrayed as freezing, or as fruitless and void. â â¬Å"The sun was transcended the ice fogs presently, so sharp and hard a sparkle on the snow that rather than warmth its beams appeared shedding cold (page 190)â⬠.In this segment of the story, Ross utilizes words that represent satisfaction, for example, ââ¬Å"sunâ⬠and ââ¬Å"warmthâ⬠, yet certain words can be associated with disengagement, for example, ââ¬Å"frostâ⬠and ââ¬Å"cold. â⬠By relating both the Earth and the sky to such chilled words, the symbolism leaves the peruser feeling as if they are caught alongside Ann in her disconnection. Another case of confinement in the setting is, ââ¬Å"She shuddered, yet didn't turn. Free, severe light the long white miles of prairie scene appeared to be a locale outsider to life. Indeed, even the inaccessible farmsteads she could see serves just to strengthen a feeling of confinement (190)â⬠.This depicts the zone that they live in as extremely void since their closest neighbors are miles over the day off , Ann nobody to go to when she is separated from everyone else. These sentiments of confinement and wretchedness are what are continually weighing on Annââ¬â¢s bears all through the story and lead to her silly contemplations and choices later on, for example, her decision to lay down with Steven. The blizzard that happens during The Painted Door bit by bit works through the span of the story and can be viewed as an image for Annââ¬â¢s inward conflict.The storm in the story is additionally Annââ¬â¢s foe in an individual vs.â nature strife, isolating her from her better half and disconnecting her from the remainder of the world. The stormier it turns into, the more Ann gets cut off from the outside world. The tempest isolates her from John for quite a while and along these lines, Ann considers things that she typically wouldnââ¬â¢t, for example, taking part in an extramarital entanglements with her husbandââ¬â¢s closest companion. These outrageous conditions are the ma in thrust behind Annââ¬â¢s silly considerations. As the story advances and she invests more energy alone, Annââ¬â¢s contemplations and stresses start to fabricate up.The way the tempest is depicted in the story, the peruser can gather that a similar disturbance is additionally present in Annââ¬â¢s mind. By depicting the tempest as ââ¬Å"eventual furyâ⬠, ââ¬Å"blustering and furiousâ⬠, and ââ¬Å"insane and dominantâ⬠these expressions can likewise be identified with Annââ¬â¢s consistently changing musings about John. While the tempest exacerbates, Ann turns out to be nearer to submitting her transgression. As the tempest arrives at its pinnacle, Ann yields to her feelings and lays down with Steven. ââ¬Å"The storm torqued at the dividers as though to make them lock in. So unbending and frantic were every one of her muscles set, withstanding, that the room around her appeared to swim and reel.So inflexible and stressed that for alleviation finally, regar dless of herself, she raised her head and met his eyes once more. (page 209)â⬠In the interim, obscure to her, John is engaging the tempest to stay faithful to his obligation to come back to her. As Ann awakens a while later, the tempest gradually subsides, leaving a way of disappointment, blame, and wretchedness behind it. The blustery, segregated states of the setting and in her brain are the main impetus behind her nonsensical choice to lay down with Steven and the wretchedness that followed her decision. Disengagement can be the thinking behind madness and wretchedness, and in The Painted Door, there are no exceptions.Annââ¬â¢s internal clash causing her to pick between her significant other and Steven, the dejection of the setting that appeared to trap her, and the tempest that represented the considerations and feelings within her were all types of disconnection that drove Ann to silly activities. Had she halted to consider where her considerations were going, maybe An n would not have let her separation influence her sanity. At that point John would even now be alive and she would not feel the blame, wretchedness, and forlornness that followed her choice.
Thursday, July 16, 2020
Book Riots Deals of the Day for February 5th, 2018
Book Riots Deals of the Day for February 5th, 2018 Book Riot Deals is sponsored today by All the Women in My Family Sing: Women Write the World: Essays on Equality, Justice, and Freedom edited by Deborah Santana: Todays Featured Deals The Lady and the Unicorn by Tracy Chevalier for $1.99. Get it here, or just click the cover image below: The Sense of an Ending by Julian Barnes for $1.99. Get it here, or just click the cover image below: In Case You Missed Yesterdays Most Popular Deal Strange Weather by Joe Hill for $3.99. Get it here, or just click the cover image below: Previous daily deals that are still active (as of this writing at least). Get em while theyre hot. Daughter of the Pirate King by Tricia Levensell for $2.99. Doc by Mary Doria Russell for $1.99. On Beauty by Zadie Smith for $1.99. Year of Wonders by Geraldine Brooks for $1.99. Dear Martin by Nic Stone for $1.99. Binti by Nnedi Okorafor for $3.99. The Narrow Road to the Deep North by Richard Flanagan for $2.99. Goodbye, Vitamin by Rachel Khong for $2.99. Purple Hibiscus by Chimamanda Ngozi Adiche for $1.99. The Lacuna by Barbara Kingsolver for $2.99. Life After Life by Kate Atkinson for $1.99. We Are the Change We Seek: The Speeches of Barack Obama for $1.99. The Liars Club by Mary Karr for $1.99. Fledgling by Octavia E. Butler for $1.99. Every Heart a Doorway by Seanan McGuire for $2.99. The Nature of the Beast by Louise Penny for $2.99. The Great Movies by Roger Ebert for $1.99. Someday, Someday Maybe by Lauren Graham for $1.99. The Fever by Megan Abbott for $2.99. Stitches by Anne Lamott for $2.99. Modern Girls by Jennifer S. Brown for $1.99. Trigger Warning by Neil Gaiman for $2.99. Dust Tracks on a Road by Zora Neale Hurston for $2.99. The Killer Angels by Michael Shaara for $1.99. The Serpent King by Jeff Zentner for $1.99. Infomocracy by Malka Older for $1.99. The Darkest Part of the Forest by Holly Black for $2.99. The Sudden Appearance of Hope by Clare North for $2.99. The Unexpected Inheritance of Inspector Chopra by Vaseem Khan for $2.99. The Wife by Meg Wolitzer for $1.99. The Bookseller by Cynthia Swanson for $2.99. Pages for Her by Sylvia Brownrigg for $3.99. Shrill by Lindy West for $2.99. Lets Pretend This Never Happened by Jenny Lawson for $1.99. This Is Where I Leave You by Jonathan Tropper for $1.99. As You Wish by Cary Elwes for $1.99. The Invisible Library by Genevieve Cogman for $2.99. The Bedlam Stacks by Natasha Pulley for $2.99. Seraphina by Rachel Hartman for $1.99. Year of Yes by Shonda Rhimes for $1.99. The Little Book of Mindfulness by Patrizia Collard for $1.99. Bitch Planet, Vol 1 for $3.99. Monstress, Vol 1 by Liu Takeda for $3.99 Paper Girls, Vol 1. by Vaughn, Chiang, Wilson for $3.99. The Wicked + The Divine Volume 1 for $3.99 The Inheritance Trilogy by N.K. Jemisin for $9.99 The Price of Salt by Patricia Highsmith for $0.99 We Should All Be Feminists by Chimamanda Ngozi Adichie for $4.99 Sign up for our Book Deals newsletter and get up to 80% off books you actually want to read.
Thursday, May 21, 2020
The Meditation Health Benefits Of The World - 1102 Words
Mediation is an ancient method that practices deep concentration of the mind and it has recently made its way back into our modern society. By participating in the age old activity one opens their mental and physical wellbeing to multiple benefits. ââ¬Å"It did to my mind what going to the gym did to my bodyâ⬠said Dr. Hedy Kober, a neuroscientist who studies the effects of meditation, ââ¬Å"it made it both stronger and more flexible.â⬠(Meditation Health Benefits). Meditation is a practice that may train oneââ¬â¢s mind to be at a state of consciousness and wholeness. Throughout history Buddhist monks and other eastern religions have been utilizing this practice for religious purposes, however recently individuals have been testing it out for themselves. One does not have to mediate for religious purposes, this phnaoman can be used to lower stress levels, cure anxiety and panic disorders, learn to handle stressful situations better, and help to control anxiety, sharpen oneââ¬â¢s mind, improve memory and critical thinking and reverse depression. The Buddhist religion is what shined the light on the process of mediation from the start. Buddha, the head of the Buddhist religion, first began to spread his teachings in 500 B.C (Iml.jou.ufl.edu). His teachings did not begin to educate the rest of the world until the mid 20th century (Iml.jou.ulf.edu). After Buddhaââ¬â¢s teachings became more widespread other religions begun to incorporate different forms of mediation into their own teachings as wellShow MoreRelatedIsabella Vigil . Mr.Short . College Composition . 19 March848 Words à |à 4 PagesComposition 19 March 2017 A Spiritual Gain but a Financial Lose Meditation has always been seen as a way to keep the mind and soul healthy. Mediation dates back to 1500 BCE originating in Ancient India. The practice soon started to expand and adapt to other cultures around the world. Some of the earliest references to meditation are found in the Hindu scriptures and it was around the 6th to 5th centuries that other forms of meditation developed into Confucian, Taoist China, and Buddhist India (Taham)Read MoreMindfulness Meditation ( Mm )1528 Words à |à 7 Pagesdecade scientific interest in meditation and mindfulness has bloomed like a lotus flower. There are numerous studies demonstrating various positive outcomes of mindfulness meditation (MM). But, what is mindfulness? What are the mechanisms behind MM that help facilitate these positive outcomes including improved physical health, psychological well-being, and cognition? The concept of mindfulness has its roots in Buddhist philosophy and is a key element of Buddhist meditation practices. T he word mindfulnessRead MoreEssay on The Benefits of Yoga Meditation1570 Words à |à 7 PagesThe Benefits of Yoga and Meditation In todayââ¬â¢s environment, many people are suffering with the stress and anxiety of day to day living and are finding themselves unable to cope with lifeââ¬â¢s little emergencies. Prescription drugs are on the rise due to the increasing need for people to deal with their stress and anxiety. However, many people are searching for ways to be less stressed and live a happy and healthy life without drugs. If stress and anxiety are getting the best of you, then think aboutRead MoreTransform Your Life With Yoga And Meditation1403 Words à |à 6 PagesTransform Your Life with Yoga And Meditation! MariaJohnson By MariaJohnson May 2, 2013 Yoga and meditation have been a crucial part of history. If you think yoga is about twisting and bending your body, then it s time to see it in a new light. In simpler form it is a combination of asanas, pranayamas, and meditation. Yoga and meditation are two important aspects that complement each other. Meditation is a crucial part of yoga sessions and one of its five principles; after-all being mentally fitRead MoreThe Psychology Of The Geriatric Population864 Words à |à 4 Pagesaged 65 years or older are referred to as the geriatric population. This population is the fastest growing population in the world; in fact, the current number of seniors in the U.S. exceeds 40 million. As people live longer, the elderly population is expected to reach 72 million by 2030. Medical professionals receive very little training when it comes to the mental health of seniors, which is concerning since the age group with the highest rate of suicide is the geriatric population. CaregiversRead More Meditation On The Practice Of Meditation1075 Words à |à 5 PagesThroughout centuries, meditation has been utilized for spiritual guidance. Meditation is often practiced within quiet rooms, where one cannot be disturbed. In the recent years, meditation has expanded beyond the homes of individuals. Schools across the nation have begun researching the benefits of meditation on students. The practice of meditation in schools has been shown to promote positive behavior in students; therefore it should be implemented in schools. The practice of meditation can be definedRead More Transcendental Meditation: Alternative Therapy for Alcohol Abuse1402 Words à |à 6 PagesTranscendental Meditation: Alternative Therapy for Alcohol Abuse Proponents of the Transcendental Meditation program initiated by Maharishi Mahesh Yogi have expressed their ideas in various web sites on the World Wide Web, through pages such as The Transcendental Meditation Program at http://www.tm.org and the Scientific Research on Transcendental Meditation and TM-Sidhi program of the Maharishi University of Management at http://www.miu.edu/TM_Research. In these sites positive messages areRead MoreThe Benefits of Complementary and Alternative Medicine Essay1495 Words à |à 6 PagesIn todayââ¬â¢s world, many people assume that the latest medical technology and treatments are always the best option. However, all over the world, different techniques for curing diseases and aliments are being used. These methods fall under the category of complementary and alternative medicine. According to Sandra Augustyn Lawton in Complementary and Alternative Medicine for Teens, complementary and alternative medicine (CAM) can be defined as ââ¬Å"a group of diverse medical and health care systems,Read MoreFive Simple Mindfulness Skills That Work Essay1008 Words à |à 5 Pagesthis article on Digg Share this article on Reddit Share this article on Pinterest Expert Author Debra Burdick Mindfulness meditation consists of skills and methods to unplug from the busy world around you and from the busy monkey brain so often experienced in today s life and particularly in ADHD, anxiety and depression. According to Jon Kabat-Zinn, mindfulness meditation trains and reinforces the ability to pay attention to the present moment, on purpose which helps to increase concentrationRead MoreExploring the Practices and Types of Meditation1479 Words à |à 6 Pagessimply, Meditation is the practice of deep concentration of the mind. The practice involves either altered state of mind or relaxed state of body. Meditation has been around for thousands of years. Evidence of the practice can be found throughout history in many different religions and many different places in the world. In the past decades, the practice has gained new popularity in the world for its physical, psychological and spiritual benefits. Many people have tried and felt the benefit, then they
Wednesday, May 6, 2020
Discernment Therapy Getting The Conversation - 1521 Words
Discernment Therapy: Getting the Conversation Started I had the privilege of attending the discernment training provided by the NHAMFT on October 2, 2015. I was astounded to learn that 30% of couples entering into coupleââ¬â¢s therapy are mixed-agenda couples (Doherty, 2011). According to the speaker, Rachel Zamore (2015), mixed-agenda couples are unsuccessful with coupleââ¬â¢s therapy because they are ââ¬Å"half-hearted.â⬠Meaning one person is ââ¬Å"leaning inâ⬠and one person is ââ¬Å"leaning outâ⬠of the relationship. She continued to explain that because therapists lacked the models and protocols to deal with these couples, they were literally falling through the cracks due to the lack of effective support. Judge Bruce Peterson of the Minnesota Hennepin County Family Court was a direct witness to mixed-agenda couples and to the inertia of divorce once the process had begun. He approached Professor Bill Doherty of the University of Minnesota with an idea to create a ââ¬Å"rest stopâ⬠for couples considering divorce. In doing so, these couples would be given the time to really consider if divorce was what they wanted, or if reconciliation was a possible option. From this one idea, and the ingenuity and creativity of two brilliant men the Minnesota Couples on the Brink Project was developed and discernment therapy was born (ââ¬Å"About the Project,â⬠2013). Discernment counseling helps couples to figure out and understand what has happened to their marriage so they can gain a greater understanding,Show MoreRelatedInstructions Up For Three Questions Prompt Essay2346 Words à |à 10 Pagescontent under the Week 1 Lectures / Presentations content area. This video is by Fr. Michael Himes, a theologian at Boston College. Prompt #1: Take a moment to respond meaningfully to the ââ¬Å"three questionsâ⬠that are discussed as key to vocational discernment, and provide any additional perspective that you may feel is necessary. Donââ¬â¢t just settle for short, one sentence answers. Try to be very specific, aiming for a couple of cohesive, well-written paragraphs in response to each of the three questionsRead MoreMarriage Guidance: Summary Notes19959 Words à |à 80 Pagesfamily of origin. âËâ Racism âËâ Sexism âËâ Classism âËâ Homophobia âËâ Genetic makeup, abilities, disabilities âËâ Family emotional patterns âËâ No time for friends, inflexibility of work place Horizontal stressors ââ â Predictable life cycle transitions: Getting married, Having a baby, Losing oneââ¬â¢s partner ââ â Unexpected ââ¬â illness, accidents, retrenchments ââ â Historical events ââ¬â war, natural disasters, political climate ââ â These generate high or low points in the couples life line System level stressors Read MoreUnderstand Person-Centred Approaches in Adult Social Care Settings12139 Words à |à 49 Pagesindividualââ¬â¢s care plan contributes in a person centred way Care Plans are the primary source of Patient information. Every specialty, PT/OT/Nursing etc. do an evaluation of the individual and formulate a program of goals for the patient to attain, therapies needed, schedule of goal levels, etc. Each person interacting with the patient can refer to the care plan for any information needed. Done properly, the care plan reflects a total person and how to best help them fulfil the goals. A care plan may
Java Based Search Engine Free Essays
string(97) " on coming up with solutions that serve customer requirements today and anticipate future needs\." ACKNOWLEDGMENT I express thanks and gratitude to Mr. â⬠¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦H. O. We will write a custom essay sample on Java Based Search Engine or any similar topic only for you Order Now D computer science department, â⬠¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦College for his encouraging support and guidance in carrying out the project. I would like to express gratitude and indebtedness to Mrâ⬠¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦, for his valuable advice and guidance without which this project would not have seen the light of the day. I thank Mrâ⬠¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦ , project guide , GSS for his insistence on good programming technique which helped us to design and develop a successful model of an Chatting Tool. Name CONTENTS 1. STUDY ANALYSIS PHASE 1. 1 INTRODUCTION 1. 1. 1 PURPOSE OF THE PROJECT 1. 1. 2 PROBLEM IN EXISTING SYSTEM 1. 1. 3 SOLUTION OF THESE PROBLEMS 1. 1. 4 SCOPE OF THE PROJECT 1. 1. 5 LIMITATIONS 1. 1. 6 HARDWARE SOFTWARE SPECIFICATIONS 1. 1. 7 ORGANISATION PROFILE 2. PROJECT ANALYSIS 1. STUDY OF THE SYSTEM 2. INPUT OUTPUT 3. PROCESS MODULES USED WITH JUSTIFICATION 3. DESIGN PHASE 1. DATAFLOW 2. UML DIAGRAMS 4. IMPLEMENTATION PHASE 5. TESTING 1. TYPES OF TESTING 1. COMPILING TEST 2. EXECUTION TEST 3. OUTPUT TEST 5. PROJECT CODING 6. OUTPUT SCREENS 7. CONCLUSION 8. BIBLOGRAPHY STUDY PHASE INTRODUCTION: EXISTING SYSTEM With the advent of the Internet in the past decade, searching for information in various formats has been redefined by the internet search engines, most of them being based on information retrieval (IR) indexing techniques. IR-based searching, which usually allows formulation of queries with multiple words PROPOSED SYSTEM This Java application is basically a recursive file finder. You can search for files based on their filename, their contents, or both in selected directory and as well as sub directories of the specified directory. Engine is a graphical version of the well-known GREP utility, with an additional feature of traversing subdirectories. You can specify which directory to start looking in, which files to search through, and what pattern to look for in the files. The various fields expect regular expressions, like Global Regular Expression, ââ¬ËEngineââ¬â¢ has not only the graphical interface, but also a command-line interface. This is useful for quick searches through, say, a development tree. Engine requires the Java 2 Platform, Standard Edition version 1. 4 or higher. SOLUTION OF THESE PROBLEMS Regular expressions figure into all kinds of text-manipulation tasks. Searching and search-and-replace are among the more common uses, but regular expressions can also be used to test for certain conditions in a text file or data stream. You might use regular expressions, for example, as the basis for a short program that separates incoming mail from incoming spam. In this case, the program might use a regular expression to determine whether the name of a known spammer appeared in the ââ¬Å"From:â⬠line of the email. Email filtering programs, in fact, very often use regular expressions for exactly this type of operation. SCOPE OF THE PROJECT Engine is a graphical version of the well-known GREP utility, with an additional feature of traversing subdirectories. The main aim of this project is to develop a java based recursive file finder. Engine is a graphical version of the well-known GREP utility, with an additional feature of traversing subdirectories LIMITATIONS Regular expressions tend to be easier to write than they are to read. This is less of a problem if you are the only one who ever needs to maintain the program (or sed routine, or shell script, or what have you), but if several people need to watch over it, the syntax can turn into more of a hindrance than an aid. Ordinary macros (in particular, editable macros such as those generated by the major word processors and editors) tend not to be as fast, as flexible, as portable, as concise, or as fault-tolerant as regular expressions, but they have the advantage of being much more readable; even people with no programming background whatsoever can usually make enough sense of a macro script to change it if the need arises. For some jobs, such readability will outweigh all other concerns. As with all things in computing, itââ¬â¢s largely a question of fitting the tool to the job. HARDWARE SOFTWARE SPECIFICATIONS Environment: Java Runtime Environment version 1. 4 or better installed. Operating System: Any O. S. compatable with JVM Hard disk:10 GB Processor:PIII or higher ORGANIZATION PROFILE EMINENT SOFTWARE SOLUTIONS EMINENT TECHNOLOGIES (ET) is an IT Solution Provider for a dynamic environment where business and technology strategies converge. Our approach focuses on new ways of business combining IT innovation and adoption while also leveraging an organizationââ¬â¢s current IT assets. We work with large global corporations and new generation technology companies ââ¬â to build new products or services and to implement prudent business and technology strategies in todayââ¬â¢s environment. EMINENTââ¬â¢s range of expertise includes: Software Development Services Engineering Services Systems Integration Customer Relationship Management Supply Chain Management Product Development Electronic Commerce Consulting IT Outsourcing We apply technology with innovation and responsibility to achieve two broad objectives: Effectively address the business issues our customers face today Generate new opportunities that will help them stay ahead in the future This approach rests on: A strategy where we Architect, Integrate and Manage technology services and solutions ââ¬â we call it AIM for success. A robust offshore development methodology and reduced demand on customer resources A focus on the use of reusable frameworks to provide cost and time benefits We combine the best people, processes and technology to achieve excellent results consistently. We offer customers the advantages of: Speed: We understand the importance of timing, of getting there before the competition. A rich portfolio of reusable, modular frameworks helps jump start projects. Tried and tested methodology ensures that we follow a predictable, low-risk path to achieve results. Our track record is testimony to complex projects delivered within and even before schedule. Expertise: Our teams combine cutting edge technology skills with rich domain expertise. Whatââ¬â¢s equally important ââ¬â we share a strong customer orientation that means we actually start by listening to the customer. Weââ¬â¢re focused on coming up with solutions that serve customer requirements today and anticipate future needs. You read "Java Based Search Engine" in category "Essay examples" A Full Service Portfolio: We offer customers the advantage of being able to Architect, Integrate and Manage technology services. This means that they can rely on one, fully accountable source instead of trying to integrate disparate multi-vendor solutions. Services: GSS is providing its services to Sain medicaments Pvt. Ltd, Grace drugs and pharmaceuticals Private Limited Alka Drugs and Pharmaceuticals Pvt Ltd to name just a few with out rich experience and expertise in Information Technology we are in the best position to provide software solutions to distinct business requirements. PROJECT ANALYSIS STUDY OF THE SYSTEM This application can be mainly divided into two modules:- â⬠¢ User Interface â⬠¢ File Manipulation and filtering INPUT AND OUTPUT: User has to input the File Name or File Contents and he has to select the Drive or Directory in which searching has to be done. Application will search for the files matching with given criteria and shows the output in the text area of the application. PROCESS MODEL USED WITH JUSTIFICTION The model used here is a SPIRAL MODEL. This Model demands a direct consideration of technical risk at all stages of the project and if properly applied it reduces risk before they become problematic, hence it becomes easier to handle a project when using this kind of model where in the end user can evaluate the program at the end of each stage and suggest modification if required. PROJECT DESIGN DATA FLOW DIAGRAM 0th Level 1st Level 2nd Level 2nd Level 3rd Level UML DIAGRAMS USE CASE DIAGRAM [pic] CLASS DIAGRAM [pic] ACTIVITY DIAGRAM [pic] SEQUENCE DIAGRAM [pic] IMPLEMENTATION PHASE MODULES: 1. COMPONENT THIS IS THE FRONT END CONSOLE OF THE USER TO INTERACT WITH SEARCH ANALYZER. 2. TOOLBAR COORDINATIOR THIS MODULE HAS THE EMBEDED TOOLS WHICH ARE TO IMPLEMENT SEARCH. 3. MAP FINDER THIS MODULE IS MAPS THE SEARCH CORRESPONDING TO THE USERS QUERY. 4. DYNAMIC STATUS FINDER THIS IS THE DYNAMIC MODULE WHICH GIVES THE STATUS OF THE SEARCH . 5. GREP GENERATOR GREP GENERATOR IS THE MAJOR MODULE ON WHICH THE SEARCH IS DONE BASED ON REGULAR EXPRESSIONS . OUTPUT SCREENS Engine view [pic] Browse [pic] Search [pic] Help [pic] Error [pic] PROJECT CODING CODE EXPLANATION Regular expressions simplify pattern-matching code Discover the elegance of regular expressions in text-processing scenarios that involve pattern matching Text processing often involves matching text against a pattern. Although Javaââ¬â¢s character and assorted string classes offer low-level pattern-matching support, that support commonly leads to complex code. To help you write simpler pattern-matching code, Java provides regular expressions with java. util. regex package. Text processing frequently requires code to match text against patterns. That capability makes possible text searches, email header validation, custom text creation from generic text (e. g. , ââ¬Å"Dear Mr. Chakradharâ⬠instead of ââ¬Å"Dear Customerâ⬠), and so on. Java supports pattern matching via its character and assorted string classes. Because that low-level support commonly leads to complex pattern-matching code, Java also offers regular expressions to help you write simpler code. After introducing regular expression terminology, the java. util. regex packageââ¬â¢s classes, and a program that demonstrates regular expression constructs, I explore many of the regular expression constructs that the Pattern class supports. I also examine the methods comprising Pattern and other java. util. regex classes. A practical application of regular expressions concludes my discussion. Regular expressionsââ¬â¢ long history begins in the theoretical computer science fields of automata theory and formal language theory. That history continues to Unix and other operating systems, where regular expressions are often used in Unix and Unix-like utilities: examples include awk (a programming language that enables sophisticated text analysis and manipulation-named after its creators, Aho, Weinberger, and Kernighan), emacs (a developerââ¬â¢s editor), and grep (a program that matches regular expressions in one or more text files and stands for global regular expression print). Regular expressions trace back to the work of an American mathematician by the name of Stephen Kleene (one of the most influential figures in the development of theoretical computer science) who developed regular expressions as a notation for describing what he called ââ¬Å"the algebra of regular sets. â⬠His work eventually found its way into some early efforts with computational search algorithms, and from there to some of the earliest text-manipulation tools on the Unix platform (including ed and grep). In the context of computer searches, the ââ¬Å"*â⬠is formally known as a ââ¬Å"Kleene star. ââ¬Å" A regular expression, also known as a regex or regexp, is a string whose pattern (template) describes a set of strings. The pattern determines what strings belong to the set, and consists of literal characters and meta characters, characters that have special meaning instead of a literal meaning. The process of searching text to identify matchesââ¬âstrings that match a regexââ¬â¢s patternââ¬âis pattern matching. Javaââ¬â¢s java. util. regex package supports pattern matching via its Pattern, Matcher, and PatternSyntaxException classes: 1. Pattern objects, also known as patterns, are compiled regexes 2. Matcher objects, or matchers, are engines that interpret patterns to locate matches in character sequences, objects whose classes implement the java. lang. CharSequence interface and serve as text sources 3. PatternSyntaxException objects describe illegal regex patterns Code for mainwindow package jog. engine; import java. awt. *; import java. awt. event. *; import java. io. *; import java. net. URL; import java. util. prefs. *; import java. util. regex. *; import javax. swing. *; import javax. swing. filechooser. FileFilter; import jog. engine. *; public class MainWindow extends JFrame implements ActionListener, FileSearchListener { rotected Preferences preferences; protected JTextField lookInField; protected JTextField filePatternField; protected JTextField searchForField; protected JTextField excludeField; protected JCheckBox includeSubCheckBox; protected JList resultList; protected RunSearch runner; protected JButton browseButton; protected JButton helpButton; protected JButton s tartButton; protected JButton stopButton; protected JButton closeButton; protected JLabel status; protected JPanel cardPanel; protected CardLayout cardLayout; private boolean stopFlag; public MainWindow() { super(Bundle. getString(ââ¬Å"AppTitleâ⬠)); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent event) { handleClose(); } }); preferences = Preferences. userRoot(). node(ââ¬Å"com/bluemarsh/jrgrepâ⬠); Container pane = getContentPane(); GridBagLayout gb = new GridBagLayout(); pane. setLayout(gb); GridBagConstraints gc = new GridBagConstraints(); gc. insets = new Insets(3, 3, 3, 3); JLabel label = new JLabel(Bundle. getString(ââ¬Å"lookInLabelâ⬠)); gc. anchor = GridBagConstraints. EAST; gb. setConstraints(label, gc); pane. add(label); String s = preferences. get(ââ¬Å"lookInâ⬠, ââ¬Å"â⬠); lookInField = new JTextField(s, 20); gc. anchor = GridBagConstraints. WEST; gc. fill = GridBagConstraints. HORIZONTAL; gc. weightx = 1. 0; gb. setConstraints(lookInField, gc); pane. add(lookInField); browseButton = new JButton(Bundle. getString(ââ¬Å"browseLabelâ⬠)); browseButton. addActionListener(this); gc. anchor = GridBagConstraints. CENTER; gc. gridwidth = GridBagConstraints. REMAINDER; gc. fill = GridBagConstraints. NONE; gc. weightx = 0. 0; gb. setConstraints(browseButton, gc); pane. add(browseButton); label = new JLabel(Bundle. getString(ââ¬Å"filePatternLabelâ⬠)); gc. anchor = GridBagConstraints. EAST; gc. gridwidth = 1; gb. setConstraints(label, gc); pane. add(label); s = preferences. get(ââ¬Å"filterâ⬠, ââ¬Å"â⬠); ilePatternField = new JTextField(s, 20); gc. anchor = GridBagConstraints. WEST; gc. fill = GridBagConstraints. HORIZONTAL; gc. gridwidth = GridBagConstraints. RELATIVE; gc. weightx = 1. 0; gb. setConstraints(filePatternField, gc); pane. add(filePatternField); Component glue = Box. createGlue(); gc. anchor = GridBagConstraints. CENTER; gc. fill = GridBagConstraints. NONE; gc. gridwidth = GridBagConstraints. REMAINDER; gc. weightx = 0. 0; gb. setConstraints(glue, gc); pane. add(glue); label = new JLabel(Bundle. getString(ââ¬Å"searchForLabelâ⬠)); gc. anchor = GridBagConstraints. EAST; gc. fill = GridBagConstraints. NONE; gc. gridwidth = 1; gb. setConstraints(label, gc); pane. add(label); s = preferences. get(ââ¬Å"searchForâ⬠, ââ¬Å"â⬠); searchForField = new JTextField(s, 20); gc. anchor = GridBagConstraints. WEST; gc. fill = GridBagConstraints. HORIZONTAL; gc. gridwidth = GridBagConstraints. RELATIVE; gc. weightx = 1. 0; gb. setConstraints(searchForField, gc); pane. add(searchForField); helpButton = new JButton(Bundle. getString(ââ¬Å"helpLabelâ⬠)); helpButton. addActionListener(this); gc. anchor = GridBagConstraints. CENTER; gc. fill = GridBagConstraints. NONE; gc. gridwidth = GridBagConstraints. REMAINDER; gc. weightx = 0. 0; gb. etConstraints(helpButton, gc); pane. add(helpButton); label = new JLabel(Bundle. getString(ââ¬Å"excludeLabelâ⬠)); gc. anchor = GridBagConstraints. EAST; gc. gridwidth = 1; gb. setConstraints(label, gc); pane. add(label); s = preferences. get(ââ¬Å"excludeâ⬠, ââ¬Å"â⬠); excludeField = new JTextField(s, 20); gc. anchor = GridBagCon straints. WEST; gc. fill = GridBagConstraints. HORIZONTAL; gc. gridwidth = GridBagConstraints. RELATIVE; gc. weightx = 1. 0; gb. setConstraints(excludeField, gc); pane. add(excludeField); glue = Box. createGlue(); gc. anchor = GridBagConstraints. CENTER; gc. fill = GridBagConstraints. NONE; gc. ridwidth = GridBagConstraints. REMAINDER; gc. weightx = 0. 0; gb. setConstraints(glue, gc); pane. add(glue); includeSubCheckBox = new JCheckBox( Bundle. getString(ââ¬Å"includeSubDirLabelâ⬠), true); includeSubCheckBox. setSelected(preferences. getBoolean( ââ¬Å"recurseâ⬠, true)); gc. anchor = GridBagConstraints. WEST; gb. setConstraints(includeSubCheckBox, gc); pane. add(includeSubCheckBox); startButton = new JButton( Bundle. getString(ââ¬Å"startSearchLabelâ⬠)); startButton. addActionListener(this); gc. gridwidth = 1; gb. setConstraints(startButton, gc); pane. add(startButton); status=new JLabel(ââ¬Å"â⬠); Color c=new Color(240,100,100); tatus. setForeground(c); gc. g ridwidth = 1; gb. setConstraints(status, gc); pane. add(status); stopButton = new JButton(Bundle. getString(ââ¬Å"stopLabelâ⬠)); stopButton. setEnabled(false); stopButton. addActionListener(this); gc. anchor = GridBagConstraints. CENTER; gc. gridwidth = GridBagConstraints. RELATIVE; gb. setConstraints(stopButton, gc); pane. add(stopButton); closeButton = new JButton(Bundle. getString(ââ¬Å"closeLabelâ⬠)); closeButton. addActionListener(this); gc. gridwidth = GridBagConstraints. REMAINDER; gb. setConstraints(closeButton, gc); pane. add(closeButton); resultList = new JList(new ResultsListModel()); JScrollPane scroller = new JScrollPane(resultList); cardPanel = new JPanel(new CardLayout()); cardLayout = (CardLayout) cardPanel. getLayout(); cardPanel. add(scroller, ââ¬Å"listâ⬠); gc. gridwidth = GridBagConstraints. REMAINDER; gc. gridheight = GridBagConstraints. REMAINDER; gc. fill = GridBagConstraints. BOTH; gc. weightx = 1. 0; gc. weighty = 1. 0; gb. setConstraints(cardPanel, gc); pane. add(cardPanel); int width = preferences. getInt(ââ¬Å"windowWidthâ⬠, 0); int height = preferences. getInt(ââ¬Å"windowHeightâ⬠, 0); if (width == 0 height == 0) { pack(); } else { setSize(width, height); } int top = preferences. getInt(ââ¬Å"windowTopâ⬠, 100); nt left = preferences. getInt(ââ¬Å"windowLeftâ⬠, 100); setLocation(left, top); stopFlag=false; } public void actionPerformed(ActionEvent event) { JButton button = (JButton) event. getSource(); //System. out. println(ââ¬Å"action ââ¬Å"+button); if (button == closeButton) { handleClose(); } else if (button == browseButton) { handleBrowse(); } else if (button == startButton) { status. setText(ââ¬Å"Search Startedâ⬠); //System. out. println(ââ¬Å"Search startedâ⬠); startSearch(); } else if (button == helpButton) { displayHelp(); } else if (button == stopButton) { //System. out. println(ââ¬Å"Search stoppedâ⬠); stopButton. setEnabled(false); runner. stop(); stopFlag=true; /int count=((ListModel)resultList. getModel()). getSize(); //status. setText(ââ¬Å"Search Stopped ââ¬Å"+count+â⬠Files Foundâ⬠); } } protected void displayHelp() { if (cardPanel. getComponentCount() 2) { URL helpUrl = Bundle. getResource(ââ¬Å"helpFileâ⬠); try { JEditorPane editor = new JEditorPane(helpUrl); editor. setEditable(false); JScrollPane scroller = new JScrollPane(editor); cardPanel. add(scroller, ââ¬Å"helpâ⬠); } catch (IOException ioe) { searchFailed(ioe); return; } } cardLayout. show(cardPanel, ââ¬Å"helpâ⬠); } public void fileFound(FileFoundEvent event) { R esultsListModel model = (ResultsListModel) resultList. etModel(); model. addElement(event. getFile()); } protected void handleBrowse() { String dirStr = lookInField. getText(); JFileChooser fc; if (dirStr. equals(ââ¬Å"â⬠)) { String lastdir = preferences. get(ââ¬Å"lastdirâ⬠, null); if (lastdir == null || lastdir. length() == 0) { lastdir = System. getProperty(ââ¬Å"user. dirâ⬠); } fc = new JFileChooser(lastdir); } else { fc = new JFileChooser(dirStr); } fc. setFileSelectionMode(JFileChooser. DIRECTORIES_ONLY); if (fc. showOpenDialog(this) ! = JFileChooser. CANCEL_OPTION) { File dir = fc. getSelectedFile(); String path = dir. getPath(); lookInField. setText(path); references. put(ââ¬Å"lastdirâ⬠, path); } } protected void handleClose() { preferences. putInt(ââ¬Å"windowTopâ⬠, getY()); preferences. putInt(ââ¬Å"windowLeftâ⬠, getX()); preferences. putInt(ââ¬Å"windowWidthâ⬠, getWidth()); preferences. putInt(ââ¬Å"windowHeightâ⬠, getHeigh t()); preferences. put(ââ¬Å"lookInâ⬠, lookInField. getText()); preferences. put(ââ¬Å"filterâ⬠, filePatternField. getText()); preferences. put(ââ¬Å"searchForâ⬠, searchForField. getText()); preferences. put(ââ¬Å"excludeâ⬠, excludeField. getText()); preferences. putBoolean(ââ¬Å"recurseâ⬠, includeSubCheckBox. isSelected()); System. exit(0); } public void searchComplete() { stopButton. etEnabled(false); //status. setText(ââ¬Å"Search completedâ⬠); int count=((ListModel)resultList. getModel()). getSize(); if(count==0){ status. setText(ââ¬Å"Search Completed No Files Foundâ⬠); } if(stopFlag){ status. setText(ââ¬Å"Search Stopped ââ¬Å"+count +â⬠Files Foundâ⬠); stopFlag=false; }else{ status. setText(ââ¬Å"Search Completed ââ¬Å"+count +â⬠Files Foundâ⬠); } } public void searchFailed(Throwable t) { Object[] messages = {Bundle. getString(ââ¬Å"exceptionOccurredâ⬠),t. getMessage()}; JOptionPane. showMessageDialog(thi s, messages, Bundle. getString(ââ¬Å"errorTitleâ⬠), JOptionPane. ERROR_MESSAGE); } protected void startSearch() { cardLayout. how(cardPanel, ââ¬Å"listâ⬠); ResultsListModel model = (ResultsListModel) resultList. getModel(); model. clear(); String dirStr = lookInField. getText(); if (dirStr == null || dirStr. length() == 0) { dirStr = ââ¬Å". ââ¬Å"; } File dir = new File(dirStr); if (! dir. exists()) { JOptionPane. showMessageDialog(this, Bundle. getString(ââ¬Å"pathDoesNotExistâ⬠), Bundle. getString(ââ¬Å"errorTitleâ⬠), JOptionPane. ERROR_MESSAGE); return; } String target = searchForField. getText(); String filter = filePatternField. getText(); String exclude = excludeField. getText(); try { Pattern. compile(target); Pattern. compile(filter); Pattern. ompile(exclude); } catch (PatternSyntaxException pse) { Object[] messages = {Bundle. getString(ââ¬Å"invalidRegexPatternâ⬠), pse. getMessage()}; JOptionPane. showMessageDialog(this, messages, Bundle. ge tString(ââ¬Å"errorTitleâ⬠),JOptionPane. ERROR_MESSAGE); return; } if (runner == null) { runner = new RunSearch(this); } runner. search(dir, target, filter, includeSubCheckBox. isSelected(), exclude); Thread th = new Thread(runner); th. start(); stopButton. setEnabled(true); } } Code for bundle package jog. engine; import java. net. URL; import java. util. MissingResourceException; import java. til. ResourceBundle; public class Bundle { private static ResourceBundle resourceBundle; static { resourceBundle = ResourceBundle. getBundle(Bundle. class. getName()); } public static ResourceBundle getBundle() { return resourceBundle; } public static URL getResource(String key) { String name = getString(key); return name == null ? null : Bundle. class. getResource(name); } public static String getString(String key) { try { return resourceBundle. getString(key); } catch (MissingResourceException mre) { return null; } } } Code for runsearch package jog. engine; import java. io. File; imp ort jog. engine. *; mport java. lang. *; class RunSearch implements Runnable { protected File dir; protected String lookFor; protected String filter; protected boolean subDirs; protected String exclude; protected FileSearchListener listener; protected Searcher searcher; public RunSearch(FileSearchListener listener) { this. listener = listener; } public void run() { if (searcher == null) { searcher = new Searcher(); if (listener ! = null) { searcher. addSearchListener(listener); } } searcher. search(dir, lookFor, filter, subDirs, exclude); } public void search(File dir, String lookFor, String filter, boolean subDirs, String exclude) this. dir = dir; this. lookFor = lookFor; this. filter = filter; this. subDirs = subDirs; this. exclude = exclude; } public void stop() { //System. out. println(ââ¬Å"Searcher is one:â⬠+ isAlive()); System. out. println(ââ¬Å"Searcherâ⬠); if (searcher ! = null) { searcher. stopSearching(); searcher=null; System. out. println(ââ¬Å"Searcher on eâ⬠); } //System. out. println(ââ¬Å"Searcher is :â⬠+ isAlive()); //System. out. println(ââ¬Å"Searcher oneâ⬠); } } Code for searcher package jog. engine; import java. io. *; import java. nio. *; import java. nio. channels. *; import java. nio. charset. *; import java. util. *; import java. til. regex. *; import javax. swing. event. EventListenerList; import jog. engine. *; class Searcher { protected static Pattern linePattern; protected static Charset charset; protected static CharsetDecoder decoder; protected EventListenerList searchListeners; protected volatile boolean stopSearch; protected Pattern targetPattern; protected Matcher targetMatcher; protected Pattern filterPattern; protected Matcher filterMatcher; protected Pattern excludePattern; protected Matcher excludeMatcher; static { try { linePattern = Pattern. compile(ââ¬Å". * ? ââ¬Å"); } catch (PatternSyntaxException pse) { System. out. rintln(ââ¬Å"Ye flipping gods! ââ¬Å"); } charset = Charset. forName(ââ¬Å"ISO-8859-1â⬠); decoder = charset. newDecoder(); } public Searcher() { searchListeners = new EventListenerList(); } public void addSearchListener(FileSearchListener listener) { searchListeners. add(FileSearchListener. class, listener); } protected void fireDone() { if (searchListeners == null) { return; } Object[] listeners = searchListeners. getListenerList(); for (int i = listeners. length ââ¬â 2; i = 0; i -= 2) { if (listeners[i] == FileSearchListener. class) { FileSearchListener fsl = (FileSearchListener) listeners[i + 1]; fsl. earchComplete(); } } } protected void fireError(Throwable t) { if (searchListeners == null) { return; } Object[] listeners = searchListeners. getListenerList(); for (int i = listeners. length ââ¬â 2; i = 0; i -= 2) { if (listeners[i] == FileSearchListener. class) { FileSearchListener fsl = (FileSearchListen er) listeners[i + 1]; fsl. searchFailed(t); } } } protected void fireFound(String match) { if (searchListeners == null) { return; } FileFoundEvent event = new FileFoundEvent(this, match); Object[] listeners = searchListeners. getListenerList(); for (int i = listeners. ength ââ¬â 2; i = 0; i -= 2) { if (listeners[i] == FileSearchListener. class) { FileSearchListener fsl = (FileSearchListener) listeners[i + 1]; fsl. fileFound(event); } } event = null; } public void removeSearchListener(FileSearchListener listener) { searchListeners. remove(FileSearchListener. class, listener); } public void search(File startIn, String target, String filter, boolean recurse, String exclude) { stopSearch = false; try { targetPattern = Pattern. compile(target); filterPattern = Pattern. compile(filter); if (exclude ! = null exclude. length() 0) { excludePattern = Pattern. ompile(exclude); } searchLow(startIn, recurse); } catch (IOException ioe) { fireError(ioe); } catch (PatternSyntaxException pse) { fireError(pse); } targetPattern = null; targetMatcher = null; filterPattern = null; filterMatcher = null; excludePattern = null; excludeMatcher = null; fireDone(); } protected void searchLow(File startIn, boolean recurse) throws IOException { String[] files = startIn. list(); if (files == null) { return; } for (int ii = 0; ii files. length; ii++) { if (stopSearch) { break; } File file = new File(startIn, files[ii]); if (file. isFile() file. canRead()) { String filename = file. etCanonicalPath(); if (filterMatcher == null) { filterMatcher = filterPattern. matcher(filename); } else { filterMatcher. reset(filename); } if (! filterMatcher. find()) { continue; } FileInputStream fis = new FileInputStream(file); FileChannel fc = fis. getChannel(); MappedByteBuffer bb = fc. map(FileChannel. MapMode. READ_ONLY, 0, fc. size()); CharBuffer cb = decoder. decode(bb); boolean matchFound = false; if ((targetPattern. flags() Pattern. DOTALL) ! = 0) { if (targetMatcher == null) { targetMatcher = targetPattern. matcher(cb); } else { argetMatcher. reset(cb); } if (targetMatcher. find()) { matchFound = true; } } else { Matcher lm = linePattern. matcher(cb); while (lm. find()) { CharSequence cs = lm. group(); if (targetMatcher == null) { targetMatcher = targetPattern. matcher(cs); } else { targetMatcher. reset(cs); } if (targetMatcher. find()) { matchFound = true; } if (lm. end() == cb. limit()) { break; } } } if (matchFound) { fireFound(filename); } } else if (recurse file. isDirectory()) { String dirname = file. getName(); if (excludePattern ! = null) { if (excludeMatcher == null) { excludeMatcher = excludePattern. atcher(dirname); } else { excludeMatcher. reset(dirname); } if (! excludeMatcher. find()) { searchLow(file, recurse); } } else { searchLow(file, recurse); } } } } public void stopSearching() { stopSearch = true; } } Code for filesearch listener package jog. engine; import java. util. EventListener; import jog. engine. FileFoundEvent; interface FileSearchListener extends EventListener { public void fileFound(FileFoundEvent event); public void searchComplete(); public void searchFailed(Throwable t); } Code for tty package jog. engine; import java. io. *; import java. util. regex. *; mport jog. engine. *; public class tty implements FileSearchListener { protected static int argIndex; protected static String excludeStr = ââ¬Å"â⬠; protected static String nameStr = ââ¬Å"â⬠; protected static void displayHelp() { String str = Bundle. getString(ââ¬Å"ttyHelp1â⬠); int i = 1; while (str ! = null) { System. out. println(str); i++; str = Bundle. getString(ââ¬Å"ttyHelpâ⬠+ i); } } public void fileFound(FileFoundEvent event) { System. out. println(event. getFile()); } protected static boolean processArgs(String[] args) { while (argIndex args. length) { String arg = args[argIndex]; if (arg. equals(ââ¬Å"-excludeâ⬠)) { rgIndex++; excludeStr = args[argIndex]; } else if (arg. equals(ââ¬Å"-hâ⬠) || arg. equals(ââ¬Å"-h elpâ⬠) || arg. equals(ââ¬Å"ââ¬âhelpâ⬠)) { displayHelp(); return false; } else if (arg. equals(ââ¬Å"-nameâ⬠)) { argIndex++; nameStr = args[argIndex]; } else { break; } argIndex++; } return true; } public void searchComplete() {} public void searchFailed(Throwable t) { System. err. println(Bundle. getString(ââ¬Å"exceptionOccurredâ⬠)); System. err. println(t. getMessage()); } public static void main(String[] args) { try { if (! processArgs(args)) { return; } } catch (ArrayIndexOutOfBoundsException aioobe) { System. err. println(Bundle. etString(ââ¬Å"ttyMissingArgumentsâ⬠)); return; } if (argIndex == args. length) { System. err. println(Bundle. getString(ââ¬Å"ttyMissingRequiredâ⬠)); return; } String target = args[argIndex]; argIndex++; String dirStr = null; if (argIndex == args. length) { dirStr = ââ¬Å". ââ¬Å"; } else { dirStr = args[argIndex]; } File dir = new File(dirStr); if (! dir. exists()) { System. err. println(Bundle. getString(â⠬Å"pathDoesNotExistâ⬠)); return; } try { Pattern. compile(target); Pattern. compile(nameStr); } catch (PatternSyntaxException pse) { System. err. println(Bundle. getString(ââ¬Å"invalidRegexPatternâ⬠)); System. rr. println(pse. getMessage()); return; } Searcher searcher = new Searcher(); tty instance = new tty(); searcher. addSearchListener(instance); searcher. search(dir, target, nameStr, true, excludeStr); searcher. removeSearchListener(instance); } } Code for filefoundevent package jog. engine; import java. util. EventObject; class FileFoundEvent extends EventObject { protected String file; public FileFoundEvent(Object source, String file) { super(source); this. file = file; } public String getFile() { return file; } } Code for result list model package jog. engine; import java. util. Vector; import javax. wing. AbstractListModel; import jog. engine. *; class ResultsListModel extends AbstractListModel { protected Vector listData; public ResultsListModel() { listData = new Vector(); } public void addElement(Object o) { listData. add(o); fireIntervalAdded(this, listData. size(), listData. size()); } public void clear() { int size = listData. size(); listData. clear(); fireIntervalRemoved(this, 0, size); } public Object getElementAt(int i) { try { return listData. elementAt(i); } catch (ArrayIndexOutOfBoundsException e) { return null; } } public int getSize() { return listData. size(); } } Code for main package jog. ngine; import jog. engine. *; public class Main { public static void main(String[] args) { new MainWindow(). show(); // new jog. searchdesk. MainWindow. show(); } } For a tool with full regex support, metacharacters like ââ¬Å"*â⬠and ââ¬Å"? â⬠(or ââ¬Å"wildcard operators,â⬠as they are sometimes called) are only the tip of the iceberg. Using a good regex engine and a well-crafted regular expression, one can easily search through a text file (or a hundred text files) searching for words that have the suffix ââ¬Å". htmlâ⬠(but only if the word begins with a capital letter and occurs at the beginning of the line), replace the . tml suffix with a . sgml suffix, and then change all the lower case characters to upper case. With the right tools, this series of regular expressions would do just that: s/(^[A_Z]{1})([a-z]+). sgml/12. html/g tr/a-z/A-Z/ As you might guess from this example, concision is everything when it comes to crafting regular expressions, and while this syntax wonââ¬â¢t win any beauty prizes, it follows a logical and fairly standardized format which you can learn to rea+*d and write easily with just a little bit of practice. In a regular expression, everything is a generalized pattern. If I type the word ââ¬Å"serendipitousâ⬠into my editor, Iââ¬â¢ve created one instance of the word ââ¬Å"serendipitous. â⬠If, however, I indicate to my tool (or compiler, or editor, or what have you) that Iââ¬â¢m now typing a regular expression, I am in effect creating a template that matches all instances of the characters ââ¬Å"s,â⬠ââ¬Å"e,â⬠ââ¬Å"r,â⬠ââ¬Å"e,â⬠ââ¬Å"n,â⬠ââ¬Å"d,â⬠ââ¬Å"i,â⬠ââ¬Å"p,â⬠ââ¬Å"i,â⬠ââ¬Å"t,â⬠ââ¬Å"o,â⬠ââ¬Å"u,â⬠and ââ¬Å"sâ⬠all in a row. The standard way to find ââ¬Å"serendipitousâ⬠(the word) in a file is to use ââ¬Å"serendipitousâ⬠(the regular expression) with a tool like egrep (or extended grep): $ egrep ââ¬Å"serendipitousâ⬠foobar ;hits This line, as you might guess, asks egrep to find instances of the pattern ââ¬Å"serendipitousâ⬠in the file ââ¬Å"foobarâ⬠and write the results to a file called ââ¬Å"hitsâ⬠. In the preceding examples, we have been using regular expressions that adhere to the first rule of regular expressions: namely, that all alphanumeric characters match themselves. There are other characters, however, that match in a more generalized fashion. These are usually referred to as the meta characters. Some meta characters match single characters. This includes the following symbols: . Matches any one character â⬠¦]Matches any character listed between the brackets [^â⬠¦]Matches any character except those listed between the brackets Suppose we have a number of filenames listed out in a file called ââ¬Å"Important. files. â⬠We want to ââ¬Å"grep outâ⬠those filenames which follow the pattern ââ¬Å"blurfle1â⬠, ââ¬Å"blurfle2â⬠, ââ¬Å"blurfle3,â⬠and so on, but exclude files of the form ââ¬Å"1blurfleâ⬠, ââ¬Å"2blurfleâ⬠, ââ¬Å"3blurfleâ⬠The following regex would do the trick: $ egrep ââ¬Å"blurfle. â⬠Important. files ;blurfles The important thing to realize here is that this line will not match merely the string ââ¬Å"blurfle. (that is, ââ¬Å"blurfleâ⬠followed by a period). In a regular expression, the dot is a reserved symbol (weââ¬â¢ll get to matching periods a little further on). This is fine if we arenââ¬â¢t particular about the character we match (whether itââ¬â¢s a ââ¬Å"1,â⬠a ââ¬Å"2,â⬠or even a letter, a space, or an underscore). Narrowing the field of choices for a single character match, however, requires that we use a character class. Character classes match any character listed within that class and are separated off using square brackets. So, for example, if we wanted to match on ââ¬Å"blurfleâ⬠but only when it is followed immediately by a number (including ââ¬Å"blurfle1â⬠but not ââ¬Å"blurflezâ⬠) we would use something like this: $ egrep ââ¬Å"blurfle[0123456789]â⬠Important. files blurfles The syntax here is exactly as it seems: ââ¬Å"Find ââ¬Ëblurfleââ¬â¢ followed by a zero, a one, a two, a three, a four, a five, a six, a seven, an eight, or a nine. â⬠Such classes are usually abbreviated using the range operator (ââ¬Å"-ââ¬Å"): $ egrep ââ¬Å"blurfle[0-9]â⬠Important. files blurfles The following regex would find ââ¬Å"blurfleâ⬠followed by any alphanumeric character (upper or lower case). egrep ââ¬Å"blurfle[0-9A-Za-z]â⬠Important. files blurfles (Notice that we didnââ¬â¢t write blurfle[0-9 A-Z a-z] for that last one. The spaces might make it easier to read, but weââ¬â¢d be matching on anything between zero and nine, anything between a and z, anythi ng between A and Z, or a space. ) A carat at the beginning of the character class negates that class. In other words, if you wanted to find all instances of blurfle except those which end in a number, youââ¬â¢d use the following: $ egrep ââ¬Å"blurfle[^0-9]â⬠Important. files blurfles Many regex implementations have ââ¬Å"macrosâ⬠for various character classes. In Perl, for example, d matches any digit ([0-9]) and w matches any ââ¬Å"word characterâ⬠([a-zA-Z0-9_]). Grep uses a slightly different notation for the same thing: [:digit:] for digits and [:alnum:] for alphanumeric characters. The man page (or other documentation) for the particular tool should list all the regex macros available for that tool. Quantifiers The regular expression syntax also provides metacharacters which specify the number of times a particular character should match. ?Matches any character zero or one times *Matches the preceding element zero or more times +Matches the preceding element one or more times num}Matches the preceding element num times {min, max}Matches the preceding element at least min times, but not more than max times These metacharacters allow you to match on a single-character pattern, but then continue to match on it until the pattern changes. In the last example, we were trying to search for patterns that contain ââ¬Å"blurfleâ⬠fo llowed by a number between zero and nine. The regex we came up with would match on blurfle1, blurfle2, blurfle3, etc. If, however, you had a programmer who mistakenly thought that ââ¬Å"blurfleâ⬠was supposed to be spelled ââ¬Å"blurffle,â⬠our regex wouldnââ¬â¢t be able to catch it. We could fix it, though, with a quantifier. $ egrep ââ¬Å"blur[f]+le[0-9]â⬠Important. files blurfles Here we have ââ¬Å"Find ââ¬Ëbââ¬â¢, ââ¬Ëlââ¬â¢, ââ¬Ëu,ââ¬â¢ ââ¬Ërââ¬â¢ (in a row) followed by one or more instances of an ââ¬Ëfââ¬â¢ followed by ââ¬Ëlââ¬â¢ and ââ¬Ëeââ¬â¢ and then any single digit character between zero and nine. â⬠Thereââ¬â¢s always more than one way to do it with regular expressions, and in fact, if we use single-character metacharacters and quantifiers in conjunction with one another, we can search for almost all the variant spellings of ââ¬Å"blurfleâ⬠(ââ¬Å"bllurfle,â⬠ââ¬Å"bllurrfleâ⬠, bbluuuuurrrfffllleâ⬠, and so on). One way, for example, might employ the ubiquitous (and exceedingly powerful) . * combination: $ egrep ââ¬Å"b. *eâ⬠Important. files ;blurfles If we work this out, we come out with something like: ââ¬Å"find a ââ¬Ëbââ¬â¢ followed by any character any number of times (including zero times) followed by an ââ¬Ëeââ¬â¢. â⬠Itââ¬â¢s tempting to use ââ¬Å". *â⬠with abandon. However, bear in mind that the preceding example would match on words like ââ¬Å"blueâ⬠and ââ¬Å"baritoneâ⬠as well as ââ¬Å"blurfle. â⬠Suppose the filenames in blurfle are numbered up to 12324, but we only care about the first 999: $ egrep ââ¬Å"blurfle[0-9]{3}â⬠Important. files blufles This regex tells egrep to match any number between zero and nine exactly three times in a row. Similarly, ââ¬Å"blurfle[0-9]{3,5}â⬠matches any number between zero and nine at lest three times but not more than five times in a row. Anchors Often, you need to specify the position at which a particular pattern occurs. This is often referred to as ââ¬Å"anchoringâ⬠the pattern: ^Matches at the start of the line $Matches at the end of the line Matches at the beginning of a word Matches at the end of a word Matches at the beginning or the end of a word BMatches any charater not at the beginning or end of a word ^â⬠and ââ¬Å"$â⬠are some of the most useful metacharacters in the regex arsenalââ¬âparticularly when you need to run a search-and-replace on a list of strings. Suppose, for example, that we want to take the ââ¬Å"blurfleâ⬠files listed in Important. files, list them out separately, run a program called ââ¬Å"fragellateâ⬠on each one, and th en append each successive output to a file called ââ¬Å"fraggled_files. â⬠We could write a full-blown shell script (or Perl script) that would do this, but often, the job is faster and easier if we build a very simple shell script with a series of regular expressions. Weââ¬â¢d begin by greping the files we want to operate on and writing the output to a file. $ egrep ââ¬Å"blurfle[0-9]â⬠Important. file ;script. sh This would give us a list of files in script. sh that looked something like this: blurfle1 blurfle2 blurfle3 blurfle4 . . . Now we use sed (or the ââ¬Å"/%sâ⬠operator in vi, or the ââ¬Å"query-replace-regexpâ⬠command in emacs) to put ââ¬Å"fragellateâ⬠in front of each filename and ââ¬Å"fraggled_filesâ⬠after each filename. This requires two separate search-and-replace operations (though not necessarily, as Iââ¬â¢ll explain when we get to backreferences). With sed, you have the ability to put both substitution lines into a file, and then use that file to iterate through another making each substitution in turn. In other words, we create a file called ââ¬Å"fraggle. sedâ⬠which contains the following lines: s/^/fraggelate / s/$/ fraggled_files/ Then run the following ââ¬Å"sed routineâ⬠on script. sh like so: $ sed -f fraggle. sed script. sh script2. sh Our script would then look like this: fraggelate blurfle1 fraggled_files fraggelate blurfle2 fraggled_files fraggelate blurfle3 fraggled_files raggelate blurfle4 fraggled_files . . Chmod it, run it, and youââ¬â¢re done. Of course, this is a somewhat trivial example (ââ¬Å"Why wouldnââ¬â¢t you just run ââ¬Å"fragglate blurfle* ;;fraggled_filesâ⬠from the command line? ââ¬Å"). Still, one can easily imagine instances where the criteria for the file name list is too complicated to express using [filename]* on the command line. In fact, you can probably see from th is sed-routine example that we have the makings of an automatic shell-script generator or file filter. You may also have noticed something odd about that caret in our sed routine. Why doesnââ¬â¢t it mean ââ¬Å"exceptâ⬠as in our previous example? The answer has to do with the sometimes radical difference between what an operator means inside the range operator and what it means outside it. The rules change from tool to tool, but generally speaking, you should use metacharacters inside range operators with caution. Some tools donââ¬â¢t allow them at all, and others change the meaning. To pick but one example, most tools would interpret [A-Za-z. ] as ââ¬Å"Any character between A and Z, a and z or a period. â⬠Most tools provide some way to anchor a match on a word boundary. In some versions of grep, for example, you are allowed to write: $ grep ââ¬Å"fleâ⬠Important. files ;blurfles This says: ââ¬Å"Find the characters ââ¬Å"fâ⬠, ââ¬Å"lâ⬠, ââ¬Å"eâ⬠, but only when they come at the end of a word. â⬠tells the regex engine to match any word boundary (whether itââ¬â¢s at the beginning or the end) and B tells it to match any position that isnââ¬â¢t a word boundary. This again can vary considerably from tool to tool. Some tools donââ¬â¢t support word boundaries at all, and others support them using a slightly different syntax. The tools that do support word boundaries generally consider words to be bounded by spaces or punctuation, and consider numerals to be legitimate parts of words, but there are some variations on these rules that can effect the accuracy of your matches. The man page or other documentation should resolve the matter. Escape Characters By now, youââ¬â¢re probably wondering how you go about searching for one of the special characters (asterisks, periods, slashes, and so on). The answer lies in the use of the escape characterââ¬âfor most tools, the backslash (ââ¬Å"â⬠). To reverse the meaning of a special character (in other words, to treat it as a normal character instead of as a metacharacter), we simply put a backslash before that character. So, we know that a regex like ââ¬Å". *â⬠finds any character any number of times. But suppose weââ¬â¢re searching for ellipses of various lengths and we just want to find periods any number of times. Because the period is normally a special character, weââ¬â¢d need to escape it with a backslash: $ grep ââ¬Å". *â⬠Important. Files ;ellipses. files Unfortunately, this contribute to the legendary ugliness of regular expressions more than any other element of the syntax. Add a few escape characters, and a simple sed routine designed to replace a couple of URLââ¬â¢s quickly degenerates into confusion: sed ââ¬Ës/http://etext. lib. virginia. edu//http://www. etext. virginia. edu/g To make matters worse, the list of what needs to be escaped differs from tool to tool. Some tools, for example, consider the ââ¬Å"+â⬠quantifier to have its normal meaning (as a ordinary plus sign) until it is escaped. If youââ¬â¢re having trouble with a regex (a sed routine that wonââ¬â¢t parse or a grep pattern that wonââ¬â¢t match even though youââ¬â¢re certain the pattern exists), try playing around with the escapes. Or better yet, read the man page. Alternation Alternation refers to the use of the ââ¬Å"|â⬠symbol to indicate logical OR. In a previous example, we used ââ¬Å"blur[f]+leâ⬠to catch those instances of ââ¬Å"blurfleâ⬠that were misspelled with two ââ¬Å"fââ¬â¢sâ⬠. Using alternation, we could have written: $ egrep ââ¬Å"blurfle|blurffleâ⬠Important. files ;blurfles This means simply ââ¬Å"Find either blurfle OR blurffle. â⬠The power of this becomes more evident when we use parentheses to limit the scope of the alternative matches. Consider the following regex, which accounts for both the American and British spellings of the word ââ¬Å"grayâ⬠: $ egrep ââ¬Å"gr(a|e)yâ⬠Important. files ;hazy. shades Or perhaps a mail-filtering program that uses the following regex to single out past correspondence between you and the boss: /(^To:|^From:) (Seaman|Ramsay)/ This says, ââ¬Å"Find a ââ¬ËTo:ââ¬â¢ or a ââ¬ËFrom:ââ¬â¢ line followed by a space and then either the word ââ¬ËSeamanââ¬â¢ or the word ââ¬ËRamsayââ¬â¢ This can make your regexââ¬â¢s extremely flexible, but be careful! Parentheses are also meta characters which figure prominently in the use of . . . Back references Perhaps the most powerful element of the regular expression syntax, back references allows you to load the results of a matched pattern into a buffer and then reuse it later in the expression. In a previous example, we used two separate regular expressions to put something before and after a filename in a list of files. I mentioned at that point that it wasnââ¬â¢t entirely necessary that we use two lines. This is because back references allow us to get it down to one line. Hereââ¬â¢s how: s/(blurfle[0-9]+)/fraggelate 1 fraggled_files/ The key elements in this example are the parentheses and the ââ¬Å"1â⬠. Earlier we noted that parentheses can be used to limit the scope of a match. They can also be used to save a particular pattern into a temporary buffer. In this example, everything in the ââ¬Å"searchâ⬠half of the sed routine (the ââ¬Å"blurfleâ⬠part) is saved into a buffer. In the ââ¬Å"replaceâ⬠half we recall the contents of that buffer back into the string by referring to its buffer number. In this case, buffer ââ¬Å"1â⬠. So, this sed routine will do precisely what the earlier one did: find all the instances of blurfle followed by a number between zero and nine and replace it with ââ¬Å"fragellate blurfle[some number] ;;fraggled filesâ⬠. Backreferences allow for something that very few ordinary search engines can manage; namely, strings of data that change slightly from instance to instance. Page numbering schemes provide a perfect example of this. Suppose we had a document that numbered each page with the notation . The number and the chapter name change from page to page, but the rest of the string stays the same. We can easily write a regular expression that matches on this string, but what if we wanted to match on it and then replace everything but the number and the chapter name? //Page 1, Chapter 2/ Buffer number one (ââ¬Å"1â⬠) holds the first matched sequence, ([0-9]+); buffer number two (ââ¬Å"2â⬠) holds the second, ([A-Za-z]+). Tools vary in the number of backreference they can hold. The more common tools (like sed and grep) hold nine, but Python can hold up to ninety-nine. Perl is limited only by the amount of physical memory (which, for all practical purposes, means you can have as many as you want). Perl also lets you assign the buffer number to an ordinary scalar variable ($1, $2, etc. ) so you can use it later on in the code block. a. OBJECT ORIENTED PROGRAMMING AND JAVA Object-oriented Programming was developed because of limitations found in earlier approaches of programming. To appreciate what OOP does, we need to understand what these limitations are and how they arose from traditional programming. PROCEDURAL LANGUAGES Pascal, C, Basic, FORTRAN, and similar languages are procedural languages. That is, each statement in the language tells the computer to do something: Get some input, add these numbers, divide by 6, display the output. A program in a procedural language is a list of instructions. For very small programs no other organizing principle (often called a paradigm) is needed. The programmer creates the list of instructions, and the computer carries them out. Division into Functions When programs become larger, a single list of instructions becomes unwieldy. Few programmers can comprehend a program of more than a few hundred statements unless it is broken down into smaller units. For this reason the function was adopted as a way to make programs more comprehensible to their human creators. (The term functions is used in C++ and C. In other languages the same concept may be referred to as a subroutine, a subprogram, or a procedure. ) A program is divided into functions, and (ideally, at least) each function has a clearly defined purpose and a clearly defined interface to the other functions in the program. The idea of breaking a program into functions can be further extended by grouping a number of functions together into a larger entity called a module, but the principle is similar: grouping a number of components that carry out specific tasks. Dividing a program into functions and modules is one of the cornerstones of structured programming, the somewhat loosely defined discipline that has influenced programming organization for more than a decade. Problems with Structured Programming As programs grow ever larger and more complex, even the structured programming approach begins to show signs of strain. You may have heard about, or been involved in, horror stories of program development. The project is too complex, the schedule slips, more programmers are added, complexity increases, costs skyrocket, the schedule slips further, and disaster ensues. Analyzing the reasons for these failures reveals that there are weaknesses in the procedural paradigm itself. No matter how well the structured programming approach is implemented, large programs become excessively complex. What are the reasons for this failure of procedural languages? One of the most crucial is the role played by data. Data Undervalued In a procedural language, the emphasis is on doing thingsââ¬âread the keyboard, invert the vector, check for errors, and so on. The subdivision of a program into functions continues this emphasis. Functions do things just as single program statements do. What they do may be more complex or abstract, but the emphasis is still on the action. What happens to the data in this paradigm? Data is, after all, the reason for a programââ¬â¢s existence. The important part of an inventory program isnââ¬â¢t a function that displays the data, or a function that checks for correct input; itââ¬â¢s the inventory data itself. Yet data is given second-class status in the organization of procedural languages. For example, in an inventory program, the data that makes up the inventory is probably read from a disk file into memory, where it is treated as a global variable. By global we mean that the variables that constitute the data are declared outside of any function, so they are accessible to all functions. These functions perform various operations on the data. They read it, analyze it, update it, rearrange it, display it, write it back to the disk, and so on. We should note that most languages, such as Pascal and C, also support local variables, which are hidden within a single function. But local variables are not useful for important data that must be accessed by many different functions. Now suppose a new programmer is hired to write a function to analyze this nventory data in a certain way. Unfamiliar with the subtleties of the program, the programmer creates a function that accidentally corrupts the. This is easy to do, because every function has complete access to the data. Itââ¬â¢s like leaving your personal papers in the lobby of your apartment building: Anyone can change or destroy them. In the same way, global data can be corrupted b y functions that have no business changing it. Another problem is that, since many functions access the same data, the way the data is stored becomes critical. The arrangement of the data canââ¬â¢t be changed without modifying all the functions that access it. If you add new data items, for example, youââ¬â¢ll need to modify all the functions that access the data so that they can also access these new items. It will be hard to find all such functions, and even harder to modify all of them correctly. Itââ¬â¢s similar to what happens when your local supermarket moves the bread from aisle 4 to aisle 12. Everyone who patronizes the supermarket must figure out where the bread has gone, and adjust their shopping habits accordingly. What is needed is a way to restrict access to the data, to hide it from all but a few critical functions. This will protect the data, simplify maintenance, and offer other benefits as well. Relationship to the Real World Procedural programs are often difficult to design. The problem is that their chief componentsââ¬âfunctions and data structuresââ¬âdonââ¬â¢t model the real world very well. For example, suppose you are writing a program to create the elements of a graphics user interface: menus, windows, and so on. Quick now, what functions will you need? What data structures? The answers are not obvious, to say the least. It would be better if windows and menus corresponded more closely to actual program elements. New Data Types There are other problems with traditional languages. One is the difficulty of creating new data types. Computer languages typically have several built-in data types: integers, floating-point numbers, characters, and so on. What if you want to invent your own data type? Perhaps you want to work with complex numbers, or two dimensional coordinates, or datesââ¬âquantities the built-in data types donââ¬â¢t handle easily. Being able to create your own types is called extensibility; you can extend the capabilities of the language. Traditional languages are not usually extensible. Without unnatural convolutions, you canââ¬â¢t bundle together both X and Y coordinates into a single variable called Point, and then add and subtract values of this type. The result is that traditional programs are more complex to write and maintain. The object oriented approach The fundamental idea behind object-oriented languages is to combine into a single unit both data and the functions that operate on that data. Such a unit is called an object. An objectââ¬â¢s functions, called member methods in Java, typically provide the only way to access its data. If you want to read the item and return the value to you, you call a member function in the object. It will read the item and return the value to you. You canââ¬â¢t access the data directly. The data is hidden, so it is safe from accidental modification. Data and its functions are said to be encapsulated into a single entity. Data encapsulation and data hiding are key terms in the description of object oriented languages. If you want to modify the data in an object, you know exactly what functions interact with it: the member functions in the object. No other functions can access the data. This simplifies writing, debugging, and maintaining the program. A Java program typically consists of a number of objects, which communicate with each other by calling one anotherââ¬â¢s members functions. We should mention that what are called member functions in C++ are called methods in Java. Also, data items are referred to as instance variables. Calling an objectââ¬â¢s member function is referred to as sending a message to the object. How to cite Java Based Search Engine, Essay examples
Java Based Search Engine Free Essays
string(97) " on coming up with solutions that serve customer requirements today and anticipate future needs\." ACKNOWLEDGMENT I express thanks and gratitude to Mr. â⬠¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦H. O. We will write a custom essay sample on Java Based Search Engine or any similar topic only for you Order Now D computer science department, â⬠¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦College for his encouraging support and guidance in carrying out the project. I would like to express gratitude and indebtedness to Mrâ⬠¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦, for his valuable advice and guidance without which this project would not have seen the light of the day. I thank Mrâ⬠¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦Ã¢â¬ ¦ , project guide , GSS for his insistence on good programming technique which helped us to design and develop a successful model of an Chatting Tool. Name CONTENTS 1. STUDY ANALYSIS PHASE 1. 1 INTRODUCTION 1. 1. 1 PURPOSE OF THE PROJECT 1. 1. 2 PROBLEM IN EXISTING SYSTEM 1. 1. 3 SOLUTION OF THESE PROBLEMS 1. 1. 4 SCOPE OF THE PROJECT 1. 1. 5 LIMITATIONS 1. 1. 6 HARDWARE SOFTWARE SPECIFICATIONS 1. 1. 7 ORGANISATION PROFILE 2. PROJECT ANALYSIS 1. STUDY OF THE SYSTEM 2. INPUT OUTPUT 3. PROCESS MODULES USED WITH JUSTIFICATION 3. DESIGN PHASE 1. DATAFLOW 2. UML DIAGRAMS 4. IMPLEMENTATION PHASE 5. TESTING 1. TYPES OF TESTING 1. COMPILING TEST 2. EXECUTION TEST 3. OUTPUT TEST 5. PROJECT CODING 6. OUTPUT SCREENS 7. CONCLUSION 8. BIBLOGRAPHY STUDY PHASE INTRODUCTION: EXISTING SYSTEM With the advent of the Internet in the past decade, searching for information in various formats has been redefined by the internet search engines, most of them being based on information retrieval (IR) indexing techniques. IR-based searching, which usually allows formulation of queries with multiple words PROPOSED SYSTEM This Java application is basically a recursive file finder. You can search for files based on their filename, their contents, or both in selected directory and as well as sub directories of the specified directory. Engine is a graphical version of the well-known GREP utility, with an additional feature of traversing subdirectories. You can specify which directory to start looking in, which files to search through, and what pattern to look for in the files. The various fields expect regular expressions, like Global Regular Expression, ââ¬ËEngineââ¬â¢ has not only the graphical interface, but also a command-line interface. This is useful for quick searches through, say, a development tree. Engine requires the Java 2 Platform, Standard Edition version 1. 4 or higher. SOLUTION OF THESE PROBLEMS Regular expressions figure into all kinds of text-manipulation tasks. Searching and search-and-replace are among the more common uses, but regular expressions can also be used to test for certain conditions in a text file or data stream. You might use regular expressions, for example, as the basis for a short program that separates incoming mail from incoming spam. In this case, the program might use a regular expression to determine whether the name of a known spammer appeared in the ââ¬Å"From:â⬠line of the email. Email filtering programs, in fact, very often use regular expressions for exactly this type of operation. SCOPE OF THE PROJECT Engine is a graphical version of the well-known GREP utility, with an additional feature of traversing subdirectories. The main aim of this project is to develop a java based recursive file finder. Engine is a graphical version of the well-known GREP utility, with an additional feature of traversing subdirectories LIMITATIONS Regular expressions tend to be easier to write than they are to read. This is less of a problem if you are the only one who ever needs to maintain the program (or sed routine, or shell script, or what have you), but if several people need to watch over it, the syntax can turn into more of a hindrance than an aid. Ordinary macros (in particular, editable macros such as those generated by the major word processors and editors) tend not to be as fast, as flexible, as portable, as concise, or as fault-tolerant as regular expressions, but they have the advantage of being much more readable; even people with no programming background whatsoever can usually make enough sense of a macro script to change it if the need arises. For some jobs, such readability will outweigh all other concerns. As with all things in computing, itââ¬â¢s largely a question of fitting the tool to the job. HARDWARE SOFTWARE SPECIFICATIONS Environment: Java Runtime Environment version 1. 4 or better installed. Operating System: Any O. S. compatable with JVM Hard disk:10 GB Processor:PIII or higher ORGANIZATION PROFILE EMINENT SOFTWARE SOLUTIONS EMINENT TECHNOLOGIES (ET) is an IT Solution Provider for a dynamic environment where business and technology strategies converge. Our approach focuses on new ways of business combining IT innovation and adoption while also leveraging an organizationââ¬â¢s current IT assets. We work with large global corporations and new generation technology companies ââ¬â to build new products or services and to implement prudent business and technology strategies in todayââ¬â¢s environment. EMINENTââ¬â¢s range of expertise includes: Software Development Services Engineering Services Systems Integration Customer Relationship Management Supply Chain Management Product Development Electronic Commerce Consulting IT Outsourcing We apply technology with innovation and responsibility to achieve two broad objectives: Effectively address the business issues our customers face today Generate new opportunities that will help them stay ahead in the future This approach rests on: A strategy where we Architect, Integrate and Manage technology services and solutions ââ¬â we call it AIM for success. A robust offshore development methodology and reduced demand on customer resources A focus on the use of reusable frameworks to provide cost and time benefits We combine the best people, processes and technology to achieve excellent results consistently. We offer customers the advantages of: Speed: We understand the importance of timing, of getting there before the competition. A rich portfolio of reusable, modular frameworks helps jump start projects. Tried and tested methodology ensures that we follow a predictable, low-risk path to achieve results. Our track record is testimony to complex projects delivered within and even before schedule. Expertise: Our teams combine cutting edge technology skills with rich domain expertise. Whatââ¬â¢s equally important ââ¬â we share a strong customer orientation that means we actually start by listening to the customer. Weââ¬â¢re focused on coming up with solutions that serve customer requirements today and anticipate future needs. You read "Java Based Search Engine" in category "Essay examples" A Full Service Portfolio: We offer customers the advantage of being able to Architect, Integrate and Manage technology services. This means that they can rely on one, fully accountable source instead of trying to integrate disparate multi-vendor solutions. Services: GSS is providing its services to Sain medicaments Pvt. Ltd, Grace drugs and pharmaceuticals Private Limited Alka Drugs and Pharmaceuticals Pvt Ltd to name just a few with out rich experience and expertise in Information Technology we are in the best position to provide software solutions to distinct business requirements. PROJECT ANALYSIS STUDY OF THE SYSTEM This application can be mainly divided into two modules:- â⬠¢ User Interface â⬠¢ File Manipulation and filtering INPUT AND OUTPUT: User has to input the File Name or File Contents and he has to select the Drive or Directory in which searching has to be done. Application will search for the files matching with given criteria and shows the output in the text area of the application. PROCESS MODEL USED WITH JUSTIFICTION The model used here is a SPIRAL MODEL. This Model demands a direct consideration of technical risk at all stages of the project and if properly applied it reduces risk before they become problematic, hence it becomes easier to handle a project when using this kind of model where in the end user can evaluate the program at the end of each stage and suggest modification if required. PROJECT DESIGN DATA FLOW DIAGRAM 0th Level 1st Level 2nd Level 2nd Level 3rd Level UML DIAGRAMS USE CASE DIAGRAM [pic] CLASS DIAGRAM [pic] ACTIVITY DIAGRAM [pic] SEQUENCE DIAGRAM [pic] IMPLEMENTATION PHASE MODULES: 1. COMPONENT THIS IS THE FRONT END CONSOLE OF THE USER TO INTERACT WITH SEARCH ANALYZER. 2. TOOLBAR COORDINATIOR THIS MODULE HAS THE EMBEDED TOOLS WHICH ARE TO IMPLEMENT SEARCH. 3. MAP FINDER THIS MODULE IS MAPS THE SEARCH CORRESPONDING TO THE USERS QUERY. 4. DYNAMIC STATUS FINDER THIS IS THE DYNAMIC MODULE WHICH GIVES THE STATUS OF THE SEARCH . 5. GREP GENERATOR GREP GENERATOR IS THE MAJOR MODULE ON WHICH THE SEARCH IS DONE BASED ON REGULAR EXPRESSIONS . OUTPUT SCREENS Engine view [pic] Browse [pic] Search [pic] Help [pic] Error [pic] PROJECT CODING CODE EXPLANATION Regular expressions simplify pattern-matching code Discover the elegance of regular expressions in text-processing scenarios that involve pattern matching Text processing often involves matching text against a pattern. Although Javaââ¬â¢s character and assorted string classes offer low-level pattern-matching support, that support commonly leads to complex code. To help you write simpler pattern-matching code, Java provides regular expressions with java. util. regex package. Text processing frequently requires code to match text against patterns. That capability makes possible text searches, email header validation, custom text creation from generic text (e. g. , ââ¬Å"Dear Mr. Chakradharâ⬠instead of ââ¬Å"Dear Customerâ⬠), and so on. Java supports pattern matching via its character and assorted string classes. Because that low-level support commonly leads to complex pattern-matching code, Java also offers regular expressions to help you write simpler code. After introducing regular expression terminology, the java. util. regex packageââ¬â¢s classes, and a program that demonstrates regular expression constructs, I explore many of the regular expression constructs that the Pattern class supports. I also examine the methods comprising Pattern and other java. util. regex classes. A practical application of regular expressions concludes my discussion. Regular expressionsââ¬â¢ long history begins in the theoretical computer science fields of automata theory and formal language theory. That history continues to Unix and other operating systems, where regular expressions are often used in Unix and Unix-like utilities: examples include awk (a programming language that enables sophisticated text analysis and manipulation-named after its creators, Aho, Weinberger, and Kernighan), emacs (a developerââ¬â¢s editor), and grep (a program that matches regular expressions in one or more text files and stands for global regular expression print). Regular expressions trace back to the work of an American mathematician by the name of Stephen Kleene (one of the most influential figures in the development of theoretical computer science) who developed regular expressions as a notation for describing what he called ââ¬Å"the algebra of regular sets. â⬠His work eventually found its way into some early efforts with computational search algorithms, and from there to some of the earliest text-manipulation tools on the Unix platform (including ed and grep). In the context of computer searches, the ââ¬Å"*â⬠is formally known as a ââ¬Å"Kleene star. ââ¬Å" A regular expression, also known as a regex or regexp, is a string whose pattern (template) describes a set of strings. The pattern determines what strings belong to the set, and consists of literal characters and meta characters, characters that have special meaning instead of a literal meaning. The process of searching text to identify matchesââ¬âstrings that match a regexââ¬â¢s patternââ¬âis pattern matching. Javaââ¬â¢s java. util. regex package supports pattern matching via its Pattern, Matcher, and PatternSyntaxException classes: 1. Pattern objects, also known as patterns, are compiled regexes 2. Matcher objects, or matchers, are engines that interpret patterns to locate matches in character sequences, objects whose classes implement the java. lang. CharSequence interface and serve as text sources 3. PatternSyntaxException objects describe illegal regex patterns Code for mainwindow package jog. engine; import java. awt. *; import java. awt. event. *; import java. io. *; import java. net. URL; import java. util. prefs. *; import java. util. regex. *; import javax. swing. *; import javax. swing. filechooser. FileFilter; import jog. engine. *; public class MainWindow extends JFrame implements ActionListener, FileSearchListener { rotected Preferences preferences; protected JTextField lookInField; protected JTextField filePatternField; protected JTextField searchForField; protected JTextField excludeField; protected JCheckBox includeSubCheckBox; protected JList resultList; protected RunSearch runner; protected JButton browseButton; protected JButton helpButton; protected JButton s tartButton; protected JButton stopButton; protected JButton closeButton; protected JLabel status; protected JPanel cardPanel; protected CardLayout cardLayout; private boolean stopFlag; public MainWindow() { super(Bundle. getString(ââ¬Å"AppTitleâ⬠)); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent event) { handleClose(); } }); preferences = Preferences. userRoot(). node(ââ¬Å"com/bluemarsh/jrgrepâ⬠); Container pane = getContentPane(); GridBagLayout gb = new GridBagLayout(); pane. setLayout(gb); GridBagConstraints gc = new GridBagConstraints(); gc. insets = new Insets(3, 3, 3, 3); JLabel label = new JLabel(Bundle. getString(ââ¬Å"lookInLabelâ⬠)); gc. anchor = GridBagConstraints. EAST; gb. setConstraints(label, gc); pane. add(label); String s = preferences. get(ââ¬Å"lookInâ⬠, ââ¬Å"â⬠); lookInField = new JTextField(s, 20); gc. anchor = GridBagConstraints. WEST; gc. fill = GridBagConstraints. HORIZONTAL; gc. weightx = 1. 0; gb. setConstraints(lookInField, gc); pane. add(lookInField); browseButton = new JButton(Bundle. getString(ââ¬Å"browseLabelâ⬠)); browseButton. addActionListener(this); gc. anchor = GridBagConstraints. CENTER; gc. gridwidth = GridBagConstraints. REMAINDER; gc. fill = GridBagConstraints. NONE; gc. weightx = 0. 0; gb. setConstraints(browseButton, gc); pane. add(browseButton); label = new JLabel(Bundle. getString(ââ¬Å"filePatternLabelâ⬠)); gc. anchor = GridBagConstraints. EAST; gc. gridwidth = 1; gb. setConstraints(label, gc); pane. add(label); s = preferences. get(ââ¬Å"filterâ⬠, ââ¬Å"â⬠); ilePatternField = new JTextField(s, 20); gc. anchor = GridBagConstraints. WEST; gc. fill = GridBagConstraints. HORIZONTAL; gc. gridwidth = GridBagConstraints. RELATIVE; gc. weightx = 1. 0; gb. setConstraints(filePatternField, gc); pane. add(filePatternField); Component glue = Box. createGlue(); gc. anchor = GridBagConstraints. CENTER; gc. fill = GridBagConstraints. NONE; gc. gridwidth = GridBagConstraints. REMAINDER; gc. weightx = 0. 0; gb. setConstraints(glue, gc); pane. add(glue); label = new JLabel(Bundle. getString(ââ¬Å"searchForLabelâ⬠)); gc. anchor = GridBagConstraints. EAST; gc. fill = GridBagConstraints. NONE; gc. gridwidth = 1; gb. setConstraints(label, gc); pane. add(label); s = preferences. get(ââ¬Å"searchForâ⬠, ââ¬Å"â⬠); searchForField = new JTextField(s, 20); gc. anchor = GridBagConstraints. WEST; gc. fill = GridBagConstraints. HORIZONTAL; gc. gridwidth = GridBagConstraints. RELATIVE; gc. weightx = 1. 0; gb. setConstraints(searchForField, gc); pane. add(searchForField); helpButton = new JButton(Bundle. getString(ââ¬Å"helpLabelâ⬠)); helpButton. addActionListener(this); gc. anchor = GridBagConstraints. CENTER; gc. fill = GridBagConstraints. NONE; gc. gridwidth = GridBagConstraints. REMAINDER; gc. weightx = 0. 0; gb. etConstraints(helpButton, gc); pane. add(helpButton); label = new JLabel(Bundle. getString(ââ¬Å"excludeLabelâ⬠)); gc. anchor = GridBagConstraints. EAST; gc. gridwidth = 1; gb. setConstraints(label, gc); pane. add(label); s = preferences. get(ââ¬Å"excludeâ⬠, ââ¬Å"â⬠); excludeField = new JTextField(s, 20); gc. anchor = GridBagCon straints. WEST; gc. fill = GridBagConstraints. HORIZONTAL; gc. gridwidth = GridBagConstraints. RELATIVE; gc. weightx = 1. 0; gb. setConstraints(excludeField, gc); pane. add(excludeField); glue = Box. createGlue(); gc. anchor = GridBagConstraints. CENTER; gc. fill = GridBagConstraints. NONE; gc. ridwidth = GridBagConstraints. REMAINDER; gc. weightx = 0. 0; gb. setConstraints(glue, gc); pane. add(glue); includeSubCheckBox = new JCheckBox( Bundle. getString(ââ¬Å"includeSubDirLabelâ⬠), true); includeSubCheckBox. setSelected(preferences. getBoolean( ââ¬Å"recurseâ⬠, true)); gc. anchor = GridBagConstraints. WEST; gb. setConstraints(includeSubCheckBox, gc); pane. add(includeSubCheckBox); startButton = new JButton( Bundle. getString(ââ¬Å"startSearchLabelâ⬠)); startButton. addActionListener(this); gc. gridwidth = 1; gb. setConstraints(startButton, gc); pane. add(startButton); status=new JLabel(ââ¬Å"â⬠); Color c=new Color(240,100,100); tatus. setForeground(c); gc. g ridwidth = 1; gb. setConstraints(status, gc); pane. add(status); stopButton = new JButton(Bundle. getString(ââ¬Å"stopLabelâ⬠)); stopButton. setEnabled(false); stopButton. addActionListener(this); gc. anchor = GridBagConstraints. CENTER; gc. gridwidth = GridBagConstraints. RELATIVE; gb. setConstraints(stopButton, gc); pane. add(stopButton); closeButton = new JButton(Bundle. getString(ââ¬Å"closeLabelâ⬠)); closeButton. addActionListener(this); gc. gridwidth = GridBagConstraints. REMAINDER; gb. setConstraints(closeButton, gc); pane. add(closeButton); resultList = new JList(new ResultsListModel()); JScrollPane scroller = new JScrollPane(resultList); cardPanel = new JPanel(new CardLayout()); cardLayout = (CardLayout) cardPanel. getLayout(); cardPanel. add(scroller, ââ¬Å"listâ⬠); gc. gridwidth = GridBagConstraints. REMAINDER; gc. gridheight = GridBagConstraints. REMAINDER; gc. fill = GridBagConstraints. BOTH; gc. weightx = 1. 0; gc. weighty = 1. 0; gb. setConstraints(cardPanel, gc); pane. add(cardPanel); int width = preferences. getInt(ââ¬Å"windowWidthâ⬠, 0); int height = preferences. getInt(ââ¬Å"windowHeightâ⬠, 0); if (width == 0 height == 0) { pack(); } else { setSize(width, height); } int top = preferences. getInt(ââ¬Å"windowTopâ⬠, 100); nt left = preferences. getInt(ââ¬Å"windowLeftâ⬠, 100); setLocation(left, top); stopFlag=false; } public void actionPerformed(ActionEvent event) { JButton button = (JButton) event. getSource(); //System. out. println(ââ¬Å"action ââ¬Å"+button); if (button == closeButton) { handleClose(); } else if (button == browseButton) { handleBrowse(); } else if (button == startButton) { status. setText(ââ¬Å"Search Startedâ⬠); //System. out. println(ââ¬Å"Search startedâ⬠); startSearch(); } else if (button == helpButton) { displayHelp(); } else if (button == stopButton) { //System. out. println(ââ¬Å"Search stoppedâ⬠); stopButton. setEnabled(false); runner. stop(); stopFlag=true; /int count=((ListModel)resultList. getModel()). getSize(); //status. setText(ââ¬Å"Search Stopped ââ¬Å"+count+â⬠Files Foundâ⬠); } } protected void displayHelp() { if (cardPanel. getComponentCount() 2) { URL helpUrl = Bundle. getResource(ââ¬Å"helpFileâ⬠); try { JEditorPane editor = new JEditorPane(helpUrl); editor. setEditable(false); JScrollPane scroller = new JScrollPane(editor); cardPanel. add(scroller, ââ¬Å"helpâ⬠); } catch (IOException ioe) { searchFailed(ioe); return; } } cardLayout. show(cardPanel, ââ¬Å"helpâ⬠); } public void fileFound(FileFoundEvent event) { R esultsListModel model = (ResultsListModel) resultList. etModel(); model. addElement(event. getFile()); } protected void handleBrowse() { String dirStr = lookInField. getText(); JFileChooser fc; if (dirStr. equals(ââ¬Å"â⬠)) { String lastdir = preferences. get(ââ¬Å"lastdirâ⬠, null); if (lastdir == null || lastdir. length() == 0) { lastdir = System. getProperty(ââ¬Å"user. dirâ⬠); } fc = new JFileChooser(lastdir); } else { fc = new JFileChooser(dirStr); } fc. setFileSelectionMode(JFileChooser. DIRECTORIES_ONLY); if (fc. showOpenDialog(this) ! = JFileChooser. CANCEL_OPTION) { File dir = fc. getSelectedFile(); String path = dir. getPath(); lookInField. setText(path); references. put(ââ¬Å"lastdirâ⬠, path); } } protected void handleClose() { preferences. putInt(ââ¬Å"windowTopâ⬠, getY()); preferences. putInt(ââ¬Å"windowLeftâ⬠, getX()); preferences. putInt(ââ¬Å"windowWidthâ⬠, getWidth()); preferences. putInt(ââ¬Å"windowHeightâ⬠, getHeigh t()); preferences. put(ââ¬Å"lookInâ⬠, lookInField. getText()); preferences. put(ââ¬Å"filterâ⬠, filePatternField. getText()); preferences. put(ââ¬Å"searchForâ⬠, searchForField. getText()); preferences. put(ââ¬Å"excludeâ⬠, excludeField. getText()); preferences. putBoolean(ââ¬Å"recurseâ⬠, includeSubCheckBox. isSelected()); System. exit(0); } public void searchComplete() { stopButton. etEnabled(false); //status. setText(ââ¬Å"Search completedâ⬠); int count=((ListModel)resultList. getModel()). getSize(); if(count==0){ status. setText(ââ¬Å"Search Completed No Files Foundâ⬠); } if(stopFlag){ status. setText(ââ¬Å"Search Stopped ââ¬Å"+count +â⬠Files Foundâ⬠); stopFlag=false; }else{ status. setText(ââ¬Å"Search Completed ââ¬Å"+count +â⬠Files Foundâ⬠); } } public void searchFailed(Throwable t) { Object[] messages = {Bundle. getString(ââ¬Å"exceptionOccurredâ⬠),t. getMessage()}; JOptionPane. showMessageDialog(thi s, messages, Bundle. getString(ââ¬Å"errorTitleâ⬠), JOptionPane. ERROR_MESSAGE); } protected void startSearch() { cardLayout. how(cardPanel, ââ¬Å"listâ⬠); ResultsListModel model = (ResultsListModel) resultList. getModel(); model. clear(); String dirStr = lookInField. getText(); if (dirStr == null || dirStr. length() == 0) { dirStr = ââ¬Å". ââ¬Å"; } File dir = new File(dirStr); if (! dir. exists()) { JOptionPane. showMessageDialog(this, Bundle. getString(ââ¬Å"pathDoesNotExistâ⬠), Bundle. getString(ââ¬Å"errorTitleâ⬠), JOptionPane. ERROR_MESSAGE); return; } String target = searchForField. getText(); String filter = filePatternField. getText(); String exclude = excludeField. getText(); try { Pattern. compile(target); Pattern. compile(filter); Pattern. ompile(exclude); } catch (PatternSyntaxException pse) { Object[] messages = {Bundle. getString(ââ¬Å"invalidRegexPatternâ⬠), pse. getMessage()}; JOptionPane. showMessageDialog(this, messages, Bundle. ge tString(ââ¬Å"errorTitleâ⬠),JOptionPane. ERROR_MESSAGE); return; } if (runner == null) { runner = new RunSearch(this); } runner. search(dir, target, filter, includeSubCheckBox. isSelected(), exclude); Thread th = new Thread(runner); th. start(); stopButton. setEnabled(true); } } Code for bundle package jog. engine; import java. net. URL; import java. util. MissingResourceException; import java. til. ResourceBundle; public class Bundle { private static ResourceBundle resourceBundle; static { resourceBundle = ResourceBundle. getBundle(Bundle. class. getName()); } public static ResourceBundle getBundle() { return resourceBundle; } public static URL getResource(String key) { String name = getString(key); return name == null ? null : Bundle. class. getResource(name); } public static String getString(String key) { try { return resourceBundle. getString(key); } catch (MissingResourceException mre) { return null; } } } Code for runsearch package jog. engine; import java. io. File; imp ort jog. engine. *; mport java. lang. *; class RunSearch implements Runnable { protected File dir; protected String lookFor; protected String filter; protected boolean subDirs; protected String exclude; protected FileSearchListener listener; protected Searcher searcher; public RunSearch(FileSearchListener listener) { this. listener = listener; } public void run() { if (searcher == null) { searcher = new Searcher(); if (listener ! = null) { searcher. addSearchListener(listener); } } searcher. search(dir, lookFor, filter, subDirs, exclude); } public void search(File dir, String lookFor, String filter, boolean subDirs, String exclude) this. dir = dir; this. lookFor = lookFor; this. filter = filter; this. subDirs = subDirs; this. exclude = exclude; } public void stop() { //System. out. println(ââ¬Å"Searcher is one:â⬠+ isAlive()); System. out. println(ââ¬Å"Searcherâ⬠); if (searcher ! = null) { searcher. stopSearching(); searcher=null; System. out. println(ââ¬Å"Searcher on eâ⬠); } //System. out. println(ââ¬Å"Searcher is :â⬠+ isAlive()); //System. out. println(ââ¬Å"Searcher oneâ⬠); } } Code for searcher package jog. engine; import java. io. *; import java. nio. *; import java. nio. channels. *; import java. nio. charset. *; import java. util. *; import java. til. regex. *; import javax. swing. event. EventListenerList; import jog. engine. *; class Searcher { protected static Pattern linePattern; protected static Charset charset; protected static CharsetDecoder decoder; protected EventListenerList searchListeners; protected volatile boolean stopSearch; protected Pattern targetPattern; protected Matcher targetMatcher; protected Pattern filterPattern; protected Matcher filterMatcher; protected Pattern excludePattern; protected Matcher excludeMatcher; static { try { linePattern = Pattern. compile(ââ¬Å". * ? ââ¬Å"); } catch (PatternSyntaxException pse) { System. out. rintln(ââ¬Å"Ye flipping gods! ââ¬Å"); } charset = Charset. forName(ââ¬Å"ISO-8859-1â⬠); decoder = charset. newDecoder(); } public Searcher() { searchListeners = new EventListenerList(); } public void addSearchListener(FileSearchListener listener) { searchListeners. add(FileSearchListener. class, listener); } protected void fireDone() { if (searchListeners == null) { return; } Object[] listeners = searchListeners. getListenerList(); for (int i = listeners. length ââ¬â 2; i = 0; i -= 2) { if (listeners[i] == FileSearchListener. class) { FileSearchListener fsl = (FileSearchListener) listeners[i + 1]; fsl. earchComplete(); } } } protected void fireError(Throwable t) { if (searchListeners == null) { return; } Object[] listeners = searchListeners. getListenerList(); for (int i = listeners. length ââ¬â 2; i = 0; i -= 2) { if (listeners[i] == FileSearchListener. class) { FileSearchListener fsl = (FileSearchListen er) listeners[i + 1]; fsl. searchFailed(t); } } } protected void fireFound(String match) { if (searchListeners == null) { return; } FileFoundEvent event = new FileFoundEvent(this, match); Object[] listeners = searchListeners. getListenerList(); for (int i = listeners. ength ââ¬â 2; i = 0; i -= 2) { if (listeners[i] == FileSearchListener. class) { FileSearchListener fsl = (FileSearchListener) listeners[i + 1]; fsl. fileFound(event); } } event = null; } public void removeSearchListener(FileSearchListener listener) { searchListeners. remove(FileSearchListener. class, listener); } public void search(File startIn, String target, String filter, boolean recurse, String exclude) { stopSearch = false; try { targetPattern = Pattern. compile(target); filterPattern = Pattern. compile(filter); if (exclude ! = null exclude. length() 0) { excludePattern = Pattern. ompile(exclude); } searchLow(startIn, recurse); } catch (IOException ioe) { fireError(ioe); } catch (PatternSyntaxException pse) { fireError(pse); } targetPattern = null; targetMatcher = null; filterPattern = null; filterMatcher = null; excludePattern = null; excludeMatcher = null; fireDone(); } protected void searchLow(File startIn, boolean recurse) throws IOException { String[] files = startIn. list(); if (files == null) { return; } for (int ii = 0; ii files. length; ii++) { if (stopSearch) { break; } File file = new File(startIn, files[ii]); if (file. isFile() file. canRead()) { String filename = file. etCanonicalPath(); if (filterMatcher == null) { filterMatcher = filterPattern. matcher(filename); } else { filterMatcher. reset(filename); } if (! filterMatcher. find()) { continue; } FileInputStream fis = new FileInputStream(file); FileChannel fc = fis. getChannel(); MappedByteBuffer bb = fc. map(FileChannel. MapMode. READ_ONLY, 0, fc. size()); CharBuffer cb = decoder. decode(bb); boolean matchFound = false; if ((targetPattern. flags() Pattern. DOTALL) ! = 0) { if (targetMatcher == null) { targetMatcher = targetPattern. matcher(cb); } else { argetMatcher. reset(cb); } if (targetMatcher. find()) { matchFound = true; } } else { Matcher lm = linePattern. matcher(cb); while (lm. find()) { CharSequence cs = lm. group(); if (targetMatcher == null) { targetMatcher = targetPattern. matcher(cs); } else { targetMatcher. reset(cs); } if (targetMatcher. find()) { matchFound = true; } if (lm. end() == cb. limit()) { break; } } } if (matchFound) { fireFound(filename); } } else if (recurse file. isDirectory()) { String dirname = file. getName(); if (excludePattern ! = null) { if (excludeMatcher == null) { excludeMatcher = excludePattern. atcher(dirname); } else { excludeMatcher. reset(dirname); } if (! excludeMatcher. find()) { searchLow(file, recurse); } } else { searchLow(file, recurse); } } } } public void stopSearching() { stopSearch = true; } } Code for filesearch listener package jog. engine; import java. util. EventListener; import jog. engine. FileFoundEvent; interface FileSearchListener extends EventListener { public void fileFound(FileFoundEvent event); public void searchComplete(); public void searchFailed(Throwable t); } Code for tty package jog. engine; import java. io. *; import java. util. regex. *; mport jog. engine. *; public class tty implements FileSearchListener { protected static int argIndex; protected static String excludeStr = ââ¬Å"â⬠; protected static String nameStr = ââ¬Å"â⬠; protected static void displayHelp() { String str = Bundle. getString(ââ¬Å"ttyHelp1â⬠); int i = 1; while (str ! = null) { System. out. println(str); i++; str = Bundle. getString(ââ¬Å"ttyHelpâ⬠+ i); } } public void fileFound(FileFoundEvent event) { System. out. println(event. getFile()); } protected static boolean processArgs(String[] args) { while (argIndex args. length) { String arg = args[argIndex]; if (arg. equals(ââ¬Å"-excludeâ⬠)) { rgIndex++; excludeStr = args[argIndex]; } else if (arg. equals(ââ¬Å"-hâ⬠) || arg. equals(ââ¬Å"-h elpâ⬠) || arg. equals(ââ¬Å"ââ¬âhelpâ⬠)) { displayHelp(); return false; } else if (arg. equals(ââ¬Å"-nameâ⬠)) { argIndex++; nameStr = args[argIndex]; } else { break; } argIndex++; } return true; } public void searchComplete() {} public void searchFailed(Throwable t) { System. err. println(Bundle. getString(ââ¬Å"exceptionOccurredâ⬠)); System. err. println(t. getMessage()); } public static void main(String[] args) { try { if (! processArgs(args)) { return; } } catch (ArrayIndexOutOfBoundsException aioobe) { System. err. println(Bundle. etString(ââ¬Å"ttyMissingArgumentsâ⬠)); return; } if (argIndex == args. length) { System. err. println(Bundle. getString(ââ¬Å"ttyMissingRequiredâ⬠)); return; } String target = args[argIndex]; argIndex++; String dirStr = null; if (argIndex == args. length) { dirStr = ââ¬Å". ââ¬Å"; } else { dirStr = args[argIndex]; } File dir = new File(dirStr); if (! dir. exists()) { System. err. println(Bundle. getString(â⠬Å"pathDoesNotExistâ⬠)); return; } try { Pattern. compile(target); Pattern. compile(nameStr); } catch (PatternSyntaxException pse) { System. err. println(Bundle. getString(ââ¬Å"invalidRegexPatternâ⬠)); System. rr. println(pse. getMessage()); return; } Searcher searcher = new Searcher(); tty instance = new tty(); searcher. addSearchListener(instance); searcher. search(dir, target, nameStr, true, excludeStr); searcher. removeSearchListener(instance); } } Code for filefoundevent package jog. engine; import java. util. EventObject; class FileFoundEvent extends EventObject { protected String file; public FileFoundEvent(Object source, String file) { super(source); this. file = file; } public String getFile() { return file; } } Code for result list model package jog. engine; import java. util. Vector; import javax. wing. AbstractListModel; import jog. engine. *; class ResultsListModel extends AbstractListModel { protected Vector listData; public ResultsListModel() { listData = new Vector(); } public void addElement(Object o) { listData. add(o); fireIntervalAdded(this, listData. size(), listData. size()); } public void clear() { int size = listData. size(); listData. clear(); fireIntervalRemoved(this, 0, size); } public Object getElementAt(int i) { try { return listData. elementAt(i); } catch (ArrayIndexOutOfBoundsException e) { return null; } } public int getSize() { return listData. size(); } } Code for main package jog. ngine; import jog. engine. *; public class Main { public static void main(String[] args) { new MainWindow(). show(); // new jog. searchdesk. MainWindow. show(); } } For a tool with full regex support, metacharacters like ââ¬Å"*â⬠and ââ¬Å"? â⬠(or ââ¬Å"wildcard operators,â⬠as they are sometimes called) are only the tip of the iceberg. Using a good regex engine and a well-crafted regular expression, one can easily search through a text file (or a hundred text files) searching for words that have the suffix ââ¬Å". htmlâ⬠(but only if the word begins with a capital letter and occurs at the beginning of the line), replace the . tml suffix with a . sgml suffix, and then change all the lower case characters to upper case. With the right tools, this series of regular expressions would do just that: s/(^[A_Z]{1})([a-z]+). sgml/12. html/g tr/a-z/A-Z/ As you might guess from this example, concision is everything when it comes to crafting regular expressions, and while this syntax wonââ¬â¢t win any beauty prizes, it follows a logical and fairly standardized format which you can learn to rea+*d and write easily with just a little bit of practice. In a regular expression, everything is a generalized pattern. If I type the word ââ¬Å"serendipitousâ⬠into my editor, Iââ¬â¢ve created one instance of the word ââ¬Å"serendipitous. â⬠If, however, I indicate to my tool (or compiler, or editor, or what have you) that Iââ¬â¢m now typing a regular expression, I am in effect creating a template that matches all instances of the characters ââ¬Å"s,â⬠ââ¬Å"e,â⬠ââ¬Å"r,â⬠ââ¬Å"e,â⬠ââ¬Å"n,â⬠ââ¬Å"d,â⬠ââ¬Å"i,â⬠ââ¬Å"p,â⬠ââ¬Å"i,â⬠ââ¬Å"t,â⬠ââ¬Å"o,â⬠ââ¬Å"u,â⬠and ââ¬Å"sâ⬠all in a row. The standard way to find ââ¬Å"serendipitousâ⬠(the word) in a file is to use ââ¬Å"serendipitousâ⬠(the regular expression) with a tool like egrep (or extended grep): $ egrep ââ¬Å"serendipitousâ⬠foobar ;hits This line, as you might guess, asks egrep to find instances of the pattern ââ¬Å"serendipitousâ⬠in the file ââ¬Å"foobarâ⬠and write the results to a file called ââ¬Å"hitsâ⬠. In the preceding examples, we have been using regular expressions that adhere to the first rule of regular expressions: namely, that all alphanumeric characters match themselves. There are other characters, however, that match in a more generalized fashion. These are usually referred to as the meta characters. Some meta characters match single characters. This includes the following symbols: . Matches any one character â⬠¦]Matches any character listed between the brackets [^â⬠¦]Matches any character except those listed between the brackets Suppose we have a number of filenames listed out in a file called ââ¬Å"Important. files. â⬠We want to ââ¬Å"grep outâ⬠those filenames which follow the pattern ââ¬Å"blurfle1â⬠, ââ¬Å"blurfle2â⬠, ââ¬Å"blurfle3,â⬠and so on, but exclude files of the form ââ¬Å"1blurfleâ⬠, ââ¬Å"2blurfleâ⬠, ââ¬Å"3blurfleâ⬠The following regex would do the trick: $ egrep ââ¬Å"blurfle. â⬠Important. files ;blurfles The important thing to realize here is that this line will not match merely the string ââ¬Å"blurfle. (that is, ââ¬Å"blurfleâ⬠followed by a period). In a regular expression, the dot is a reserved symbol (weââ¬â¢ll get to matching periods a little further on). This is fine if we arenââ¬â¢t particular about the character we match (whether itââ¬â¢s a ââ¬Å"1,â⬠a ââ¬Å"2,â⬠or even a letter, a space, or an underscore). Narrowing the field of choices for a single character match, however, requires that we use a character class. Character classes match any character listed within that class and are separated off using square brackets. So, for example, if we wanted to match on ââ¬Å"blurfleâ⬠but only when it is followed immediately by a number (including ââ¬Å"blurfle1â⬠but not ââ¬Å"blurflezâ⬠) we would use something like this: $ egrep ââ¬Å"blurfle[0123456789]â⬠Important. files blurfles The syntax here is exactly as it seems: ââ¬Å"Find ââ¬Ëblurfleââ¬â¢ followed by a zero, a one, a two, a three, a four, a five, a six, a seven, an eight, or a nine. â⬠Such classes are usually abbreviated using the range operator (ââ¬Å"-ââ¬Å"): $ egrep ââ¬Å"blurfle[0-9]â⬠Important. files blurfles The following regex would find ââ¬Å"blurfleâ⬠followed by any alphanumeric character (upper or lower case). egrep ââ¬Å"blurfle[0-9A-Za-z]â⬠Important. files blurfles (Notice that we didnââ¬â¢t write blurfle[0-9 A-Z a-z] for that last one. The spaces might make it easier to read, but weââ¬â¢d be matching on anything between zero and nine, anything between a and z, anythi ng between A and Z, or a space. ) A carat at the beginning of the character class negates that class. In other words, if you wanted to find all instances of blurfle except those which end in a number, youââ¬â¢d use the following: $ egrep ââ¬Å"blurfle[^0-9]â⬠Important. files blurfles Many regex implementations have ââ¬Å"macrosâ⬠for various character classes. In Perl, for example, d matches any digit ([0-9]) and w matches any ââ¬Å"word characterâ⬠([a-zA-Z0-9_]). Grep uses a slightly different notation for the same thing: [:digit:] for digits and [:alnum:] for alphanumeric characters. The man page (or other documentation) for the particular tool should list all the regex macros available for that tool. Quantifiers The regular expression syntax also provides metacharacters which specify the number of times a particular character should match. ?Matches any character zero or one times *Matches the preceding element zero or more times +Matches the preceding element one or more times num}Matches the preceding element num times {min, max}Matches the preceding element at least min times, but not more than max times These metacharacters allow you to match on a single-character pattern, but then continue to match on it until the pattern changes. In the last example, we were trying to search for patterns that contain ââ¬Å"blurfleâ⬠fo llowed by a number between zero and nine. The regex we came up with would match on blurfle1, blurfle2, blurfle3, etc. If, however, you had a programmer who mistakenly thought that ââ¬Å"blurfleâ⬠was supposed to be spelled ââ¬Å"blurffle,â⬠our regex wouldnââ¬â¢t be able to catch it. We could fix it, though, with a quantifier. $ egrep ââ¬Å"blur[f]+le[0-9]â⬠Important. files blurfles Here we have ââ¬Å"Find ââ¬Ëbââ¬â¢, ââ¬Ëlââ¬â¢, ââ¬Ëu,ââ¬â¢ ââ¬Ërââ¬â¢ (in a row) followed by one or more instances of an ââ¬Ëfââ¬â¢ followed by ââ¬Ëlââ¬â¢ and ââ¬Ëeââ¬â¢ and then any single digit character between zero and nine. â⬠Thereââ¬â¢s always more than one way to do it with regular expressions, and in fact, if we use single-character metacharacters and quantifiers in conjunction with one another, we can search for almost all the variant spellings of ââ¬Å"blurfleâ⬠(ââ¬Å"bllurfle,â⬠ââ¬Å"bllurrfleâ⬠, bbluuuuurrrfffllleâ⬠, and so on). One way, for example, might employ the ubiquitous (and exceedingly powerful) . * combination: $ egrep ââ¬Å"b. *eâ⬠Important. files ;blurfles If we work this out, we come out with something like: ââ¬Å"find a ââ¬Ëbââ¬â¢ followed by any character any number of times (including zero times) followed by an ââ¬Ëeââ¬â¢. â⬠Itââ¬â¢s tempting to use ââ¬Å". *â⬠with abandon. However, bear in mind that the preceding example would match on words like ââ¬Å"blueâ⬠and ââ¬Å"baritoneâ⬠as well as ââ¬Å"blurfle. â⬠Suppose the filenames in blurfle are numbered up to 12324, but we only care about the first 999: $ egrep ââ¬Å"blurfle[0-9]{3}â⬠Important. files blufles This regex tells egrep to match any number between zero and nine exactly three times in a row. Similarly, ââ¬Å"blurfle[0-9]{3,5}â⬠matches any number between zero and nine at lest three times but not more than five times in a row. Anchors Often, you need to specify the position at which a particular pattern occurs. This is often referred to as ââ¬Å"anchoringâ⬠the pattern: ^Matches at the start of the line $Matches at the end of the line Matches at the beginning of a word Matches at the end of a word Matches at the beginning or the end of a word BMatches any charater not at the beginning or end of a word ^â⬠and ââ¬Å"$â⬠are some of the most useful metacharacters in the regex arsenalââ¬âparticularly when you need to run a search-and-replace on a list of strings. Suppose, for example, that we want to take the ââ¬Å"blurfleâ⬠files listed in Important. files, list them out separately, run a program called ââ¬Å"fragellateâ⬠on each one, and th en append each successive output to a file called ââ¬Å"fraggled_files. â⬠We could write a full-blown shell script (or Perl script) that would do this, but often, the job is faster and easier if we build a very simple shell script with a series of regular expressions. Weââ¬â¢d begin by greping the files we want to operate on and writing the output to a file. $ egrep ââ¬Å"blurfle[0-9]â⬠Important. file ;script. sh This would give us a list of files in script. sh that looked something like this: blurfle1 blurfle2 blurfle3 blurfle4 . . . Now we use sed (or the ââ¬Å"/%sâ⬠operator in vi, or the ââ¬Å"query-replace-regexpâ⬠command in emacs) to put ââ¬Å"fragellateâ⬠in front of each filename and ââ¬Å"fraggled_filesâ⬠after each filename. This requires two separate search-and-replace operations (though not necessarily, as Iââ¬â¢ll explain when we get to backreferences). With sed, you have the ability to put both substitution lines into a file, and then use that file to iterate through another making each substitution in turn. In other words, we create a file called ââ¬Å"fraggle. sedâ⬠which contains the following lines: s/^/fraggelate / s/$/ fraggled_files/ Then run the following ââ¬Å"sed routineâ⬠on script. sh like so: $ sed -f fraggle. sed script. sh script2. sh Our script would then look like this: fraggelate blurfle1 fraggled_files fraggelate blurfle2 fraggled_files fraggelate blurfle3 fraggled_files raggelate blurfle4 fraggled_files . . Chmod it, run it, and youââ¬â¢re done. Of course, this is a somewhat trivial example (ââ¬Å"Why wouldnââ¬â¢t you just run ââ¬Å"fragglate blurfle* ;;fraggled_filesâ⬠from the command line? ââ¬Å"). Still, one can easily imagine instances where the criteria for the file name list is too complicated to express using [filename]* on the command line. In fact, you can probably see from th is sed-routine example that we have the makings of an automatic shell-script generator or file filter. You may also have noticed something odd about that caret in our sed routine. Why doesnââ¬â¢t it mean ââ¬Å"exceptâ⬠as in our previous example? The answer has to do with the sometimes radical difference between what an operator means inside the range operator and what it means outside it. The rules change from tool to tool, but generally speaking, you should use metacharacters inside range operators with caution. Some tools donââ¬â¢t allow them at all, and others change the meaning. To pick but one example, most tools would interpret [A-Za-z. ] as ââ¬Å"Any character between A and Z, a and z or a period. â⬠Most tools provide some way to anchor a match on a word boundary. In some versions of grep, for example, you are allowed to write: $ grep ââ¬Å"fleâ⬠Important. files ;blurfles This says: ââ¬Å"Find the characters ââ¬Å"fâ⬠, ââ¬Å"lâ⬠, ââ¬Å"eâ⬠, but only when they come at the end of a word. â⬠tells the regex engine to match any word boundary (whether itââ¬â¢s at the beginning or the end) and B tells it to match any position that isnââ¬â¢t a word boundary. This again can vary considerably from tool to tool. Some tools donââ¬â¢t support word boundaries at all, and others support them using a slightly different syntax. The tools that do support word boundaries generally consider words to be bounded by spaces or punctuation, and consider numerals to be legitimate parts of words, but there are some variations on these rules that can effect the accuracy of your matches. The man page or other documentation should resolve the matter. Escape Characters By now, youââ¬â¢re probably wondering how you go about searching for one of the special characters (asterisks, periods, slashes, and so on). The answer lies in the use of the escape characterââ¬âfor most tools, the backslash (ââ¬Å"â⬠). To reverse the meaning of a special character (in other words, to treat it as a normal character instead of as a metacharacter), we simply put a backslash before that character. So, we know that a regex like ââ¬Å". *â⬠finds any character any number of times. But suppose weââ¬â¢re searching for ellipses of various lengths and we just want to find periods any number of times. Because the period is normally a special character, weââ¬â¢d need to escape it with a backslash: $ grep ââ¬Å". *â⬠Important. Files ;ellipses. files Unfortunately, this contribute to the legendary ugliness of regular expressions more than any other element of the syntax. Add a few escape characters, and a simple sed routine designed to replace a couple of URLââ¬â¢s quickly degenerates into confusion: sed ââ¬Ës/http://etext. lib. virginia. edu//http://www. etext. virginia. edu/g To make matters worse, the list of what needs to be escaped differs from tool to tool. Some tools, for example, consider the ââ¬Å"+â⬠quantifier to have its normal meaning (as a ordinary plus sign) until it is escaped. If youââ¬â¢re having trouble with a regex (a sed routine that wonââ¬â¢t parse or a grep pattern that wonââ¬â¢t match even though youââ¬â¢re certain the pattern exists), try playing around with the escapes. Or better yet, read the man page. Alternation Alternation refers to the use of the ââ¬Å"|â⬠symbol to indicate logical OR. In a previous example, we used ââ¬Å"blur[f]+leâ⬠to catch those instances of ââ¬Å"blurfleâ⬠that were misspelled with two ââ¬Å"fââ¬â¢sâ⬠. Using alternation, we could have written: $ egrep ââ¬Å"blurfle|blurffleâ⬠Important. files ;blurfles This means simply ââ¬Å"Find either blurfle OR blurffle. â⬠The power of this becomes more evident when we use parentheses to limit the scope of the alternative matches. Consider the following regex, which accounts for both the American and British spellings of the word ââ¬Å"grayâ⬠: $ egrep ââ¬Å"gr(a|e)yâ⬠Important. files ;hazy. shades Or perhaps a mail-filtering program that uses the following regex to single out past correspondence between you and the boss: /(^To:|^From:) (Seaman|Ramsay)/ This says, ââ¬Å"Find a ââ¬ËTo:ââ¬â¢ or a ââ¬ËFrom:ââ¬â¢ line followed by a space and then either the word ââ¬ËSeamanââ¬â¢ or the word ââ¬ËRamsayââ¬â¢ This can make your regexââ¬â¢s extremely flexible, but be careful! Parentheses are also meta characters which figure prominently in the use of . . . Back references Perhaps the most powerful element of the regular expression syntax, back references allows you to load the results of a matched pattern into a buffer and then reuse it later in the expression. In a previous example, we used two separate regular expressions to put something before and after a filename in a list of files. I mentioned at that point that it wasnââ¬â¢t entirely necessary that we use two lines. This is because back references allow us to get it down to one line. Hereââ¬â¢s how: s/(blurfle[0-9]+)/fraggelate 1 fraggled_files/ The key elements in this example are the parentheses and the ââ¬Å"1â⬠. Earlier we noted that parentheses can be used to limit the scope of a match. They can also be used to save a particular pattern into a temporary buffer. In this example, everything in the ââ¬Å"searchâ⬠half of the sed routine (the ââ¬Å"blurfleâ⬠part) is saved into a buffer. In the ââ¬Å"replaceâ⬠half we recall the contents of that buffer back into the string by referring to its buffer number. In this case, buffer ââ¬Å"1â⬠. So, this sed routine will do precisely what the earlier one did: find all the instances of blurfle followed by a number between zero and nine and replace it with ââ¬Å"fragellate blurfle[some number] ;;fraggled filesâ⬠. Backreferences allow for something that very few ordinary search engines can manage; namely, strings of data that change slightly from instance to instance. Page numbering schemes provide a perfect example of this. Suppose we had a document that numbered each page with the notation . The number and the chapter name change from page to page, but the rest of the string stays the same. We can easily write a regular expression that matches on this string, but what if we wanted to match on it and then replace everything but the number and the chapter name? //Page 1, Chapter 2/ Buffer number one (ââ¬Å"1â⬠) holds the first matched sequence, ([0-9]+); buffer number two (ââ¬Å"2â⬠) holds the second, ([A-Za-z]+). Tools vary in the number of backreference they can hold. The more common tools (like sed and grep) hold nine, but Python can hold up to ninety-nine. Perl is limited only by the amount of physical memory (which, for all practical purposes, means you can have as many as you want). Perl also lets you assign the buffer number to an ordinary scalar variable ($1, $2, etc. ) so you can use it later on in the code block. a. OBJECT ORIENTED PROGRAMMING AND JAVA Object-oriented Programming was developed because of limitations found in earlier approaches of programming. To appreciate what OOP does, we need to understand what these limitations are and how they arose from traditional programming. PROCEDURAL LANGUAGES Pascal, C, Basic, FORTRAN, and similar languages are procedural languages. That is, each statement in the language tells the computer to do something: Get some input, add these numbers, divide by 6, display the output. A program in a procedural language is a list of instructions. For very small programs no other organizing principle (often called a paradigm) is needed. The programmer creates the list of instructions, and the computer carries them out. Division into Functions When programs become larger, a single list of instructions becomes unwieldy. Few programmers can comprehend a program of more than a few hundred statements unless it is broken down into smaller units. For this reason the function was adopted as a way to make programs more comprehensible to their human creators. (The term functions is used in C++ and C. In other languages the same concept may be referred to as a subroutine, a subprogram, or a procedure. ) A program is divided into functions, and (ideally, at least) each function has a clearly defined purpose and a clearly defined interface to the other functions in the program. The idea of breaking a program into functions can be further extended by grouping a number of functions together into a larger entity called a module, but the principle is similar: grouping a number of components that carry out specific tasks. Dividing a program into functions and modules is one of the cornerstones of structured programming, the somewhat loosely defined discipline that has influenced programming organization for more than a decade. Problems with Structured Programming As programs grow ever larger and more complex, even the structured programming approach begins to show signs of strain. You may have heard about, or been involved in, horror stories of program development. The project is too complex, the schedule slips, more programmers are added, complexity increases, costs skyrocket, the schedule slips further, and disaster ensues. Analyzing the reasons for these failures reveals that there are weaknesses in the procedural paradigm itself. No matter how well the structured programming approach is implemented, large programs become excessively complex. What are the reasons for this failure of procedural languages? One of the most crucial is the role played by data. Data Undervalued In a procedural language, the emphasis is on doing thingsââ¬âread the keyboard, invert the vector, check for errors, and so on. The subdivision of a program into functions continues this emphasis. Functions do things just as single program statements do. What they do may be more complex or abstract, but the emphasis is still on the action. What happens to the data in this paradigm? Data is, after all, the reason for a programââ¬â¢s existence. The important part of an inventory program isnââ¬â¢t a function that displays the data, or a function that checks for correct input; itââ¬â¢s the inventory data itself. Yet data is given second-class status in the organization of procedural languages. For example, in an inventory program, the data that makes up the inventory is probably read from a disk file into memory, where it is treated as a global variable. By global we mean that the variables that constitute the data are declared outside of any function, so they are accessible to all functions. These functions perform various operations on the data. They read it, analyze it, update it, rearrange it, display it, write it back to the disk, and so on. We should note that most languages, such as Pascal and C, also support local variables, which are hidden within a single function. But local variables are not useful for important data that must be accessed by many different functions. Now suppose a new programmer is hired to write a function to analyze this nventory data in a certain way. Unfamiliar with the subtleties of the program, the programmer creates a function that accidentally corrupts the. This is easy to do, because every function has complete access to the data. Itââ¬â¢s like leaving your personal papers in the lobby of your apartment building: Anyone can change or destroy them. In the same way, global data can be corrupted b y functions that have no business changing it. Another problem is that, since many functions access the same data, the way the data is stored becomes critical. The arrangement of the data canââ¬â¢t be changed without modifying all the functions that access it. If you add new data items, for example, youââ¬â¢ll need to modify all the functions that access the data so that they can also access these new items. It will be hard to find all such functions, and even harder to modify all of them correctly. Itââ¬â¢s similar to what happens when your local supermarket moves the bread from aisle 4 to aisle 12. Everyone who patronizes the supermarket must figure out where the bread has gone, and adjust their shopping habits accordingly. What is needed is a way to restrict access to the data, to hide it from all but a few critical functions. This will protect the data, simplify maintenance, and offer other benefits as well. Relationship to the Real World Procedural programs are often difficult to design. The problem is that their chief componentsââ¬âfunctions and data structuresââ¬âdonââ¬â¢t model the real world very well. For example, suppose you are writing a program to create the elements of a graphics user interface: menus, windows, and so on. Quick now, what functions will you need? What data structures? The answers are not obvious, to say the least. It would be better if windows and menus corresponded more closely to actual program elements. New Data Types There are other problems with traditional languages. One is the difficulty of creating new data types. Computer languages typically have several built-in data types: integers, floating-point numbers, characters, and so on. What if you want to invent your own data type? Perhaps you want to work with complex numbers, or two dimensional coordinates, or datesââ¬âquantities the built-in data types donââ¬â¢t handle easily. Being able to create your own types is called extensibility; you can extend the capabilities of the language. Traditional languages are not usually extensible. Without unnatural convolutions, you canââ¬â¢t bundle together both X and Y coordinates into a single variable called Point, and then add and subtract values of this type. The result is that traditional programs are more complex to write and maintain. The object oriented approach The fundamental idea behind object-oriented languages is to combine into a single unit both data and the functions that operate on that data. Such a unit is called an object. An objectââ¬â¢s functions, called member methods in Java, typically provide the only way to access its data. If you want to read the item and return the value to you, you call a member function in the object. It will read the item and return the value to you. You canââ¬â¢t access the data directly. The data is hidden, so it is safe from accidental modification. Data and its functions are said to be encapsulated into a single entity. Data encapsulation and data hiding are key terms in the description of object oriented languages. If you want to modify the data in an object, you know exactly what functions interact with it: the member functions in the object. No other functions can access the data. This simplifies writing, debugging, and maintaining the program. A Java program typically consists of a number of objects, which communicate with each other by calling one anotherââ¬â¢s members functions. We should mention that what are called member functions in C++ are called methods in Java. Also, data items are referred to as instance variables. Calling an objectââ¬â¢s member function is referred to as sending a message to the object. How to cite Java Based Search Engine, Essay examples
Subscribe to:
Posts (Atom)