Posts
#java #class #immutable How to create an Immutable class ?
- Get link
- X
- Other Apps
How to create an Immutable class ?
- Get link
- X
- Other Apps
What is an immutable class in Java? Immutable objects are instances whose state doesn’t change after it has been initialized. There are many immutable classes like String, Boolean, Byte, Short, Integer, Long, Float, Double etc. In short, all the wrapper classes and String classes are immutable. We can also create our own immutable class by creating a final class that has final data members. How to create an Immutable class ? Rules for creating Immutable class in Java− Make class final − class should be final so that it cannot be extended. Make each field final & private − Each field should be final so that they cannot be modified after initialization. Create a getter method for each field. − Create a public getter method for each field. fields should be private. No setter method for each field. − Do not create a public setter method for any of the fields. Create a constructor − Such a constructor will be used to initialize properties once. Please refer video: How to create an Immu...
#string #java #stringbuffer #immutable #mutable How to Reverse a String ...
- Get link
- X
- Other Apps
#java #faq #jarray #multidimensionalarray Jagged Array in Java
- Get link
- X
- Other Apps
#parameter #pathparameter #queryparameter API TERMINOLOGY : Part-2
- Get link
- X
- Other Apps
Why java is Platform Independent?
- Get link
- X
- Other Apps
How is Java platform independent? Platform means → H/W+S/W+OS(Windows, Mac, Linux etc.) Java is a platform-independent language. In other words, once you write your code then run it anywhere, on any platform that provides the environment to run it. This environment is the Java Virtual Machine (JVM). The JVM should be present to execute the code. The JVM is different for each platform. In the case of Java, platform independence does not mean that you can run the code anywhere, you can run it wherever the environment is provided. To run a program on any machine you need to convert it to the machine language so that the specific machine can understand it. In Java the source code is not directly converted into the machine code. It is first converted into the byte code by the compiler. In Java, the byte code is interpreted by the JVM and converts it into the machine specific code. So the Java Vir...
API TERMINOLOGY : Part-1
- Get link
- X
- Other Apps
API TERMINOLOGY Q1: What is a Resource? Resource is a physical or virtual component, which supports/extends/represents/constructs a system. Consider a real time example of a Vehicle . Wheels, brakes, headlight, fuel tank etc all are resources of a Vehicle . All resources have names, location and identifiers. Take another example of Google. Now append “/gmail” in the last of the base url “https://www.google.com/” as "https://www.google.com/gmail". Google will launch Gmail Page: https://www.google.com Base URL: https://www.google.com Resource: /gmail/about/# Q2: What are Collections? Collections are simply groups of resources. You’ll find that we don’t mention any collections in the API documentation. That is because we offer singleton resources, which are independent and exist outside of any collections Q3: What is Endpoints/BaseUrl? API endpoint is the point of entry in a communication channel when two systems are interacting....
Converting Pdf Text in to Audio Files
- Get link
- X
- Other Apps
Converting Pdf Text in to Audio Files: Libraries:- PyPDF , is a library in python that is used to read text from a pdf file. PyPDF2 · PyPI Pyttsx3 , is a text-to-speech convert library. pyttsx3 · PyPI Here we are using PyPDF library to read text from the pdf file and then we are converting the text into speech and save it as an audio file. Program: import pyttsx3 , PyPDF2 pdfrReader=PyPDF2.PdfFileReader( open ( 'File_1.pdf' , 'rb' )) audio=pyttsx3.init() for page_num in range (pdfrReader.numPages): text=pdfrReader.getPage(page_num).extractText() cleanText=text.strip().replace( ' \n ' , ' ' ) print (cleanText) audio.say(cleanText) audio.save_to_file(cleanText , 'File_1.mp3' ) audio.runAndWait() audio.stop() THANKS!!
How will you check if a class is a child of another class?
- Get link
- X
- Other Apps
- This is done by using a method called issubclass() provided by python. The method tells us if any class is a child of another class by returning true or false accordingly. - We can check if an object is an instance of a class by making use of isinstance() method: Example: class Parent (): pass class b (Parent): pass print ( issubclass (b , Parent)) #true print ( issubclass (Parent , b)) #False obj1=b() obj2=Parent() print ( "=======" ) print ( isinstance (obj2 , b)) #False print ( isinstance (obj2 , Parent)) #True THANKS!!
Introduction of Python
- Get link
- X
- Other Apps
Introduction of Python What is Python? Python is a popular programming language. It was created by Guido van Rossum, and released in 1991. It is used for: web development (server-side),software development, mathematics, system scripting. What can Python do? Python can be used on a server to create web applications. Python can connect to database systems. It can also read and modify files. Python can be used to handle big data and perform complex mathematics. Python can be used for rapid prototyping, or for production-ready software development. Why Python? Python is a high-level, interpreted, interactive and object-oriented scripting language. Python is designed to be highly readable. It uses English keywords frequently where as ...
GIT BRANCH DETAILS
- Get link
- X
- Other Apps
GIT BRANCH COMMANDS: ======================= git checkout branch_name git branch branch_name git checkout branch_name git checkout -b branch_name git branch --list git branch git branch -r git push origin -delete branch_name git checkout - git branch -m B1 TestB1 git branch -d branch_name OR git branch -D branch_name git push origin --delete branch_name
Python self Variable
- Get link
- X
- Other Apps
Python self Variable Python self variable is used to bind the instance of the class to the instance method. We have to explicitly declare it as the first method argument to access the instance variables and methods. This variable is used only with the instance methods. In most of the Object-Oriented programming languages, you can access the current object in a method without the need for explicitly having it as a method parameter. For example, we can use “this” keyword to access the current object in Java program. But, in Python we have to explicitly declare the object instance as “self” variable Example1: class Emp : def __init__ ( self , name , empid ): self .name = name self .empid = empid print ( id ( self )) def e1 ( self ): print ( "Name of Emp: " , self .name) print ( "Emp id is : " , self .empid) e = Emp( 'VDS' , 100 ) print ( id (e)) e.e1() POINTS TO REMEMBER: Python self variable is not a reserved key...
JavaScriptExecutor : Part-1
- Get link
- X
- Other Apps
JavaScriptExecutor Before we discuss on JavaScriptExecutor, We will discuss what is JavaScript actually? So, What is JavaScript ? Java Script is an object-oriented programming language commonly used to create interactive effects within the web browser to Handle WebElements within Web Page. It is used by Selenium WebDriver to do handle WebElements. Now lets us discuss, What is JavaScriptExecutor? The JavaScriptExecutor is an interface that provides mechanisms to execute javascript through the Selenium Driver. To run JavaScript in the context of the currently selected frame or window, it provides two methods i.e. "executescript" and "executeAsyncScript" The basic advantage of JavaScriptExecutor is that Selenium provides a way to run Java Script in webdriver. Sometimes the locator can not work, in that case the JavaScriptExecutor will help interact with web elements on a particular webpage. The reason behind this is, even Selenium webdriver convert the bindings ...
Python Docstrings
- Get link
- X
- Other Apps
Python Docstrings Python documentation strings (or docstrings) provide a convenient way of associating documentation with Python modules, functions, classes, and methods. It’s specified in source code that is used, like a comment, to document a specific segment of code. Unlike conventional source code comments, the docstring should describe what the function does, not how. How docstring look like? The doc string line should begin with a capital letter and end with a period. The first line should be a short description. If there are more lines in the documentation string, the second line should be blank, visually separating the summary from the rest of the description. The following lines should be one or more paragraphs describing the object’s calling conventions, its side effects, etc. Doc String can be one liner or multiliner based on requirements with proper indentation . Declaring Docstrings: The docstrings are declared using ”’triple single quotes”’ or “””triple double quotes””” j...
range() vs xrange() in Python:
- Get link
- X
- Other Apps
range() vs xrange() in Python: The range() and xrange() are two functions that could be used to iterate a certain number of times in for loops in Python. In Python 3, there is no xrange , but the range function behaves like xrange in Python 2. If you want to write code that will run on both Python 2 and Python 3, you should use range(). range() – This returns a range object (a type of iterable). xrange() – This function returns the generator object that can be used to display numbers only by looping. The only particular range is displayed on demand and hence called "lazy evaluation". The points of comparison are: Return Type: range() returns – range object. xrange() returns – xrange() object. Example: a=range(5) print(type(a)) # O/P: <type 'list'> x=xrange(6) print(type(x)) #O/P: <type 'xrange'> Operation Usage: range() returns the list, all the operations that can be applied on the list can be used on i...
*args and **kwargs in Python
- Get link
- X
- Other Apps
What do you mean by *args and **kwargs in Python function? *args: *args is a special syntax used in the function definition to pass variable-length arguments. “*” means variable length and “args” is the name used by convention. You can use any other. **kwargs: **kwargs is a special syntax used in the function definition to pass variable-length keyworded arguments. Here, also, “kwargs” is used just by convention. You can use any other name. Keyworded argument means a variable that has a name when passed to a function. It is actually a dictionary of the variable names and its value. ========================================================================= Important Points related to *args & **kwargs: *args and **kwargs are special keyword which allows function to take variable length argument. *args passes variable number of non-keyworded arguments list and on which operation of the list can be performed. **kwargs passes variable number of keyword arguments dictionary to functi...
Python namespaces & LEGB rule in Python
- Get link
- X
- Other Apps
What are Python namespaces? What is the LEGB rule in Python? A namespace in Python ensures that object names in a program are unique and can be used without any conflict. Python implements these namespaces as dictionaries with 'name as key' mapped to a corresponding 'object as value'. This allows for multiple namespaces to use the same name and map it to a separate object. A few examples of namespaces are as follows: Local Namespace includes local names inside a function. the namespace is temporarily created for a function call and gets cleared when the function returns. Global Namespace includes names from various imported packages/ modules that are being used in the current project. This namespace is created when the package is imported in the script and lasts until the execution of the script. Built-in Namespace includes built-in functions of core Python and built-in names for various types of exceptions. The lifecycle of a namespace depends upon the sco...
Dynamically typed language
- Get link
- X
- Other Apps
What is a dynamically typed language? Before we understand a dynamically typed language, we should learn about what typing is. Typing refers to type-checking in programming languages. In a strongly-typed language, such as Python, "3" + 2 will result in a type error since these languages don't allow for implicit conversion of data types. On the other hand, a weakly-typed language like Java, C++, will simply output "32" as result. Type-checking can be done at two stages Static - Data Types are checked before execution. Dynamic - Data Types are checked during execution. Python is an interpreted language, executes each statement line by line and thus type-checking is done on the fly, during execution. Hence, Python is a Dynamically Typed Language. Thanks for reading!!