Download as pdf
Download as pdf
You are on page 1of 7
s) ‘Tass Notes Topic: U Understand (NETBEANS tegrated Development E What is JAVA? > JAVA isan Object Oriented programming language as well a platform. By using JAVA, we ean write Platform independent application programs, which ean run ‘on any type of OS and Hardware. JAVA is desigoed to build Interactive, Dynamic and Secure applications on network computer system. acteristics of JAVA, : > Object Oriented Language: Java is Object Oriented Language (a real-world programming, style) all with no cost. > Open Souree Produet: It is Open Source i. feely available to > Write Once Run Anywhere (WORA): JAVA Program can be run on any type of HAW and 8 platforms ie. Java programs are platform independent. > Light Weight Code: Big applications can be developed with small code. > Security: JAVA Programs are safe and secure on Network } Interpreter & Compiler based Language: JAVA uses both Compiler and Interpreter JVM) to proxluce portable and platform-independdent object code. > Built-in Graphics & Supports Multimedia: JAVA is equipped with Graphies feature. is best for integration of Audio, Video and graphics & animation. NetBeans ID: NetBeans IDE is used to create java applications very easily using the efficient GUI builder. to develop applications by dragging and positioning GUI components from a palette onto a allows 1g and alignment of the different container. The GUI builder automatically takes care of the correct spacini components relative to each other. 1, Title Bar 2. Menu Bar with pull down menus 3. Toolbars 4, GUI builder: It is an area to place components on the form visually. There are two views of the GUI builder- the Design View and the Source View. We can switch over from one view to another by simply clicking on the source and design tabs directly above the Design Area. 5, Palette: Palette contains controls or components used to create GUI applications. 6. Inspector Window: This window is used to display a hierarchy of all the components or controls placed on the current form. 7. Properties Window: Using this window we can make changes in the properties of currently selected control on the form. 8. Code Editor Window: - It is the area where we write code for our java application. Basics of GUI Applications How GUL app tion works? Diaptical User interface (GUN based applicition comaina Windows, Batons Tes ation, when epee nl Menus ct, known as GUT eompunents, Wile using GUT application, ete le, known as GUI components, While using at sation to take ee ‘Setion. an Event is generated which causes a Message sent to applicati What is Event? An Events refets othe occurrence ofan activity by ase ike ick, double lik et What is Message? ‘\ Message isthe information/request sent othe application when event occur JAVA Tokens: The smallest in Punctuation mark etc. Followi Punetuators ( (J ete), ‘vidual unit in a program is known as Token. It may any word, symbols or ¥/Pes OF tokens used in Java-Keywords, Identifiers, Literals, Operators(+,-,/,", te.) Keywords in Java: Keywords are the reserve words t Can't be used as identifiers or variable name ete, Com, that have a special meaning to the compiler. Key words Couble, int, shor, void. main, while , new ete inonly used key words are- char, long, for, case, if Identifiers in Java: Identifiers are fundamental build i 5 Fave fundamental building block of program and used as names given to variables, objects, classes and functions ete fl bite 7 ‘The following rules must be followed while using identifiers, ¥—Mdentfiersmay have alphabets, digits and dolla(S), underscore () sign, ¥ They must not be Java keywords. ¥ They must not begin with digit v ‘They can be of any length. Y They are Case Sen: ive ie. Age is different fromage. Literals in Java: Literals or constants are data items that have fixed data value Java allows several types of literals like” Literals, String Literals, The null literals. Integer Literals, Floating Literals, Boolean Literals, Character Integer Literals: An integer constant or literals must have at least one +/- digit without decimal point. Java allows three types of integer literals - Decimal Integer Literals (Base 10) e.g. 1234, 41, 497, -I7 ete. Y Octal Integer Literals (Base 8) e.g.010, 014 (Octal must start with 0) Y Hexadecimal Integer Literals (Base 16) e.g. OxC. Oxab (Hex numbers must start with Ox) L or U suffix can used to represent long and unsigned literals respectively. Floating / Real Literals: A rea! literals are fractional numbers having at leastone digit before and after decimal point with + or ~ sign. ‘The following are valid real numbers- 2.0, 17.5, -13.0. -0.00626 The Following are invalid real numbers- 7. 7. +17/2 andl 17,250.26 ete. Other Literals ¥ The Boolean Literals represents either TRUE or FALSE. Italways Boolean type. > A null literals indicates nothing. It always null type. fae 2 racler and mustenclosed in single Heaps eo op {naallonssone non gaphic scters (which can not betyped directly through ceyboartl) by using Escape sequence (\) ‘The following Escape characters are commonly used in Java Horizontal tab). {a (alert Ab (backspace). (Horm feed \n (new Hine), (return Key. ( abst ek san xing que)" ube quote)? ¢question mark). (aul) (ver te 1 String Literals isa sequence of vero or more characters encased in Jouble uae “amit”, Duta types in JAVA: Datatypes ave means to idaniy the type of dia aed asscined OPraONS of hanulling it, Java offers two types of data types. Primitive: These are in-built data types offered by the compiler. Java supports 8 primitive oat, double, char, Boole. data types e.g. byte, short, int, fone, Reference: These are constructed by using primitive data yet sartyes store the memory adress of an object. Clas Interface and Ar of Reference Data types. as per user need, Reference ay are the example interface elements the user interacts ‘Components idgets") are the basic it ‘on a container (like the jFrame). COMPONENTS (ALSO known as "Wi ‘with: jlabels,jbuttons, textfieds ete, Components are placed “There are two types of controls « Parent or container controls: They act asa background for For exarmple-Frame, When we delete a parent control, all its cil parent control al its child controls also move along with it P Child controls: controls placed inside a container control areca For example-Text Field, Label, Button ete. ‘other controls. Td controls get deleted. When we move a led child controls. ced anywhere during the application, Bach” so that it can be referen * at rales for naming variable. The rules and conventions for nam Variable Naming Conventions Each variable needs to have a name s programming language has its own se Variables in Java are summarized below: ‘¢ Variable names are case sen ¢# Keywords or words, which have special m the variable names. ‘¢ Variable names shi «All variable names must b ‘The convention is to always use & underscore (_) and dollar sign ($). aoa ttc ne ft nial eter, variable names may contain letters and digits (0.09) and (_. ‘or special characters are allowed. ing ve. reaning in java, should not be used as ould be short and meaning gin witha letter, an underscore (_) ora dollar sign (S) fetter and avoid starting variable names with $), but no spaces Creating a new Form To create a new application project call 1. Choose File > New Project. Altemately, 2. From the Categories pane select Java and in the Projects P + Emera name (in this case Books) inthe Project Name field and speity the project location by clicking on the Browse button. By default, the project is saved in the NetBeans Projects folder in My ‘Dacumments and so this is the default Project location displayed in tis field 1 nue thatthe Set as Main Project checkbox is selected and clear the Create Main Class field. 5. Click Finish. led "Books" click the New Project icon in the toolbar. ane, choose Java Application. Click Next nes 40 Ug presses or puss 10 WEEE J with the click Clicks om the button at rnin ic Window ot form. ible text or icon to be displayed Frame: Used as @ Bi jLabel: Allows Non-edital user o i scroll ba allows us to ace mukitine input from the or horizontal “The Text Area component iontatically adds vertical of information, This component au required during run tine. : > JoheekBox isl box like component hat is iter marked or unmarked ‘hanges Irom checked to unchecked or viee vers it when itis elicke fomatically. allow him to sceet one of tHe fe option), But radio ide the user several choices and allow oup allowing the user to select sin The eno buttons ae wed 10 po hice the ati butions blog to ten occupy aot of spaee os pa er components sed to ner conden inp ike passwords wih single ne F FCombobos is ike a drop doxen box - you can click a drop-down arrow and! select an option from list whereas jList provides a scrollable set of items from which one or more may DE selected. > JOptionPane allows to create pop-up window or dialog with predefined style JOP ara io information fom th xe, display information 10 He wer OF 0 of both “The major eompon: 1.Class 2. Object 3. Data Members & Methods 4. Access Specifier and Visibility Modes ‘X dtase i used to encapsulate data and methods together in a single unt. It helps the programmer to keep the data members in various visibility modes ‘depending upon what kind of pecans nceds to be provided inthe remaining part of the application, ‘An objec is an instance of a class that is capable of holding actual data in memory locations. Chass and objects are related t0 each other inthe same way as datatype and variables ‘The JTextField, JLabel, JTextArea, JButton, IJCheckBox and JRadioButton are all lasses and the jTextField], jLabell, jTextAreal, jButton!. jCheckBox! and {jRadioBution! components are all objects. The setText(), setEnabled(), pow(), ‘substring() are all methods of different classes. mbination| ens of Object Oriented Programming are as follows: Variables [A variable isa placebolder for data that can change its value during program execution. Variables dare containers used to store the values for some input, intermediate result or the final result of an operation. The characteristics of a variable are: + Ithas a name. + Itis capable of storing values. + Itprovides temporary storage. + Itis capable of changing its value during program execution. Data Types Datatype states the way the values ofthat type ae stored. the operations that can be done on that type, and the range for that type. Numeric Data Types: ‘These data types are used to store integer values only Le. whole numbers only. Floating Data Types: ‘These data types are used to store numbers having decimal points ie. they ean store numbers having fractional values. Character Data Types: ‘These datatypes are used to store characters. Character data types can store any type of values - numbers, character d We . . characters and special characters Operators : ignment Operator: One of the most common ope ‘common operators is the assignment operator value to a variable. ‘ d Arithmetic Operators: These operators perform audition, subtraction, multiplication, similar to mathematical symbols, The only symbol that is different opera by another and returns the remainder as its esti Relational Operator: A relational operator is used to test for some kind of relation ronal operator which is used to assign nd division. These symbols are °%", which divides one n between two entities. A Forms a relational expression or a condition. ‘mathematical expression created using a rel ‘Operator | Meaning | Us99e = eavalie eats whotar too valubs ave equal Talaqnario | Testa whet oa values ave une > Grea an | Fone vaue ot ef expression ater than hat fhe igh = saan] Feat van oT expreon #8 Ta that of he rh = Gam rane | Tote evo of et enantio eater quale than or ecu tat of he ht. = Seat ae]Taa Ta von eT TH eprasOn OHS equalio than ore to that of ho Pht Logical Operator: A logical operator d enote a logical operation. Logical operators and relational operators are xed together to form a complex condition, Logical operators ‘operator [Use Meaning a sie ga bee [a and dave bain wwe 0 arto 1 Ether a orb i ive p ra ais tase Bitwise Operator: Biwise operators are used (o pet tuned with any of the integral types (chat, shot, tpdate and query operations of Binary indexed tre. form manipulation of individual bits of a number. They: can be int etc), They are used when performing, Executing a File Nin that the code for the fist application is ready let us test our fist application To areeate the application simply select Run>Run File or press Shift+F6 ‘Changing Properties of Components “The Properties Window displays the names and valve unenty selected component. We can eit the values + ofthe attibutes (properties) of the ‘of most properties in the Properties window Font property: to change the text writing style Foreground property: to change the text color ‘Text property: to chi thedsplay tat D pe z0216) Tahoma 18 Plan Bi 3590) od ity = Integer. parselnt(S2) s int suni= x+y; a ITF3.setText(""+sum): 2. Write a JAVA code to accept a 2 digit number and calculate the sum of its inta= int b =a 10: int c= a % 10: int sum = b+ c: ITF2.setText("™+sum); Integer parselnt(JTFI getText() oooceo005: } 3. Write a JAVA code to accept a 2 digit number and reverse its digits: ss events sonbvert Ot torso pethate void jHationtiat sae | in Bee : 4. Write a JAVA code to accept any values tween 1 to 100 and check i it is an even number jnt n= Integer.parselatOTFI gerText OX: intr=n% 2; in(r==0) { pa setText ("tis an BVEN No" } Else { rez serText("l is an ODD No."): to accept 3 values and find the greatest. 5, Writea JAVA program pittaninoinin seerieasiceeete era Go soe a = Heneper parsedat oTF2 9ees i art Spee eat ete ra AEE itp gee = werpaare | eect 28 Note: ‘Content developediprepared absolutely from home.

You might also like