Page 1 :
UNIT- 2, , INTRODUCTION TO PROGRAMMING, , CHAPTER- PROGRAMMING USING IDE
Page 2 :
Introduction, Language is a medium to express our view and feelings. To communicate, with computer we need a language which a computer can understand., A set of structured instructions is called a program which tells the computer, what to do., The process of writing specific instruction in a computer language is called, programming., Person who writes such programs is known as a programmer or coder., , What is Java?, Java is a high level computer programming language because it is, similar to ordinary English language. Originally known as OAK ., James Gosling initiated the java language project in the year 1991., The Sun Microsystem released the 1st public implementation as java 1.0, in 1995. It is a Write Once Run Anywhere (WORA) type language, providing no-cost runtime on popular platforms., , OOPs, • Java programming language is completely based on OOPs concept, • OOPs stands for Object Oriented Programming System. Object, means a real world entity such as a pen , chair , table , computer, watch etc., • OOPs is a methodology or paradigm to design a program using, classes, object s., • It simplifies software development and maintenance by providing, some concept.
Page 3 :
Object, Any entity that has state and behavior is known as an object. For, example, a chair, pen, table, keyboard, bike, etc. It can be physical or, logical. An Object can be defined as an instance of a class., Class, Collection of objects is called class. It is a logical entity. A class can also, be defined as a blueprint from which you can create an individual object., Class doesn't consume any space., Inheritance, When one object acquires all the properties and behaviors of a parent, object, it is known as inheritance. It provides code reusability. It is used, to achieve runtime polymorphism., Polymorphism
Page 4 :
If one task is performed in different ways, it is known as polymorphism., For example: to convince the customer differently, to draw something,, for example, shape, triangle, rectangle, etc., Abstraction, Hiding internal details and showing functionality is known as, abstraction. For example phone call, we don't know the internal, processing., Encapsulation, Binding (or wrapping) code and data together into a single unit are, known as encapsulation. For example, a capsule, it is wrapped with, different medicines. A java class is the example of encapsulation., , Features of Java, 1- Java is Platform –independent language., 2- It is highly reliable., 3- It is Portable., 4- Programs developed in it can be run on any system., 5- It is object oriented., 6- It is a simple language., 7- It is a robust language., 8- It is a multithreaded language., 9- Java is highly suitable for the internet, web designing., 10It is distributed., JVM- Java Virtual Machine, It is a platform independent execution environment that converts, java byte code into object code and execute it.
Page 5 :
Most programming languages compile source code directly into, machine code that is designed to run on any specific os such as windows, or mac. This create platform dependency. But the developers of java, wanted it to be a platform independent language . So the concept of, JVM was included in java., Source, , Compiler, , Code, , JAVAC, , Byte, code, , Mac,, windows, , Object, code, , JVM, Source code- It is a collection of computer instructions written by using, any human readable computer language. The code / instruction provided, by programmer/ user is known as source code., Object code- The program in the form of machine instructions or binary, instructions is known as object code., Byte code- In java When a source code is compiled it doesn’t directly, convert into object code directly , rather it convert into a special code, known as byte code., RAD- Rapid Application Development, It is an object oriented approach for s/w development being, introduced by James Martin in the year 1980s. It includes a method of, development as well as s/w tools., Two most popular RAD systems are1- Net Beans IDE, 2- My Eclipse
Page 6 :
JDK- Java Development Kit, Java programs are mainly two types i.e applets and applications. Applets are java, programs executed by web browser while applications are the programs that executed directly on, your machine . JDK provides all the tools needed to write powerful Java applications or applets., , JDK includes:1- JRE(Java Runtime Environment) – It is the environment which is used to run the, predeveloped applets or applications in JDK., 2- JavaC- Java compiler is names as JavaC. It take input source code and coverts them into, compiled bytecode., 3- Java- The java interpreter /loader normally called as Java. It can be used to execute Java, applications. Interpreter translates bytecode directly into program action., 4- Java doc – It used to generate our source code into HTML file documentation., 5- Jar- It is an archiever to create jar file . This file contains the class, image and sound file, for java application or applet gathered into a single file possibly compressed., 6- Applet Viewer- This small program provides a real java environment for testing applets., , What is IDE?, •, •, •, •, •, , IDE stands for Integrated Development Environment., It is a software application that provides many useful facilities under one platform., An IDE normally consists of a source code editor, compiler or interpreter and a debugger, that developer can access through a single graphical user interface., A debugger helps to point out the exact spot where there is a problem in the source code., In other words IDE is a software program that is designed to help programmers and, developers to build software., There are so many types of IDE such as Android Studio , XCode , Eclipse , NetBeans, IDE, , NetBeans IDE, It is a free, open source, integrated development environment that enables you to develop, mobile , desktop and web applications. The IDE runs on windows, linux, Mac OS and other, operating system., Steps to Open NetBeans IDE, Steps1- Click on start button → All programs → NetBeans IDE 8.1, Or
Page 7 :
Double click on the shortcut icon of NetBeans IDE 8.1 On the Desktop., Step2- The loading screen of NetBeans IDE 8.1 will appear on your desktop., Step3- After loading the welcome screen of NetBeans IDE 8.1 will appear., , Different Part of IDE windows, 1- Title Bar- It display the name of the application or a program., 2- Menu Bar-It provides various commands used to work with NetBeans IDE such as file,, edit, view etc., 3- Tool Bar- It provide some important tools that help us to create applications quickly., 4- Palette Window- This window contain all the graphical components such as level, ,panels, text fields etc., 5- Project Window- It shows a logical structure of different project contents., 6- Design Area- It is the primary area used for creating and editing java forms., 7- Source editor- It is fully featured text editor program which includes a compiler ,, debugger and other components of IDE., 8- Output window- It automatically shows the output message after compilation of a, program., , GUI in JAVA, It stands for graphical user interface. A GUI is developed with the help of graphical elements, such as buttons, scroll bars , list and text fields. These elements are called components of GUI., It content 3basic elements,, 1. Graphical Component:, It is an object that defines screen element such as, Button , text field , Menus etc. Each, component has certain properties. They are the source of events ., 2. Event:, An event (occurrence of an activity) is generated when user do something like mouse, click, pressing key on the keyboard ,dragging etc., 3. Event Listener :, It contains method/functions which is attached to a component executed in response to an, event., Java GUI involves 2 packages the original Abstract Windows Tool Kit(AWT) and newer swing, toolkit. Component are same in both package. The main difference is that AWT is platform, dependent and Swing is platform Independent.
Page 8 :
Java Swing, It is a group of classes that provides more powerful and flexible GUI components than AWT., The two key features of swing are- Lightweight components and a pluggable look and feel, (means look and feel can be changed at runtime)., Some Basic Component of Swing, NetBeans IDE offers various Java Swing that can be used in Application Frame /, Windows /Form. Commonly used controls are-:, 1- Label : It is the display area for a short text string or an image . It is created through, Jlabel Component. A label displays a single line of read only text., 2- Text Field : Text field is the simplest text component which allows a user to feed input, text at the run time . It is derived from JTextfield component , which provides the basic, functionality common to swing components. JTextField allows you to edit one line of, text ., User Name, Password, , Text Field, , ********, Label, , 3- Text Area: Text area is a multi- line text component which enables a user to enter a large, amount of text . It is created through JTextArea component class ., Declaration, , 4- Button: A button is created through JButton class. JButton class provides the, functionality of a push button ( or simply say button) . It allows an icon, string or both to, be associated with the push button., login, , 5- Check Box: A check box is a graphical component that can be in one of the state as, ‘Selected’ or ‘Deselected’ . It is created through JCheckBox class. Each time when the, user clicks it, its state changes., Hobbies : Cricket, Football, Badminton, 6- Radio Button: Radio button is a group of mutually exclusive buttons, in which only one, button can be selected at a time. It is supported by the JRadio Button class, which extends, JToggleButton.
Page 9 :
Cast : GEN, OBC, SC, ST, 7- Frame: It is a top level container to which components are added. It provides a home for, the other components of the interface, and dictates the overall feel of the application. A, frame is created through JFrame component., 8- Panel: It is a lightweight container used for holding components which include JButton,, JLabel, JList , etc. A panel is created through JPanel component., 9- Password Field: The password field is used to accept the password for an application, during the execution of a program. It is created through JPasswordField component. The, password field is similar to text field but the text displayed in a password field is the form, of an echo character (echochar). *******, 10- List: A List displays a list of objects and allows the user to select one or more items. A, List is created through JList component . Lists can have many items , they are often put, in scroll panes., 11- ComboBox- It gives dropdown list of items or new items can be added. It is combination, of Jlist+Jtextfield. A combo box is created through JCombobox., , EVENT HANDLING IN JAVA GUI APPLICATION, EVENT, , EVENT, LISTENER, , SOURCE, , It receives and handles, events through listener, interface, , Event, object/messa, ge, , Event, occurrence, , It generate, event eg.button, , It created when event occurs. It, contain information about event, , Components, 1- Event- An event is a change of state of an object., 2- Event Source- It is an object that generates an event., 3- Listener- A listener is an object that listens to the event. A listener gets notified when an, event occurs., Handling of Events, A source generates an event and sends it to one more listeners registered with the source., Once event is received by the listener they process event and return.
Page 10 :
Basic Component Handling Methods, To handle different swing components there are several methods by which the various, properties of components can be handled and modified., 1- setText()- This method is used to set the text of a component(button, label, textfield,, textarea,checkbox etc)at run time., Syntax- component_name.setText(“Text”);, Example- jButton1.setText(“Enter”);, In the above example , jButton1 is component _name, “Enter” is the text displayed on the, button and setText is the method name., 2- getText()- This method is used to fetch out or retrieve the text contained by the specified, component (button, label, textfield, textarea,checkbox etc)at run time., Syntax- component_name.getText(“Text”);, Example- String str= jTextField1.getText();, In the above statement ‘str’ is a string type variable which holds the value of the text field, name as jTextField1 using getText() method. This method returns a string value., 3- isSelected()- This method is used to get the current state of the component.It returns the, value of the state in the form of true or false., Syntax- component_name.isselected();, Example – Boolean b=jcheckbox1.isselected();, In the above example b is a Boolean variable which hold current state of the component, named as jCheckBox1 using isselected()method., 4- setSelected- This method is used to set the current state of the component as selected or, unselected., Syntax – Component_name.setSelected();, Example – jCheckbox1.setSelected(true);, In the above example the checkbox name is jCheckBox1 is set to checked.