0% found this document useful (0 votes)
17 views10 pages

Oops Key

Oops

Uploaded by

nikhilnikzz198
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

Oops Key

Oops

Uploaded by

nikhilnikzz198
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
Scoring Indicators COURSE NAME: Object Oriented Programming COURSECODE: 4131 QUD: 2103230063 a] Sabres Teal QNo Scoring Indicators pci arc oe PARTA 9 | 11 Encapsulation 1 1 12 true 1 1 13 bsxtends ila 14 ibstract. 1 I ts [avout Manegers control the position of components within | —, ; B ontainer. 9 |I. Top-level containers, : | 18) b tightweightéontsiner. ieee 17 _ primary key. 1 1 1s [ADBMS (Daabase Management System) isa software yatem |, ; hat is used to create, manage, and maintain databases, 19 _fpetConnectiong au aei PARTB Ey ava Virtual Machine(IVM) is a program which provides th intime environment to execute Java programs. JVM is virtua wachine that resides in the real machine and the machine TL fengusge for IVM is bytecode, The Java compiler generates byt 5 | 3 | 5 ‘ode for JVM rather than different machine code for each type o achine.JVM executes the byte code generated by compiler and roduce output VM is the one that makes java platform |___jindependent, [Constructor isa special method that gets invoked "automatically" M12 ithe time of objet creation, Constructor has the same name as | 5 | 3 | 5 he class name. Constructor is normally used for initializing bjects with default values unless different values are supplied, I. Using packagename.* 1.3 b.Using packagename.classname 3x1] 3 3 Using fully qualified name if we make any class as final, we cannot extend I. 11,4. Ee. final public class MyFinalClass { pie aye ia 1/ class implementation Page 1 of 10 | Split | Subtor | Total QNo Scoring Indicators seore | al | score |. Swing is a part of JFC (Java Foundation Classes) P- Swing is built on top of AWT (Abstract Window Toolkit) Swing components are lightweight | 4. Swing components have pluggable look and feel aug]. 3 3 (5. Swing components are platform independent Swing components are included in the package javax swing (Any 3) ILS /A listener is an object that is notified when an event occurs, For 11.6 fMevent listener to work it must have been registered with one or more sources to receive notification and an appropriate method thould have been implemented to process the event. 1. add(Component ¢) - inserts a component on a container. P. setSize(int width,int height) - sets the size (width and height) of the component. setLayout(LayoutManager m) - defines the layout manager ifor the component. 1+1+1] 3 3 i+ setVisible(boolean status) - changes the visibility of the -omponent, by default false. . setTitle(String text) -sets the title for a component(Any three), 17 11.8 |/-By creating the object of JFrame class B. By extending JFrame class toa 1. INTEGERINT TINYINT | SMALLINT DECIMAL beta Py) |g 3 VARCHAR 6x12 TEXT DATE: 9. TIME: 10. DATETIME 11. BOOLEAN Lo SI Awe wD in JDBC, a ResultSet is an interface that represents the result ofa latabase query. It provides methods to traverse and manipulate TL 10 the data returned by the query, The ResultSet object is created 3 3 3 hen the executeQuery() method of the Statement object is called ith an SQL query. ITPART C a2 Page 2 of 10 QNo Scoring Indicators Split ‘SubTot al Total m1 Ii. Object 2. Class . Encapsulation \4. Abstraction '5. Polymorphism Inheritance 77. Dynamic Binding 8. Message Passing ject Ibjects are real-world entities that have their own properties and yehavior. It has physical existence. Eg: person, banks, company, customers ete lass [A class is a blueprint or prototype from which objects are created, class is a generalized description of an object. Encapsulation The wrapping up of data( variables) and function (methods) into a ingle unit (called class) is known as encapsulation, \Abstraction bstraction means displaying only essential information and iding the details. Data abstraction refers to providing only sssential information about the data to the outside world, hiding the background details or implementation. [Polymorphism ;Polymorphism is the ability of a message to be displayed in more than one form. inheritance [The capability of a class to derive properties and characteristics from another class is called Inheritance. Dynamic Binding Dynamic binding means that the code associated with a gi [procedure call is not known until the time of the call at runtime jessage Passing | message for an object is a request for execution of a procedure. lessage passing involves specifying the name of the object, the name of the method(message), and the information to be sent Listin| gl Any 4) X15 146 Page 3 of 10 QNo Scoring Indicators Spit SubTot Total IV import java.util, Scanner, ass Person { String name; age; public Person(String name, int age) { this.name = name; this.age = age; } public void printDetails() { System.out.printin("Name: " + name); System.out.printin("Age: " + age); 3 B public class Main { public static void main(String{] args) { Scanner scanner = new Scanner(System.in); System.out print("Enter your name: "); String name = scanner.nextLine(); System.out.print("Enter your age: int age = scanner.nextint(); Person person = new Person(name, age); person. printDetails(): 3 }) class Declaration ~ 1, Input - 2 Logic -3 Output —1 the program. When the JVM encounters an error such as divide y zero, it creates an exception object and throws it —as a hotification that an error has oceurred.(2 marks) [Eg lass exceptionhandling It public static void main(String args[]) It int af J={5,10}5 int b=5; try te exception is a condition that is caused by a runtime error in. it lint x=af2]/b-a[1]; iH Page 4 of 10 QNo Scoring Indicators Split ‘SubTot al Total] atch ArithmeticException e){ System.out printIn(" Division by zero"); } ‘eateh(ArrayStoreException e){ | System.out printIn(” Wrong data type"); } int yal a0}; system.out.printin(" y=" +y); b }) (S marks) 245 VI java supports definition of global methods and variables that can e accessed without creating objects of a class. Such members are alled Static members [They are prefixed with the keyword statie Static variables: One copy per class — All objects share the same ariable . IE.g. static int count; (3 marks) \Static methods: A class can have methods that are defined as static (e.g., main method). Static methods can be accessed ithout using objects. Also, there is NO need to create objects. [They are prefixed with keyword “static”. (4 marks) 34 Vil inheritance in Java is a mechanism in which one object acquires Lal the properties and behaviors of a parent object.(2 marks) Different forms of inheritance: 1.Single inheritance (only one super class) 2.Multiple inheritance (several super classes) Hierarchical inheritance (one super class, many sub classes) 4. Multi-Level inheritance (derived from a derived class) S.Hybrid inheritance (more than two types) _(5 marks) 241 XS ‘vill [The super keyword in Java is a reference variable which is used (0 refer immediate parent class object. ‘sage of Java super Keyword 1. super can be used to refer immediate parent class instance ariable. 22. super can be used to invoke immediate parent class method. B. super() can be used to invoke immediate parent class onstructor. #4. We can use super keyword to access the data member of parent lass. It is used if parent class and child class have same ttribute.(4 marks) Page 5 of 10 Split QNo Scoring Indicators ee Total Eg | ‘lass Person { private String name; public Person(String name) { this.name = name; } public void introduce() { System.out-printin("Hi, my name is " + name); } iH | class Student extends Person { private int gradeLevel; public Student(String name, int gradeLevel) { super(name); this.gradeLevel = gradeLevel; 43 } public void study() { System.out.printin("I'm studying in grade " + gradeLevel); } 1 Jass Main { public static void main(Stringf] args) { Student student = new Student("John", 9); | student introduce(); student.study(Q); } } @ marks) jethod overloading and method overriding are two important concepts in Java's object-oriented programming paradigm. The; hare used to achieve polymorphism, which means the ability of an jethod Overloading: Method overloading allows multiple 2 methods in a class to have the same name but with different jparameters. It is achieved by changing the number of parameter r the data types of the parameters in the method signature. IX _ [object to take many forms. 3.5X |When a method is called, the compiler determines which method (0 execute based on the number of arguments and their data types, fethod overloading is also known as compile-time polymorphism or static polymorphism. jethod Overriding: Method overriding is a technique tha lows a subclass to provide a specific implementation of 4 PA method that is already provided by its super class. It is achiev yy creating a method in the subclass with the same name, ret type, and parameters as the method in the super class. The ethod in the subclass must also have the same or a mote| essible access level than the method in the super class fethod overriding is also known as runtime polymorphism o namic polymorphism. Page 6 of 10 QNo Scoring Indicators ‘SubTot al Total import java.util Scanner, interface Shape { void draw); 3 ass Rectangle implements Shape { private String name; public Rectangle(String name) { this.name = name; 3 public void draw() { System.out.printin("Drawing rectangle"); } public class Example { public static void main(String] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the name of the rectangle: "); | String name = scanner.nextLine(); Rectangle rectangle = new Rectangle(name); rectangle.draw(); System.out printIn("Name of the rectangle is: " + name); } class Declaration - 2, interface - 2 implementation ~3 Il +343) XI Il. Import the necessary Swing packages: To use Swing in a Java program, you need to import the necessary packages, such a jiavax.swing and java.awt. 2. Create a JFrame object: The [Frame class represents the Inain window of a Swing application. You can create a JFrame ‘object using the constructor or by extending the JFrame class. 8. Add components to the JFrame: Once you have a JFrame Ypject, you can add components to it, such as buttons, labels, text fields, and other controls. 4, Set layout manager: Choose a layout manager that best suits e design of the interface. '5. Set the properties of the JFrame: You can set various [properties of the JFrame, such as its size, title, and visibility. . Write event handlers: You can write event handlers to handle \ser input, such as button clicks or menu selections. 14241 +1+1+) 1 Page 7 of 10 abot | To QNo Scoring Indicators ela ce import javax.swing,*; import javaawt.*; import java.awt.event.*; public class ButtonExample extends JFrame implements ctionListener { rivate JButton button; yublic ButtonExample(){ betSize(200,200); setTitle("Button Example"): uutton = new JButton("Click M \dd(button); jputton.addActionListener(this); XII fetVisibletrue); TALE 7 G public void actionPerformed(ActionEvent e) { if (e.getSource() == button) { |OptionPane.showMessageDialog(this, "Button clicked!"); I} public static void main(String[] args) It jButtonEXample aob=new ButtonExample(); I} } class Declaration — 1, creation of swing components - 3 Methods implementation ~ 3 {1.CREATE - This command is used to create a table. | {Syntax: CREATE TABLE table_name ( column] datatype, | ‘olurn2 datatype, column3 datatype, ...); Example: CREATE TABLE EMPLOYEE (Name ARCHAR2(20), Email VARCHAR2(100), DOB DATE) \marks) 2. ALTER - This command is used to modify the structure of an xan existing table, can a) Add a new column to the table Syntax: ALTER TABLE table_name ADD column_name datatype; Example: ALTER TABLE Customers ADD Email varchar(255); ) Delete a column Syntax: ALTER TABLE table_name DROP |COLUMN column_name; Example: ALTER TABLE Customers DROP COLUMN Email; Page 8 of 10 Split | Subtor | Total QNo Scoring Indicators scm || Eni || were ) Rename a columa Syntax: ALTER TABLE table_name RENAME COLUMN Id_name to new_name: Example: ALTER TABLE Customers RENAME COLUMN [Email to Mail 1) Modify datatype of an attribute | XII |Syntax: ALTER TABLE table_name MODIFY COLUMN [3341] 7 «| 7 jlumn_name datatype; ‘xample: ALTER TABLE Customers MODIFY COLUMN :mail varchar (50); (3 marks) . DROP - It is used to delete both the structure and record stored in the table. Syntax: DROP TABLE table_name; Example: ROP TABLE Employee;(1 mark) il. Load the JDBC driver: Before connecting to a database we eed to load the appropriate JDBC driver for the database. We load the driver class by calling Class.forName() with the driver class name as an argument. ‘or connecting to MySQL database, we write | \Class.forName("“com.mysql.jdbe.Driver”); . Establish a connection: The JDBC DriverManager class lefines objects which can connect Java applications to a JDBC | iriver. Its getConnection() method is used to establish a mnnection to a database. It uses a username, password, and a DBC URL to establish a connection to the database and returns a -onnection object. Connection conn = riverManager. getConnection("jdbc:mysql://localhost/mydatabas, ', "username", "password"; . Create a statement: After establishing a connection, you can reate a Statement object using the Connection.createStatement() | \ethod. The Statement object is used to execute SQL statements. \statement stmt = conn.createStatement(); |. Execute SQL statements: You can execute SQL statements sing the Statement executeQuery() method. The executeQuery() jethod takes a sql query string as an argument and returns the esult as a ResultSet object. ResultSet rs = Stmt.executeQuery("SELECT * FROM mytable"); The -xecuteUpdate() method executes the SQL INSERT,DELETE,UPDATE statements Page 9 of 10 | No Scoring Indicators eel el tae ‘5. Process the results: We can retrieve the data from the ResultSet using the getXXX() methods, where XXX is the data ype of the column, while (rs.next()) { int id = rs.getint("id"); tring name = rs.getString("name"); System.out.printin("ID:" + |1+2+1 id +", Name: " + name); } lise] 7 | 7 1 5. Close the connection: After all database operations are finished, the connection can be closed using the ‘Connection.close() method. conn.close(); Page 10 of 10

You might also like