Learnitweb

Author: Editorial Team

  • Custom annotation in Java

    In the following example, we are creating an annotation TestAnnotationForClass. Now, we’ll use TestAnnotationForClass annotation for Test class. In this example, we have used RetentionPolicy.RUNTIME because we want to demonstrate and read annotation at runtime. RetentionPolicy.RUNTIME indicates that annotations are to be recorded in the class file by the compiler and retained by the virtual…

  • Annotations in Java – an introduction

    Annotations were introduced in Java 5. Annotation is also know as metadata. Metadata is a set of data that describes and gives information about other data. Annotations are only metadata and do not(and should not) contain any business logic. For example: In this code, @Override is the annotation. When this annotation is used with the…

  • Packages in Java

    There are millions (or more) Java classes containing code. Java library itself has thousands of classes. Consider a case when a programmer writes a class having class name HashMap. Java library itself has HashMap class. If programmer uses HashMap class in code, then the question is which HashMap class to use out of the two.…

  • Python program to find largest number in a list

    We’ll discuss 3 methods to find largest number in a list. Method 1 : Sort the list in ascending order and print the last element in the list. Output Method 2 : Using max() method Output Method 3: Without using built in functions Output

  • Python Program to find sum of numbers in an array

    Approach 1 In the first approach we’ll loop through the elements of the array and add every element to the sum which is initialized to 0. Output Approach 2 In the second approach, we’ll use the inbuilt method sum() to calculate the sum of elements of an array. Please note that you can pass any…

  • Strings in Python

    Textual data in Python in represented by string objects. Strings are immutable sequences of unicode code points. Strings in Python can be written in three ways: 1. Single quotes Single quoted strings allows embedded double quotes. Single quoted strings do not span multiple lines. 2. Double quotes Double quoted strings allow embedded single quotes. Double…

  • Boolean type in Python

    Boolean values in Python are represented as two constants True and False. True and False constants are simply set to integer values of 1 and 0, i.e True is represented as 1 and False is represented as 0. In simple way, True and False are alternative ways to spell integer values 1 and 0. Note:…

  • Complex number in Python

    Complex numbers are used in scientific calculations. Complex number in Python is represented in the form of a + bj. Here, a and b are real numbers and j represents the imaginary unit, satisfying the equation j2 = -1. Because no real number satisfies this equation, j is called an imaginary number. For the complex…

  • Python Program to check Armstrong Number

    A positive integer of n digits is an Armstrong number of order n (order is number of digits) if For example, 153 is an Armstrong number. 153 = 1^3 + 5^3 + 3^3 Output

  • Python program to calculate simple interest

    Simple interest formula is given by: Here, P stands for Principal, T stands for Time and R stands for Rate of Interest In the following example, we’ll use principal and rate of interest as float values and time as int value just for the sake of simplicity. Output