Programming Articles - Page 2563 of 3366

Can we change the order of public static void main() to static public void main() in Java?

Alshifa Hasnain
Updated on 16-Apr-2025 18:53:41

4K+ Views

Yes, we can change the order of public static void main() to static public void main() in Java, the compiler doesn't throw any compile-time error or runtime error. In Java, we can declare access modifiers in any order, the method name comes last, the return type comes second to last and then after it's our choice. But it's recommended to put access modifier (public, private and protected) at the forefront as per Java coding standards. Java Method Modifiers and Their Order Java allows you to place method modifiers (the keyword "public, " "static, " "final, " etc.) in various orders. The Java ... Read More

Can we extend an enum in Java?

raja
Updated on 07-Feb-2020 05:58:29

4K+ Views

No, we cannot extend an enum in Java. Java enums can extend java.lang.Enum class implicitly, so enum types cannot extend another class.Syntaxpublic abstract class Enum> implements Comparable, Serializable {    // some statements }EnumAn Enum type is a special data type which is added in Java 1.5 version.An Enum is used to define a collection of constants, when we need a predefined list of values which do not represent some kind of numeric or textual data, we can use an enum.Enums are constants and by default, they are static and final. so the names of an enum type fields are in uppercase letters.Public or protected modifiers can only ... Read More

What are the differences between a static block and a constructor in Java?

raja
Updated on 11-Feb-2020 10:10:35

2K+ Views

Static blockThe static blocks are executed at the time of class loading.The static blocks are executed before running the main () method.The static blocks don't have any name in its prototype.If we want any logic that needs to be executed at the time of class loading that logic needs to placed inside the static block so that it will be executed at the time of class loading.Syntaxstatic {    //some statements }ExampleLive Demopublic class StaticBlockTest {    static {       System.out.println("Static Block!");    }    public static void main(String args[]) {       System.out.println("Welcome to Tutorials Point!");    } }OutputStatic Block! ... Read More

What is lambda binding in Python?

Sri
Sri
Updated on 30-Jul-2019 22:30:26

745 Views

When a program or function statement is executed, the current values of formal parameters are saved (on the stack) and within the scope of the statement, they are bound to the values of the actual arguments made in the call. When the statement is exited, the original values of those formal arguments are restored. This protocol is fully recursive. If within the body of a statement, something is done that causes the formal parameters to be bound again, to new values, the lambda-binding scheme guarantees that this will all happen in an orderly manner.there is only one binding for x: ... Read More

How to Zip a directory in PHP?

Alok Prasad
Updated on 29-Jun-2020 11:47:35

2K+ Views

We can use PHP ZipArchive class in order to zipping and unzipping the folder in PHP. As of PHP 5.3, this class is inbuilt. For using in windows users need to enable php_zip.dll inside of php.ini.Example

Is Python Object Oriented or Procedural?

Sri
Sri
Updated on 30-Jul-2019 22:30:26

5K+ Views

Yes, Python support both Object  Oriented and Procedural  Programming language as it is a high level programming language designed for general purpose programming. Python are multi-paradigm, you can write programs or libraries that are largely procedural, object-oriented, or functional in all of these languages. It depends on what you mean by functional. Python does have some features of a functional language. OOP's concepts like, Classes, Encapsulation, Polymorphism, Inheritance etc.. in Python makes it as a object oriented programming language. In Similar way we can created procedural program through python using loops ,for ,while etc ..and control structure.Exampleclass Rectangle:    def __init__(self, length, breadth, ... Read More

How To Do Math With Lists in python ?

Sri
Sri
Updated on 30-Jul-2019 22:30:26

10K+ Views

We  not only use lists to store a collection of values, but we also use it to perform some mathematical calculations or operations to do.Example 1import math data = 21.6 print('The floor of 21.6 is:', math.floor(data))OutputThe floor of 21.6 is: 21How To Calculate the Weighted Average of a ListExample 2cost = [0.424, 0.4221, 0.4185, 0.4132, 0.413] cases = [10, 20, 30, 40, 50] cost = [23, 10, 5, 32, 41] weight= [10, 20, 30, 40, 50] for i in range(len(cost)): cost[c] = (cost[i] * weight[i] / sum(weight)) cost = sum(cost) print(cost)Output72.84444444444445Example 3import math degree = 180 radian = math.radians(degree) ... Read More

Can we define a method name same as class name in Java?

Alshifa Hasnain
Updated on 05-Jun-2025 12:35:08

5K+ Views

A method is a collection of statements that are grouped together to perform an operation. In Java, you can define a method having the same name as the class but it is not recommended as per the coding standard. Can We define a Method Having Same as Class? Yes, It is allowed to define a method with the same name as that of a class. There is no compile-time or runtime error will occur. But this is not recommended as per coding standards in Java. Normally the constructor name and class name always the same in Java. Example of a ... Read More

What is singleton design concept in PHP?

Alok Prasad
Updated on 29-Jun-2020 11:38:58

4K+ Views

Singleton Pattern ensures that a class has only one instance and provides a global point to access it. It ensures that only one object is available all across the application in a controlled state. Singleton pattern provides a way to access its only object which can be accessed directly without the need to instantiate the object of the class.ExampleOutputconnection createdExplanationIn the above example as we are following a singleton pattern so the object $db2 can't be created. Only a single object will be created and i.e available all across the application.

How To enable GZIP Compression in PHP?

Alok Prasad
Updated on 29-Jun-2020 11:41:43

5K+ Views

GZIP Compression is a simple, effective way to save bandwidth and speed up PHP application. The mechanism runs behind the GZIP compression is described below −Step1The browser/client request for a file to the server.Step2The server sends a .zip file to the browser (index.html.zip) rather than plain old index.html in response, due to which the download time and bandwidth decreases.Step3After the execution of the above step, the browser downloads the zipped file, extracts it, and then shows it to the user. This loads the webpage very quickly.In the Apache server, we have to Add the following to .htaccess file to enable ... Read More

Advertisements