Main Method in Java: Why It Is Always Static

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

17K+ Views

Java main() method is always static, so that compiler can call it without the creation of an object or before the creation of an object of the class.In any Java program, the main() method is the starting point from where compiler starts program execution. So, the compiler needs to call the main() method.If the main() is allowed to be non-static, then while calling the main() method JVM has to instantiate its class.While instantiating it has to call the constructor of that class, There will be ambiguity if the constructor of that class takes an argument.Static method of a class can be ... Read More

Print Results of Script in MongoDB

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

1K+ Views

We will use printjson() for this. Let us first create a collection with documents −> dbprintResultScriptDemoinsertOne({"StudentName":"John", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cf22c02b64a577be5a2bc0b") } > dbprintResultScriptDemoinsertOne({"StudentName":"Carol", "StudentAge":20}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cf22c09b64a577be5a2bc0c") } > dbprintResultScriptDemoinsertOne({"StudentName":"David", "StudentAge":19}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cf22c11b64a577be5a2bc0d") }Following is the query to display all documents from a collection with the help of find() method −> dbprintResultScriptDemofind();This will produce the following document −{ "_id" : ObjectId("5cf22c02b64a577be5a2bc0b"), "StudentName" : "John", "StudentAge" : 21 } { "_id" : ObjectId("5cf22c09b64a577be5a2bc0c"), "StudentName" : "Carol", "StudentAge" : 20 } { "_id" ... Read More

HTML DOM Input Time Value Property

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

145 Views

The HTML DOM Input Time value property returns a string, which is the value of the value attribute of input Time. User can also set it to a new string.SyntaxFollowing is the syntax −Returning string valueinputTimeObject.valueSetting value attribute to a string valueinputTimeObject.value = ‘String’ExampleLet us see an example of Input Time value property − Live Demo Input Time value    form {       width:70%;       margin: 0 auto;       text-align: center;    }    * {       padding: 2px;       margin:5px;    }    input[type="button"] {       ... Read More

Create Directory Tree Using C++ in Linux

Samual Sam
Updated on 30-Jul-2019 22:30:26

1K+ Views

In this section we will see how to create a directory tree using C++ code in Linux. In Linux terminal we can put some command like “mkdir –p /dir/dir1/dir2” Here –p is used to mark as parent (recursively create inner directories).In C++ code we can use some libraries of Linux system. Then we can use Linux terminal commands as string argument of the system() function. We can create directory tree like this.Example#include #include #include #include using namespace std; int main() {    int status;    status = system("mkdir -p TP/My_Folder/test"); // Creating a directory    if ... Read More

Ping External Host from Swift in iOS

Smita Kapse
Updated on 30-Jul-2019 22:30:26

1K+ Views

Sometime you may require to ping an external website and check whether it’s up and running before you do any processing or fire request on the same.Here we will be seeing how to check whether the external website is up and running.Let’s being by Creating new projectStep 1 − Open Xcode → New Project → Single View Application → Let’s name it “PingMe”Step 2 − Open ViewController.swift and add the function checkIsConnectedToNetwork() and add the following code.func checkIsConnectedToNetwork() {    let hostUrl: String = "https://google.com"    if let url = URL(string: hostUrl) {       var request = URLRequest(url: ... Read More

Start a Service from Notification in Android

Smita Kapse
Updated on 30-Jul-2019 22:30:26

960 Views

This example demonstrate about How to start a service from notification in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.package app.tutorialspoint.com.notifyme ; import android.app.AlarmManager ; import android.app.PendingIntent ; import android.content.Intent ; import android.os.Bundle ; import android.support.v7.app.AppCompatActivity ; import android.view.View ; import java.util.Calendar ; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate (Bundle savedInstanceState) {       super ... Read More

Why __init__ is Always Called After New in Python

Ranjit Kumar
Updated on 30-Jul-2019 22:30:26

321 Views

Python is having special type of methods called magic methods named with preceded and double underscores.if we want to talk about magic method __new__ then obviously will also need to talk about __init__ method. The magic method __new__ will be called when instance is being created.where as __init__ method will be called to initialize instance when you are creating instance.Example Live Democlass X(): _dict = dict() def __new__(self): if 'data' in X._dict: print ("new instance Exists") return X._dict['data'] else: print ("magic method New") return super(X, self).__new__(self) def __init__(self): print ("instantiation") X._dict['data'] = self print ("") a1 = X() ... Read More

Specify Tab Location to Make it Visible at the Bottom in Java

Chandu yadav
Updated on 30-Jul-2019 22:30:26

173 Views

Use the setTabPlacement() method to set the tab location. To make it visible in the bottom, use the BOTTOM constant −JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);The following is an example to specify tab location to make it visible in the bottom −package my; import javax.swing.*; import java.awt.*; import java.awt.event.KeyEvent; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Technologies");       JTabbedPane tabbedPane = new JTabbedPane();       JPanel panel1, panel2, panel3, panel4, panel5;       panel1 = new JPanel();       panel2 = new JPanel();   ... Read More

Pop a Single Value in MongoDB

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

252 Views

You can use pop() for this. Let us first create a collection with documents −> db.persistChangeDemo.insertOne({"Name" : "Larry", "CreditScore": [500, 700, 760, 100]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cdfc52cbf3115999ed51203") }Following is the query to display all documents from a collection with the help of find() method −> db.persistChangeDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cdfc52cbf3115999ed51203"),    "Name" : "Larry",    "CreditScore" : [       500,       700,       760,       100    ] }Following is the query to pop a value −> myDocument.CreditScore.pop(); 100Let us save ... Read More

Ways to Print Escape Characters in Python

Hafeezul Kareem
Updated on 30-Jul-2019 22:30:26

4K+ Views

In this article, we are going to see how we can print the escape characters in Python. I think you know what escape characters are? Let's see what escape characters for those who don't know are?Escape characters are used for the individual meanings in strings. If we want to include a new line, tab space, etc., in strings, we can use these escape characters. Let's see some examples.Example Live Demo## new line new_line_string = "HiHow are you?" ## it will print 'Hi' in first line and 'How are you?' in next line print(new_line_string)OutputIf you run the above program, it will ... Read More

Advertisements