Posts

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 (...

Assignment 11-03

  Assignment 1.Write the definition of a Point class. Objects from this class should have a ·   a method show to display the coordinates of the point ·   a method move to change these coordinates. Solution :   '''the following code p class takes 2 arguments the SHOW function returns the co-ordinates or point suppose (x,y) the MOVE function takes 2 arguments (x1,y1) and moves the (x,y) point by (x1,y1) the SHOW function displays the new co-ordinates ''' class p( object ): def __init__ ( self , x , y): self .x = x self .y = y def show ( self ): return self .x , self .y def move ( self , x , y): self .x += x self .y += y p1 = p( 1 , 4 ) p2 = p( 2 , 5 ) print (p1.show()) print (p2.show()) p1.move( 5 , 6 ) p2.move( 7 , 8 ) print (p1.show()) print (p2.show()) 2.Write a Python class to implement pow(x, n)       Solution : class p: def pow ( self , x , n): if x == 0 or...