Posts

Showing posts from March, 2022

Unittest

Unit Testing in Python  Unit Testing is the first level of software testing where the smallest testable parts of a software are tested.  This is used to validate that each unit of the software performs as designed. import unittest     class SimpleTest(unittest.TestCase):        def test( self ):                  self .assertTrue( True )     if __name__ = = '__main__' :      unittest.main()  This is the basic test code using unittest framework, which is having a single test. This test() method will fail if TRUE is ever FALSE.   There are three types of possible test outcomes : OK – This means that all the tests are passed. FAIL – This means that the test did not pass and an AssertionError exception is raised. ERROR – This means that the test raises an exception other than AssertionError.    EXAMPLE : import...

Assert in testcases

  Unit Testing in Python – Unittest What is Unit Testing? Unit Testing is the first level of software testing where the smallest testable parts of a software are tested. This is used to validate that each unit of the software performs as designed.   import unittest     class SimpleTest(unittest.TestCase):          # Returns True or False.       def test( self ):                  self .assertTrue( True )     if __name__ = = '__main__' :      unittest.main()   assertEqual() function  assertEqual() in Python is a unittest library function that is used in unit testing to check the equality of two values. This function will take three parameters as input and return a boolean value depending upon the assert condition. If both input values are equal assertEqual() will return true else retur...

Annotations in Java

Image
  Annotations in Java :             Annotations are used to provide additional information about a program.  Annotations start with @ Annotations do not change the action of a compiled program. Annotations help to associate metadata (information) to the program elements i.e. instance variables, constructors, methods, classes, etc. Annotations are not pure comments as they can change the way a program is treated by the compiler. Annotations basically are used to provide additional information, so could be an alternative to XML and Java marker interfaces.   Example 1 :   package java ; public class ann { public void display (){ System. out .println( "hell0 children" ) ; } } class ch1 extends ann{ @Override public void display () { super .display() ; // System.out.println("hello"); } public static void main (String[] args) { ch1 c1 = new ch1() ; c1.display() ; @SuppressWar...

Queue in Java

Image
  Queue Interface In Java :   The Queue interface present in the java.util package and extends the Collection interface is used to hold the elements about to be processed in FIFO(First In First Out) order.  It is an ordered list of objects with its use limited to insert elements at the end of the list and deleting elements from the start of the list, (i.e.), it follows the FIFO or the First-In-First-Out principle.       queue needs a concrete class for the declaration and the most common classes are the PriorityQueue and LinkedList in Java.   Queue is an interface, objects cannot be created of the type queue. We always need a class which extends this list in order to create an object   Example : import java.util.LinkedList ; import java.util.Queue ; public class q { public static void main (String[] args) { Queue<Integer> qu = new LinkedList<>() ; for ( int i = 0 ; i < 5 ; i++) ...

Method Over riding in Java

Method Overriding in Java : If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java . In other words, If a subclass provides the specific implementation of the method that has been declared by one of its parent class, it is known as method overriding.   Usage of Java Method Overriding Method overriding is used to provide the specific implementation of a method which is already provided by its superclass. Method overriding is used for runtime polymorphism   Rules for Java Method Overriding The method must have the same name as in the parent class The method must have the same parameter as in the parent class. There must be an IS-A relationship (inheritance).   // normal parent and child class usage class  Vehicle{      void  run(){System.out.println( "Vehicle is running" );}   }     //child class    class  Bike  exte...

Method Over loading in Java

 Method Overloading in Java :    If a class has multiple methods having same name but different in parameters, it is known as Method Overloading   If we have to perform only one operation, having same name of the methods increases the readability of the  program . If we have to perform addition of the given numbers but there can be any number of arguments, if you write the method such as a(int,int) for two parameters, and b(int,int,int) for three parameters then it may be difficult for you as well as other programmers to understand the behavior of the method because its name differs.    Method overloading increases the readability of the program.     two ways to overload the method in java By changing number of arguments By changing the data type   1) Method Overloading: changing no. of arguments In this example, we have created two methods, first add() method performs addition of two numbers and second add method performs additio...

OOPS in Java

Object Oriented Programming Object-oriented programming has several advantages over procedural programming: OOP is faster and easier to execute OOP provides a clear structure for the programs OOP makes it possible to create full reusable applications with less code and shorter development time     What are Classes and Objects? Classes and objects are the two main aspects of object-oriented programming.   class is a template for objects, and an object is an instance of a class. When the individual objects are created, they inherit all the variables and methods from the class.     Create an Object In Java, an object is created from a class. We have already created the class named Main , so now we can use this to create objects. To create an object of Main , specify the class name, followed by the object name, and use the keyword new : Example public class Main { int x = 5 ; public static void main ( String [ ] args ) { Main ...

Basics of JAVA

JAVA PROGRAMMING What is Java? Java is a popular programming language, created in 1995. It is owned by Oracle, and more than 3 billion devices run Java. It is used for: Mobile applications (specially Android apps) Desktop applications Web applications Web servers and application servers Games Database connection And much, much more! Why Use Java? Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.) It is one of the most popular programming language in the world It is easy to learn and simple to use It is open-source and free It is secure, fast and powerful It has a huge community support (tens of millions of developers) Java is an object oriented language which gives a clear structure to programs and allows code to be reused, lowering development costs As Java is close to C++ and C# , it makes it easy for programmers to switch to Java or v ice versa Java Syntax   Program to Print Hello World : public class Main { public static void main ( S...

Assignment 12-03

    1.viewing the customer based on customer id : ''' Write a Program for Customer Management: Create a Customerdetails ⇒ id,name,city,tickets Options : 1.viewing the customer based on customer id 2. Total count of tickets sold 3. City wise ticket sold 4. Information ⇒ based on descending order 5. Update ⇒ customer id ⇒ which detail 6. Delete ⇒ customer id ⇒ delete the record ''' import sqlite3 con = sqlite3.connect( 'cus.db' ) cursor = con.cursor() sq = '''CREATE TABLE customer_details( id INTEGER PRIMARY KEY, name TEXT , city TEXT, tickets INTEGER)''' cursor.execute(sq) print ( 'table is created successfully' ) con.commit() con.close()       import sqlite3 def data (dl2): con = sqlite3.connect( 'cus.db' ) cursor = con.cursor() ins = '''INSERT INTO customer_details VALUES (...