Internet and Web Programming KPH 5th Sem

You might also like

Download as pdf
Download as pdf
You are on page 1of 67
INTERNET ANO WWW _ |_Wes Process | (3 HTM 4 davaScret 5 | XML — 6. SOLUTION (2019) EAS-E.19 7._| UNso.veD EXAMINATION MODEL PAPER [ears] insmittes fisher 'No part ofthis book can be reproduced or transmitted ee in any form or by any means. electronic of mechanical without the written permission of Publisher. Q Publishers KAMAL PUBLISHING HOUSE 110/201, Laxmi Tower, | Near R.K. Mission Schoo! & Hospital, R.K. Nagar, G.T. Road Kanpur — 208 012 Contact No. +91 9559401840 Email kamalpubhouse@gmail.com info@kphit Website www. kphindia. Komal Graphics Q_ Composed by Kanpur have been made in the preparation ofthis book nets ‘are responsible for any kind of errors and omiss be subject to Kanpur Jurisdiction only. While all possible effor the author nor the publ In case of any dispute a ice providers, domain name server, interne Web (WWW). World Wide Wat and its ov (URL) Browsers — internet ox firefox, chrome, Mozilla. Search engine, wab proxy server, HTTP protocol ‘Unir-TWwo Wee PROGRAMMING Programming in Java : Core Java : Introd. type, Variable, Arrays, Control Statement tance, Package and _ Interface, Handling, read programming, VO, Java Applet. String handling ing, Event handling, Introduction to AWT AWT controls Layout managers, Menus, Images, Graphics Communication Issues, the Cl Websites, Quality Assurance an and Impact on Web Teams. a UniT- THREE HTML UNITBRER Q Formatting Tags, Links, List, Tablets, Frames, forms. Comments in HTML, DHTML. oo ui = JAVA SCRIPT UersFOUR ava Sexier Introduction, Documents, forms, Statements, functions Objects in JavaScript. Events and Event Handling, Arrays, Forms, Buttons Checkboxes, Text fields and Text areas ta=rve 0D Intodution Do SE Introduction, Displaying an XML Document, Dal an XML document, Document type de Client-side usage, Server Side usage Common Gateway Interface (CGI), PERL, RMI VBScript, Active Server Pages (ASP) Multi-department & Large scale testing, Technological advances 'S, Parsers using XML, compcom [Le kind of serviee or informa’ the local client machines categorized by the services mail server provides the works by HTTP and so it organizations set standards can access it in different displays, interactive collabo: protocols. Many of these protocols progr: search for and retrieve material made protocol. In Internet no one b: ‘The Internet consists primarily of Components of Internet : Internet supports the vanety of components Q.2. What are the applic: Ans. Applications of Intern World Wide Web TelNet UseNet News, Chat, Instant Messages FAQ, RFC «Even chatting is a major use of the intern (4) Job Search : Nowadays, many people search for ‘their jobs online as it is quicker and there is a larger variety of job vacancies present. (5) Hobbies : Those who are having certain hobbies can try to improve on it by reading up on many aspects of their hobby. (6) Research : Research papers are present online which helps in the researcher doing a literature review Q3. Explain e-mail strategies and services on the Internet. ‘Ans.E-mail is the mostly used Internet services. From the E-mail numbers of messages are sending and received. E-mail is the intensive way of sending or receiving information's which can be in text, sound, image etc forms. E-mail is a very useful communication for but it has some limitations. For sending an e-mail on the Internet we required an e-mail address just such as username@hostname Example : xy#@yahoo.co.in Some smaller network also requires a syntax other than name@address format. E-mail Services : Electronic mails provides following types of services : Q) Signature files (2) Sending Messages (3) Mail boxes (4) Mail Filtering (5) File Attachments Signature Files : A signature file is a small text file by which a receiver can known you. A signature appending with the mail messages. The files information like e-mail address, sender name also business name, phone or fax numbers ete. The purpose of these signature files is to make sure receiver that messages can reach to them. It helps business person to give their clients information’s about themselves (2) Keep it short In a window system a signature file can called anything and stored anywhere when its directory and filename information is provided to mailer. Sending Messages : Generally the messages are send to recipients by entering his/her e-mail address in the proper field. ae field is used for it. Next in the ‘subject’ field the title of messages are written that is purpose of messages is a you can leave it blank. erp “ages Tt en mails are send to a group of I n addresses of them come in header lines of the matches was received so everyone know who else got the mail A ‘bee’ field provides features by which the information doce not appear in the message headers sent to the other equipments ‘bec’ stands for blind carbon copy. The other users not known about ‘bec’ who others get the blind copy where frequently used e-mail address is st ess is stored, box field after it is uses as the typing text on it Mailboxes : The mailboxes are used for the incoming and To reply a message a ‘reply’ buttor by reply messages are send to origina others with messages send: Ley Tiltering 3 By mi ring we can tell the mailer have to do with incoming message which match sages sender or of recipients. General obtained by —unkni communication refer File Attachments @ file attachments commonly use Binary (compl MIME (Muttimedia Internet Mail Exten allows the file attachments when a binary: file is send with the meseage than it is enended before sending, At receiver side the Bile again decoded and converted ack into the original format With the help of MIME the tnrge text file are attached with the messages. A large file also can be Gomprese before sending. Numbers of tools are used for compressing Qu. Write down the eseential netiquettes of e-mails. ‘Ans. Essential Netiquettes of e-mails : When communicating with others on the Internet, observe the following commonsense netetiquettes. These etiquettes should be observed whether you are writing an email message, ‘participating in a chat session, or posting a message on the Bulletin Board, Write email message or other communication in complete English sentences. Use regular“English style. Capitalize first letter of a sentence or a name, otherwise, use lowercase letters. Spell-check your message before sending or before posting on the Bulletin Board. Be Polite in your email message or other postings; apply the same general rule of politeness you would if you were talking to a person on his or her face. Make sure you make yourself look good while ‘communicating in cyberspace. Do not write in all Caps. Using all uppercase letters appears as a sender shouting at the recipient. Some words in upperease letters may be used for emphasis. ‘Sign (Write) your name when an email message is, sent. Be discrete with use of emoticons; use of excessive number of emoticons is very distracting. (1) Avoid criticism and sarcasm, (2) No flaming or spamming. Q.5. What do you understand by FTP? ‘Ans.File Transfer Protocol (FIP) : FTP is a standard ‘mechanism provided by the Internet for copying a file from ‘one host to the other. Some of the problems in transferring files from one system to the other are as follows (1) Two systems may use different file name conventions. (2) Two systems may represent text data in different type. ming As a) The directory structures of the (eo ystems may be ferent {erp provides 9 simple solution to all these problems (a) The basic model of FTP is shows in Figure, (3) FIP establishes two connections between the client And server. One is for data transfer and the other is for the control information (8). This fact that PTP separates control and data, makes it very efficient, (4) The control connection uses simple rules of communication only one line of command or a line of response ia transferred at a time. (6) As shown in the ‘component. (a) User interface (b) Control process (©) Data transfer process figure the client has three fe Faure Basic Model of FTP : : FIP Server: The server has vo components (Q)" Thocontral proces (2) Data transfer process Control Connection: (1) The contol commen i made betwen the conta broceses weil data connection Is mae Bete Se ae (2) Control conection sve dr Data Connection: ig the entire process (Data connection uses the port 20 at t - server site ‘onnection is opened when data to be transferred is ready and it closed when transfer of data is over spec shether « file contains text or binary nd whether test Sles use the ASCI or EBCDIC character Authentication Control : It requires clients to authorize themselves by sending s login name and password to the server before requesting file transfers. Telnet also indudes 8 mechanism that allows the élient and server to negotiate options and it provides a set of standard options Q6. What do you understand by TELNET? Ans. TELNET : A terminal emulation program for TC networks such ax the Internet. The Telnet program runs o your computer and connects your PC to a server on tl network. You can then enter commands through the Telnet, program and they will be executed as if you were entering, them directly on the server console. This enables you the network. To start a Telnet session, you must log server by entering a valid username and password. is a common way to remotely control Web servers Q.7. Write Short note on Internet Addressing. Ans.Internet Addressing : Each file in the Inte (URL), The address of a file in the Internet is re by the URL. ‘AURL is determined by the following (2) The type of server or protocol such as IT (2) The address of the serves on the Internet. Internet servers are categorized by th which it provides such as a ‘mail server’ pro mail. A HTTP server provides Hypertext / Qs. Ans.’ Qa. Ans, ww yahoo com-> Indicates the name of the server where, www = It shows a web server jicates commercial enterprises When we use hypertext documents on the web this initial file called the home page ‘com single interface. The www have its own pro (Hyper Text Transfer Protocol). WWW also include What do you mean by World wide web? World Wide Web : It is a system of ‘rhet. protoc FTP, TelNet protocols. WWW or Web can work multi up of fi How a connection is established to the Inte lia and advanced Programming languages the fastest growing components of the Int based upon the hypertext as retrieval. Hypertext is a docum connect to other documents and know: be words or graphics types Hypertext for th (Hyper Text Markup La World Wide Web? -Before connecting Hardware 1 Software t results the right software's are also necessary. The operating system for the Internet must be uptodate. To make connection, connection software is needed. This software allows your computer to dial into an Internet access provider, establish an account, The Internet access providers can provide point to point protocol connections or serial line interface protocol connections. Both protocols allows you to run independent, software packages such as web browsers either one at a time or simultaneously. Browser : Browsers are links for the access of the sites. ‘The browsers like ‘Netscape navigator’ or ‘Internet explorer’ dre very common use browsers. Both browsers allow for the use of plug-ins, for extra software applications that runs as if they are an integral part of the browsers. Connections : To access the Internet the ‘network connections’ or ‘dial up connections’ are used. Some new connections for Internet are: (1) Cable Internet (2) Satellite connection (8) Integrated Services Digital Network (ISDN) (4) Wireless Connections Q.10.Discuss the utility of Netscape Navigator Browser of Internet. ‘Ans.Netseape Navigator : Netscape once Navigator, also known as Netscape, is a proprietary web browser that was popular during the 1990s. Once the flagship product of Netscape Communications Corporation and the dominant browser in usage share, its user base had almost completely evaporated by 2002, partly due to the inclusion of Microsoft's Internet Explorer web browser with the Windows operating system, but also due to lack of significant innovation after the late 1990s. Netscape’s demise was a central component of Microsoft's antitrust trial, where the court ruled that (among other things) bundling Internet Explorer with Windows was an monopolistic business practice. Protection against phishing scams (4) Easily customizable security settings (6) One click privacy options (@) Secure password and form fill Time-Saving and Easy to Use : (1) Tabbed browsing (2) Multiple toolbars (8) Improved-bookmarking Q.11.What is Ecommerce? ‘Ans. Ecommerce, also known as electronic commerce or internet commerce, refers to the buying and selling of goods or services using the internet, and the transfer of money and data to execute these transactions. Ecommerce is often used to refer to the sale of physical products online, but it can also describe any kind of commercial transaction that is facilitated through the internet. Whereas e-business refers to all aspects of operating an online business, ecommerce refers specifically to the transaction of goods and services, history of ecommerce begins with the first ever online sale: on the August LL of manage cb wy the band Sting to his friend through his website NetMarket, an American retail platform. This is the first example of a fansumer purchasing product from a business through ree etld, Wide Web—or ‘ecommerce’ as: we commonly Since then, ecommerce has evolved to easier to discover and purchase throug and marketplaces. Independent fr: businesses, and large corporations have ecommerce, which Types of Ecommerce Models ecommerce models that is a good or service to an individual consumer (e.g. You buy a pair of shoes from an online retailer), Business to Business (B2B) : When a business s 1 good or service to another business (e.g. A business cells software-as-a-service for other businesses to use Consumer to Consumer (C2C) : When a consumer sells a good or service to another consumer (e.g. You sell your old furniture on eBay to another consumer), Consumer to Business (C2B) : When a consumer sells their own products or services to a business or organization (e.g. An influencer offers exposure to their online audience in exchange for a fee, or a photographer licenses their photo for a business to use). Examples of Ecommerce : Ecommerce can take on a variety of forms involving different transactional relationships between businesses and consumers, as well as different objects being exchanged as part of these transactions, “@ (1) Retail : The sale of a product by a business directly to a customer without any intermediary. (2) Wholesale : The sale of products in bulk, often to a retailer that then sells them directly to consumers, (3) Drop Shipping : The sale of a product, which is manufactured and shipped to the consumer by a third party. Q.12.What is video conferencing? Ans. Videoconferencing (or video conference) means to con conference between two or more participants at differer sites by using computer networks to transmit audio and data. For example, a point-to-point (two-person) vide conferencing system works much like a video teley Each participant has a video camera, microphont computer. As the two s or her speakers mounted on his ticipants speak to one another, their voices are carried fe vetwork and delivered to the other's speakers, and over the n “ihatever images appear in front of the video camera appear in a window on the other participant's monitor. Multipoint videoconferencing allows three or more participants to sit in a virtual conference room and Communicate as if they were sitting right next to each other. Until the mid 90s, the hardware costs made videoconferencing prokibitively expensive for most organizations, but that situation is changing rapidly. Many analysts believe that videoconferencing will be one of the fastest-growing segments of the computer industry in the latter half of the decade. Q.13.What is e-business? ‘Ans. E-business (electronic business) is the conduct of business processes on the internet. These e-business processes include buying and selling products, supplies and services, servicing customers; processing payments; managing production control; collaborating with business partners. sharing information; running automated services; recruiting; and more. E-business can comprise a range of functions and services, ranging from the development of intranets and extranets to e-services, the provision of services and tasks over the internet by application service providers. Today, as major corporations continuously rethink their businesses in terms of the internet — specifically, its availabilty, wide reach and ever-changing capabilities ~ they are conducting e-business to buy parts and supplies, from other companies, collaborate on sales promotions and conduct joint research. As e-commerce has accelerated, stringent security protocols and tools, including eneryption and digital certificates, were adopted to protect against hackers, fraud and theft. Nonetheless, security and data Privacy remain big concerns conducting business built employee domain name) The port number on the sery, (4) The location of “rver (optional) the resource i i fs “Source in the directory structure A fragment identifier toptional) Also known as a Universal Resour ers wurce Locator (URL) or Web address. A URL is a type of uniform resourc identifier (URD. In com: 6)" sults in Web content rest sideor or ather line data. = ee ga search engine 10 8 Us armed vi sults page (SERP). known as a search engine res) ct vice that allows ‘earch engine is @ Se alee Web Server Seotych for content via the World vile Internet users to St ters keywords or key phrases int Web (WWW). A wae ceives a list of Web content results in search engine ant re mages, videos or other online data, ee see cata vequrned via a search engine to a user is lis (SERP). th engine results page ( known os Mache is the most widely used web server Apache «eloped and maintained by Apache Software seamjation, Apache is an open source software available for free. It runs on 67% of all web servers in the world. It is fest, reliable, and secure. It can be highly customized to mest the needs of many different environments by using extensions and modules. Most WordPress hosting providers use Apache as their web server software. id receives a list of sh engine am we form of websites ‘The list of content ret mon practice, the term URI isn't However, WordPress can run on other web server software jae or i used synonjmously with URL, eventhough, BOWS is technically incorrect > ).16.What is IIS? Q.15.What is internet explorer? i Ans.IIS is a web server that runs on the Microsoft Ans. Internet Explorer : ternet Explorer (IE) is a product from -NET platform on the Windows OS. While it’s possible to software giant Microsoft. This is the most commonly used run IIS on Linux and. Meee using Mono, it's not browser in the universe. This was introduced in 1995 along recommended and likely be unstable. with Windows 95 launch and it has passed Netscape (There are other options, which I'll present later). It’s popularity in 1998 versatile and stable, and it’s been widely used in Googie Chrome Production for many years. Version 10 is the most current. and its beta ve Q.17.What is proxy server? Ans.A proxy server 18 @ server (a computer system or an is web browser is developed by Google was first released on September 2, rome is known to be h its global share 2008 for Microsoft Windows. Today ‘one of the most popular web browser 10%. lies aoe mee x is a new browser derived from other servers. A client connects to the proxy server, requesting some service, 88 a file, connection, web page, from a different serv such or other resource available er and the proxy server evaluates the ‘0 simplify and control its complexits x ‘ed to add structure and encapsulation to distributed systems, ae ‘Types of Proxy Servers : A proxy server may reside on ve user's local computer, or at any point between the ‘s computer and destinstion servers on the Internet, ‘A proxy server that passes unmodified requests ang responses is usually called a gateway or sometimes q tunneling proxy. 'A forward proxy is an Internet-facing proxy used to @ @ retrieve data from a wide range of sources (in most cases anywhere on the Internet). (a) A reverse proxy is usually an internal-facing proxy sed as a front-end to control and protect access to a server on a private network. A reverse proxy ‘commonly also performs tasks such as load-balancing, authentication, decryption or caching. Q.18.What is DNS? How does DNS work? . ‘Ans. The Domain Name Systems (DNS) is the phonebook of the “Internet. Humans access information online through domain names, like nytimes.com or espn.com. Web browsers interact through Internet Protocol (IP) addresses. DN’ translates domain names to IP addresses so browsers can load Internet resources. Each device connected to the Internet has a unique IP address which other machines use to find the device. DNS servers eliminate the need for humans to memorize IP addresses such as 192,168.1.1 (in IPv4), or more complex newer alphanumeric IP addresses such as 2400:cb00:2048:1::c629:d7a2 (in IPv6). Working of DNS : The process of DNS resolution involves converting a hostname (such as www.example.com) into @ computer-friendly IP address (such as 192.168.1.1). An IP address is given to each device on the Internet, and th: necessary to find the appropriate Inte! address resolution, hardware For the wel e webpage : DNS rst the process behind the nt ieee about the different important rg query must pass between components IDNS lookup occurs “behind the 3,°'no interaction from the user's the initial request. ; from NS servers involved in loading a ‘The recursor can be thought of as a @) DNS Or asked to go find a particular book -@ CO) (4) librarian who designed to rec ‘ary. The DNS recursor is a server 'e queries from client machines through applications such as web browsers. Typically the recursor is then responsible for making additional requests in order to satisfy the client's DNS query. Root Nameserver : The root server is the first step in translating (resolving) human readable host names into IP addresses. It can be thought of like an index in a library that points to different racks of books - typically it serves as a reference to other more specific locations. TLD Nameserver : The top level domain server (TLD) can be thought of as a specific rack of books in a library. This nameserver is the next step in the search for a specific IP address, and it hosts the last portion of a hostname (In example.com, the TLD server is “com”) Authoritative Nameserver : This final nameserver can be thought of as a dictionary on a rack of books, in which a specific name can be translated into its definition. The authoritative nameserver is the last stop in the nameserver query. If the authoritative name server has access to the requested record, it will return the IP address for the requested hostname back to the DNS Recursor (the librarian) that made the initial request. device - like a street address is used to find a particular ; Q.19.What is opera Browser? home. When a user wants to load a webpage, a translation must occur between what a user types into their wel browser (example.com) and the machine-friendly addres* cate the example.com webpage. iOs, Chinese-owned company Opera Software A p Ans. Opera is a web browser for Microsoft Windows, Android, developed by macOS, and Linux operating syst. Opera Software is a Norwegian software company publicly listed on the NASDAQ stock exchange, ownership and control belonging to Chinese bus Zhou Yahui, founder of Beijing Kunlun Tech specialises in mobile games and Chinese cyber sen eden company Qihoo 360, Opera is a Chromium-based brow ner te fe Media Independent : It means, any type Paes ce Blink layout engine. It differentiates itgciy (2) HTTP is Media iver et gas both the client because of a distinct user interface and other features, °° of data can be sent by HTT ante the data content, Opera was conceived at Telenor as a research project an the wared for the elient as well as the server to in 1994 and was bought by Opera Software in 1995. It get Lee are onutan BAS pela anine fer erorriatel commercial software for the first ten years and had st. a own proprietary Presto layout engine. The Presto versions oe Stateless : As mentioned above, HTTP is S Dien reset sassy sorels, but Presto Sevelopeian; 19) ER Te TE a aivachsenclh oP ETP being ended after the big transition to Chromium in 2013. © stateless protocol. The server and client are aware There are also three mobile versions called Opera of eachother only during a current requost. ‘h other during 1t knows about ead veand response only. Further requests .ction like client and server are ent and se wnt request ade on new connes | ~ Mobile, Opera Touch and Opera Mini. A gaming browser ‘Afterwards, both of them forget about each other. Due - called Opera GXis coming soon. to this nature of the protocol, neither the client nor Q.20Explain HTTP protocol in brief. the browser can retain information between different Ans.The Hypertext Transfer Protocol (HTTP) is an requests across the web pages. application-level protocol for distributed, collaborative, HTTP/1.0 uses a new connection for each hypermedia information systems. This is the foundation for __request/response exchange, where as HTTP/1.1 connection data communication for the World Wide Web (i.c. internet) __ may be used for one or more request/response exchanges, since 1990. HTTP is a generic and stateless protocol which Basic Architecture : The following diagram shows a very can be used for other purposes as well using extensions of basic architecture of a web application and depicts where its request methods, error codes, and headers. HTTP sits: Basically, HTTP is a TCP/IP based communication Protocol, that is used to deliver data (HTML files, image files, query results, etc.) on the World Wide Web. The default port is TCP 80, but other ports can | be used as well. It provides a standardized way for computers to communicate with each other. HTTP specification specifies how clients' request data will be constructed and sent to the server, and how the servers respond to these requests. Basic Features : There are three basic features that make HTTP a simple but powerful protocol () HTTP is Connectionless : The HTTP client, ie. a browser initiates an HTTP request and after a request is made, the client waits for the response. The server processes the request and sends a response en back after which client disconnect the connection. So Figure The HTTP protocol is a requestires; based on the clientiserver based architecture where web browsers, robots and search engines, ete. act like HTTP Gents, and the Web server acts as a server Client : The HTTP client sends a request to the >= 2) ee som “| sane as ¢ =| a ae |= . ce | Bivise AND assignment operator. | same as 68) ——S nee r= | Biise ease OR and Tie | as _ “I eecesm — | ssstonentoprtor_ "| SoS | Rinse OR ad amt sa erty sce” | Q6. What ; dana saanmtan hy ae pee data value, A varigblenees oh memory that can contain a ble thus has a data t ‘covered in mi eta maa * ra od detail in the text on Java date ty Me waa src ra are typically used to store gieh you peer needs to do its job, (eg. country codes, money ‘a ey temporary results of multi step c tain the dean ta saicyeat seca sng on en } } we can te makes the coe optimized, o dex 5 ta data located at an int We can sin size of element eal he me To sae te ns aork js used in Java which gr0% erstand by control statements in 1 the order of exeeution of the program, based on e orde trol statements can be divided inte java’ 5. Con ‘Ane gic and values Tn Java, cont roving three categories o the election Statements iteration Statements jump Statements Selection Statements : Selection ‘ontrol the flow of program execut outcome of an expression or state during runtime. ‘Selection statements can be divided into the following categories (1) The ifand ifelse statements statements allow you to tion on the basis of the of a variable known (4) The switch statements ‘The first contained statement if statement only executes when ion is true. If the condition is false and keyword then the first contained skipped and execution continues with ‘The If Statements : the rest of the program. The condit that returns a boolean value Example: package com. deepak main; limpor java.util. canner, public class Demo { pubic static void main(String) args) ( int age; ‘Scanner inputDevice = new Scanner System System.outprin('Please enter Age: e.nextint); y Sisemoutpintn-atove 18% } The if-else Statements : In if-else fatements, if specified cor mn in the if statement is false, thon Statemet after the else Keyword (that can be a bine execute. “ Example: package com.ceepek main; impor java.util Scanner; pubiic ot { IseDemo Public static void main( Stingl J args ) { tage Scanner ape = new Scanner Systemin System outpace enrages) 29@ = inputDevice.nextini(); * ‘The ifelse-if Statements : Thi else keyword can be another if or That would looks is statement following the statement. nj sting 298) tem.in ) mioge: joe = new Scar a Sor pte err ADE) tem out print “not matched . ent is a + The switch statem Pe Ste Statomement The switch statement eee mmulti-way branch statem‘ ee anveution of a program. It provides a better alternative jon of a cae large series of ifccondion>inrement aoe Poo : ‘The initialization block executes first before the loop decrement 2ekage com deepak main, pubte ass WhleDeme Publi tae void main Sting args ) elements, Example Package com deepak main; Pubic class Fore zchDomo Public static void main Stngt | args ) Jump Statements : Jump statements are used to unconditionally transfer the program control to anothe, art of the program. Java provides the following jump statements (break statement 2) continue statement (8) return statement Break Statement : The break statement immediately Quits the current iteration and goes to the first statement following the loop. Another form of break is used in the switch statement. ‘The break statement has the following two forms Jo pase dos stl ing 298) C le sever SH , e 4 se tintvar® © em out pint Srere=3) ‘rea ) ) ‘ed for when we i: This is us ve | abeled Break Sam contol ‘out of nested loops ant t0 jump multiple loop. jle = Fat nh pubic class LabeledBreakDero y public static void main( String(] args ) { o;var< 5:¥a! (var is:*+ va") utr for(int vart =O; vart <5; ari++ ) © setintvan = ta <5:¥02++) { System outpritin( "vart*+ vart +", var2:" + var2 (vant =3) break Outer, y } ) Continue Statement : The continue statement is used when you want to continue running the loop with the next iteration and want to skip the rest of the statements of the body for the current iteration. ” The continue statement has the following two forms pbc class UniabeledContinveDemo public state void main Stingl) args) for( intvart =0;vart <4: vart++ ) * for(int var2 = 0; var? < 4; var2++ ) © (va continue; __ System out pintn( "Var + vart +", var"+ var) } i Labeled Continue Statement : This statement skips the current iteration ofthe loop with the specified label. Example: package com deepak main; bic lass LabedConineDemo pale sae wid man Str] as) Outer: for(int var { for(intvar=,vaa vag==2) continue Outer, System.out printing "var." + vart + *, vara" + var? O;vart <5; vart++ ) ra) } } } } Q.9. What d lo you mean by Inheritance? Elaby Aas Taher eae of inheritance by giving example.” ‘ne tnheritance: Inheritance is the process by which ob a mass acquires the properties of objects ohanothen | in :pports the concept of class ‘flying bird’, which is a nce than one Figure Proefeatares OM Tg ig called cass may inhOr ore than one supe! dias wi : oe etow are various PES OF elo m one by e class wl B would be a child cl: saat each one of the ye and flow diagrams. nad hows that class B ex ynich is A. Here A is 8 pare! ‘inheritance is damn Jass extends another yheritance. The ‘tends only int class of B and Figure : Si ‘System.outpr Class B extends A Inheritance inheritance example program in Java ic void method) inBase class method"); }) to the concept (Or inherits) more th: inheritance we learnt earlier ha base class or parent. The ‘ Problem wi inheritance” is that the derived clase ey manage the dependency on two base clasmea A 8 ¢ Note 1 aus: Mali Inheritance iot : Multiple Inheritance is very rarely u; software projects, Using multiple inheritance <4,” leads to problems in the hierarchy. This resule unwanted complexity when further extendin, class. Note 2 : Most of the new OO lan, guages Talk, Java, C# do not support multiple Multiple Inheritance is supported in C- (3) Maltilevel Inheritance : Multilev inherits refers to a mechanism in OO technology where fs can inherit from a derived class, thereby making derived ae base class for the new class. As yo can see in below flow diagram C is subclass or chi class of B and B is a child class of A. wes oni - by 8 Figure : muh Inheritance Multilevel: Inheritance example program in Java i public void methodX() Stompin cas X method"); ec incsving 295) publica vid™ ‘hod © gxjz new Zi rent class me Zoho k net ed kind of ob b ical Inheritan’ d many Sul (Hierarchical, Tess is inherited Py nherits inhertane,ciow example class Mase class) of disses, Jn below nt dl fhe same cla85 B,C&D. f D Hierarchical Inheritance 6 Q10.Explain the term Package in det: ‘Ans.Package : Packages are used in Jay naming searchingflocating and Hybrid Inheritance : In that hybrid inheritance multiple inheritance. Bh ple terms you can say is a combination of single and ‘A typical flow diagram would below. A hyb! itance ean be achieved v2 same way as multiple inheritance can Yerfaces, By using interfaces you can le as well as hybrid inheritance in Java. 5B acon Figure : Hybrid Inheritance order to prevent access, to make interfaces, control usage of classes conflicts, to ‘ ime space ting packages in Java are nut funetio bundled in this package : m tions ang Programmers can define theit own packa bundle group of eastesnterfaces, ee. Tis a good nf, to group related classes implemented by you so! (te Programmer can easily determine that the ell * interfaces, enumerations, annotations are related,“ Creating a Package : When creating a package should choose a name forthe package and put a paket statement with that name at the top of every source fe that contains the classes, interfaces, enumerations, qu annotation types that you want to include in the package The package statement should be the first line inthe souree file, There ean be only one package statement i, each source file, and it applies to all types in the file. If a package statement is not used then the class interfaces, enumerations, and annotation types will be put into an unnamed package. Example:Let us look at an example that creates « package called animals, It is common practice to use lowercased names of packages to avoid any conflicts with the names ot classes, interfaces. package animals rat Q.11.What do you mean by classes? Ans. lasses : Classes are the group of objects which have same properties, common behaviour and common relationship. Each class defined a set of individual objects Classes define the state and behaviour or the basic Program components known as object. Classes create the objects and objects use methods to communicate between them. Such as the Human is a class, or in polygon clase triangle, square, rectangles are its object. In Java programming everything is inside the class “ass rain ting 298 UD) iber"); ist tin(Fibonacci num “gem our & ; { + system.out.printn (13); it ple (<= 100) ) d 2 (.18.What san ners interface is ikea stripped-down a a ae aoevaset of methods that an instance must class: It specifies a set handle, but it omits inks ations imrleffetoriented programming is sometimes modeled 2s cammunication between objects—one object talks to, ot sends a message to, anotaer object by invoking a metho on it, In this view, an interface in the Java language specifies the bare minimam one object needs to know in ritance relations and method 7 bject: a set of abs that is, methods minus any implementation ot Put another way, an interface specifies how y, an abject, but says nothing about what king ‘handle your messages. It is the job of one or ma instances to provide the substance behind an a" ‘Promise. etfag " ‘A class implements an interface by declaring implements the interface and by petty implementations for all methods contained in the inj, Despite not having any implementation, an nye embodies both form and intent. When you defn interface, you specify the set of methods in the inteng,"* you should also specify the intended meaning of « method. Correspondingly, implementing an inter requires that a class mateh the interface in both form ‘intent: ~ (The cass provides implementations for all, ‘methods in the interface ' (2) The class declares explicitly that it implements th interface Because both steps are required, implementing. ap interface is guaranteed to be a deliberate coco by ti, class's author. Simply having the methods as a interface is not sufficient. “ns s For example, Applet subelasses commonl ple, Applet subelasses commonly implemen the Runnable interface in order to run themedes mt Separate thread. The Runnable interface in the jor Package declares just a single run method taking Eegameters: A Runnable Applet subclass must thet sale fat it implements the Runnable inerioce ced must define a run method m PUBIC class MyApplet extends java applet __ iloments Rennapis PO APHet lc void rund ¢ : cade to run the applot in @ separate thread Oca of obj , nga nine ome of the method declarations. This ar fbi compil amming 2 spplet Oo trons, play sounds, disp! erations, al applet is develop lovally and store i Internet inal Piet execution not requires any (a) A local ap cranes ores or loaded int directories @ cE . Rac Ae store on a remote computer and ° A rane oO Jocal system with the help of the for er load a remote applet Internet connection is raenote applet can be load with the its address on the web on the local systom. The address is known as L) Uniform Resource Locator. tools, ‘are created in a well defined cycle. At the execution time of applet the following methods are used init: By this method, the initialization of an take place. It is used for loading graphi stop(): Bx , Apple’ State Q.15.Create an applet, which draw the following figure A ‘Ans. Create an Applet Code : importava aut Buble cass demo extend java. applet Applet ‘ etl ed pin (Gopi 9) crt 100 400,90 400) 8 crautne 10000-7450) Daten 200,400 380 0), {g.drawd.ine( 300,400,250, 450). Sravtin( 70,450,350 480) ‘.drawine(70.450,70,600), routinet 250 45,250.50) 8 craw. in( 360 450350500) {9.drawt. ine 70,600,350, 600): a srawtoct270 60060110 SetBackgroun{ Color tia) 1 A.10) 35.10% ; the various AWT controls? Explain all of qi6.What are then i VT Controls vous AWT Controls: Ane ictal: K Label objec 8 Siero is class creates a labeled button. ___| Sa cis. oraphical component fat can Ta] Button Tis S55 or Ata ono apis be in esther an on(true) or off (false) state. _ __| Bea Box Group {The Checxbox Group cass 1s used to ro el of checkbox 1 ere List component presenis thé user with a soroling © | ictoftn toms mee (© | Text Field : A Text Fic alos fore eding ofa single tine oftext, Text Area: A Text Area object is a text component the lasses representing graphical Seroll Bar : A Scrollbar control a tle and a border used to take some form (3) [File Dialog : A FieDialog dow rom which the user can Q17.Explain different types of controls in brief that aw ‘supports, Ans. Controls are components that allow a usc your application. AWT supports the controls : Labels, Push Buttons, Check Bc a Lists, Scrollbars, Text Components. These subclasses of Component. ‘Labels : The eases contol to use is a label. A label is object of type Label, and it contains a displays. Labels are passive controls th Pa any interaction with the user. Label defines the followrint constructors ion creates a blank ‘The second version creates a la string specified by str. This string third version creates method. You can obtain the c getText( ). The following example adds them to an applet. impor java.awt* [import java apple Component in onder to enable user to seers values. Dialog =A Dialog contol repress atop iva of ir a at nb rom 8 scar event eras oe Bulton. Butt Button (a) Button(String str) ve first version ereates an empty button, The ond first pty button. The sect The “After a button ). setae | These methods are es fol 5 vod oetabeltring str) (2) String getLabel for the button. Fer ctr becomes the new label f tha to nattons label ing method on the ActionEvext B30 import java. import ava.awt.event*; import java applet.” . pole; applet code="ButtonDemo" width= ou widt=250 hoight=15p. pubic class ButtonDer cto m0 extends Appt, ‘ oe Sting msg ="; Button yes, no, maybe, pati iat " yes enon ons) va majo no ato dec add(yes); a eae) sa) soathteLsone "net sere |v as ei eco acrramacneo) Stn sr= a gtActonconnan cranes) “ yO "Youressd Yes eter omatrnery 'msq = "You prossed No.” else { } repaint) msg = "You pressed Undecided.” public void paintiGraphies g) 9 drawStringimsa, 6, 100) Sample output is. as follows actionPerformed ). Code Fe ann that ws aa joses A dmc Ht or aaa aba = nin ‘ oes ie that deseribes ‘what option Ceci cried set een YOU ES ho une indie Ce Seki Sc boxes a le ia tron spore then om be Oe 3 Che ne ‘tr, boolean on) Checkbox String st vt rean on, CheckboxGrouP i Gecteiane ein sheckboxGroup ¢bGroup, OE aang ars Chek we check box whose label is aan rm creates 4 a he Seino he chsk bo is unheced aaares a check box whose label is The send fom, eae de eck box is unchecked sees by ste The state 3 specie oem allows you to set the initial state of the Th thir fone is trac, the check box i initially checked heck or itn cleared. The fourth and fifth forms create @ se hor whose label is specified by str and whose group ci ed by cbGroup. If this check box is not part of aoe then cbGroup must be null. (Check box groups are Ecnbed soon in this article) The value of on determines the inital state of the check box. To retrieve the current state of a check box, eal etStatel ), To set its state, call setStata) You can obtain the current label associated with 2 check box by calling getLabel ). To set the label, call setlabel). These methods are as follows (boolean getStato: (2) void setStatatboolean on) “Sppet code="CheckboxDemo" width=250 height t=2005 public class Checkbo» Demo extends ADEE! impomey, {String msg =~; . (Checkbox Win9B, winNT, solar on: + Solaris, mac; {Wing = new CheckboxWi = findows 98/XP*, null, ‘ONT = new Checkbox Windows NT/2000"); tr metre ceo srs 7 ee add(wings), mcs repaint) splay current state of the check bo: Public void paint(Graphics g) a { msg = "Current state: msg =" Windows NT/2000:* + wioNT gt g.drawString(msg, 6, 120); ose msg =" Solas * + stars gotta 9.drawString(r sisi msg" Maco G draustingtnse, 6, ‘Sample output is as follows = Figure choice, ides a compact, multiple: te: The List lass PPT the Choice object, which single selected item in the pee a List ‘any number of choices in structed ta SPO Sreated to allow multiple the third form, if multiple Select is select two or more items at a time. item may be selected. To add a jnto view as needed). In true, then the user may itis false, then only one it Itit is fae the list, call add( ). It has the following two selection to forms (1) void add(String name) @) void add(String name, int index) Here, name is the name of the item added to the list. ‘The first form adds items to the end of the list. The second fom adds the item at the index specified by index. Indexing begins at zero. You can specify —1 to add the item to the end of the list. For lists that allow only single selection, you can determine which item is curr selected by calling either getSelectedItem( ) or getSelectedindex( ). These methods are shown here (Q) String getSelectedItem( ) (2) int getSelectedIndex( ) ‘The getSelecteditem( ) method returns containing the name of the item. If more than one item is BM The first item is at index 0. n selected, oF if no selection hae yt be returned. For lists that allow multiple selon use either getSelectedltems( ) or getSelecsey 7 my” shown here. to determine the current selectis (A) String] getSelectedtems( ‘ens (2) int) getSelectedindexest ) setSelectedltems ( ) returns an array names of the currently selected a th getSelectedIndexes ( ) returns an array contain" idexes of the currently selected items. To obtar® number of items in the list, call getltemCount (), Yq set the curently selected item by using the selow ° method with a zero-based integer index. These meth(y are shown here oa Q) int getltemCount () (2) void select{int index) Code: import java.awt."; imped java atevent' import java applet"; “Spe cote Use” it heht8> 7 art, 8 Ueno exes Amt implores {Ustos, trouser ‘String msg = ™; put void nit) (os=now List, ne) rouser= new Lis, iradttenstoosia’ 0s.add("Windows 98/XP"); 08.add("Windows NT/2000"); sede Soars) os.add("MacOS*); Tadd tems to browser it browser ade-Netscape 3.) browser.add{"Netscape 4.x"); browser.add("Netscape 5.x"); browser add Netscape 6.) browser.add("Intemet Explorer 4.0"); browser.add("internet Explorer 5.0") ; browser.add("intermet Explorer 6.0"); exe dept tenet) )) enctont tr itener ee teenth ‘0 pet esis, 0328 tran o it ae) Figure 1d to select continuous Seroll Bars : Seroll bars are use stpesbetween a specified minimum and maximum. Scroll tally or vertically. A scroll bar bars may be oriented horizont js actually a composite of sever: tad has an arrow that you can click to move the current tabe of the seroll bar one unit in the direction of the arom. The current value of the scroll bar relative to its nrinimum and maximum values is indicated by the slider bor (or thumb) for the scroll bar. The slider box can be dragged by the user to a new position. The scroll bar will then reflect this value. In the background space on either sid of the thumb, the user can click to cause the thumb to jump in that direction by some increment larger than | ‘al individual parts. Each in the third constructor just described, To obtain the current value of the se etValuel ). It returns the eurrent setting, To setValue( ), These methods are ov follows : (1) int getValuet ) @) void setValuetint newValue) Here, newValue specifies the new vah bar. When you set a value, the slider box bar will be positioned to reflect the new value. You ean retrieve the minimum and maximum’ valuce getMinimumn( ) and getMaximum< ), shown here i ‘getMinimum( ) (2) int getMaxim ordinates of each drag event bars. An asterisk is displayed at import java awe; ‘impor java.ava.event. cone ia ‘ei agusentvalechangea(AdustmentEvent 26) } ose void Ne ju vl pbc : repaint): \ 1 bars to reflect mouse dragging. pe ousbraggeanause vent) repaint) Necessary fr MouseNotonListerer pi vd novcoved Mouse ve me) ax Somove outst isa shown below (1) String getText( ) (2) void setText(String str) Here, str is the new string. ‘The user can sele Portion of the text in a text field. Also, Portion of text under program control by getSelectedText( ). These methods are shown here (String getSelectedText( ) (2) void select(int startIndex, int endIndex) Example : Here is an example that creates the classie user name and password screen : Code : import java.aw.* import java.awt.event.; sme, Passi fest poe ye: Label RIGHT): ne ON RIGHT) ada ee receive action events 1 etonistner is roe enone) } yressed Enter, nee jonPerformed(ActionEvent ae) paseo ! repaint(): 1 evr par(Grapies 9) : (Name: " + name.getText(), 6, 60); ogous Saoded edn name nae goto ot Om a: * + pass.getText), 6, 100} sarawstingt (is.iseuss the purpose and utility of layout managers for AWT. Create the following frame using the AWT components :

You might also like