Filter
Exclude
Time range
-
Near
Java interview scenario based questions on Exceptions: Short Question 1: Can a static block throw an exception? Scenario based: You have a class that initializes a critical static resource in a static block. This initialization process might fail and throw an exception. What happens if an exception is thrown from a static initializer block? What error is ultimately thrown by the JVM, and what is the state of the class afterward? Hint -> If an exception is thrown from a static block, the class initialization fails Short Question 2: Does Java have a concept of throwing an exception by a constructor? Scenario based: You are creating a DatabaseConnection class. The constructor attempts to establish a connection to a database and throws a SQLException if it fails. What happens to the memory allocated for the DatabaseConnection object if the constructor throws this exception? Can the object be used after the exception is thrown? Hint-> Constructors can, and often should, throw exceptions to signal that an object cannot be created in a valid state
5
19
230
12,382
14 Oct 2025
New to databases in Xojo? Connect instantly with DatabaseConnection (no code) or use Database.Connect in code, and wrap changes in Transactions for safe commits or rollbacks. Explore SQLite, MySQL/MariaDB, PostgreSQL, and ODBC, plus the built-in example projects. #Xojo #Database
4
85
Citrix Virtual Apps and Desktops documentation script update 3.43.003. carlwebster.com/downloads/do… github.com/CarlWebster/Citri… carlwebster.sharefile.com/pu… dropbox.com/scl/fi/0rlrdwuxc… Read CVAD_V3_Script_ChangeLog.txt for the complete details. #Version 3.43.003 1-Aug-2025 #Added Broker Registry Keys (Thanks to CG at Citrix for providing this information): #HKLM:\Software\Policies\Citrix\DesktopServer\CheckExpiredEntitlementPeriodHours (2503) #HKLM:\Software\Policies\Citrix\DesktopServer\CheckExpiredLicensesPeriodHours (2411) #HKLM:\Software\Policies\Citrix\DesktopServer\CheckNFRLicensesPeriodHours (2411) #HKLM:\Software\Policies\Citrix\DesktopServer\IgnoreUnexpectedAgentShutdown (2503) #HKLM:\Software\Policies\Citrix\DesktopServer\MaxOpEventsToPurge (2411) #HKLM:\Software\Policies\Citrix\DesktopServer\VDASignedKeyCacheValidity (2503) #HKLM:\Software\Citrix\Broker\Service\State\DatabaseConnection\CancelAutoMaintenanceMode (2503) #HKLM:\Software\Citrix\DesktopServer\LHC\HigherRankedPeerElectedCheckIntervalMinutes (2411) #HKLM:\Software\Citrix\DesktopServer\LHC\TrustServiceKeySyncIntervalSecs (2503) #HKLM:\Software\Citrix\DesktopServer\LHC\WebSocketEnabledLhc (2503) #HKLM:\Software\Citrix\Broker\Service\State\LHC\HasHigherRankedPeerBeenElected (2411) #HKLM:\Software\Citrix\StaService\Service\State\STA\StandaloneStaEnabled (2503) #HKLM:\Software\Citrix\Broker\Service\State\XmlServiceKeyAuth\PowerStateCacheEntryExpiryTimeSecs (2503) #HKLM:\Software\Citrix\Broker\Service\State\XmlServiceKeyAuth\PowerStateCacheEnumerationLifetimeSecs (2503) #HKLM:\Software\Citrix\Broker\Service\State\XmlServiceKeyAuth\PowerStateCachePollingIntervalSecs (2411) #HKLM:\Software\Citrix\Broker\Service\State\XmlServiceKeyAuth\UniqueDeviceIdOptions (2411)

3
6
476
24 Apr 2025
Sure thing! Here’s a simple way to implement a database connection using the Singleton Design Pattern in Python: import psycopg2 class DatabaseConnection: _instance = None def new(cls, *args, kwargs): if cls._instance is None: cls._instance = super(DatabaseConnection, cls).new(cls) cls._instance._connection = None return cls._instance def connect(self, host, port, dbname, user, password): if self._connection is None: try: self._connection = psycopg2.connect( host=host, port=port, dbname=dbname, user=user, password=password ) except Exception as e: print(f"Failed to connect to database: {e}") def get_connection(self): return self._connection def disconnect(self): if self._connection is not None: self._connection.close() self._connection = None With this setup, every time you create a DatabaseConnection object, you’ll get the same instance and share a single DB connection across your app.
11
🧵 (3/3) Flow 📷 why are we using super() instead of calling the parent class DatabaseConnection directly? 📷 Full details in my Medium article: 🔄rahulnegi20.medium.com/learn… Guess the output? they are same or not🤔. (line: 51)
2
221
20 Jul 2024
That’s why for the DB I have a top level variable or inside a singleton that looks like this: late final Signal<DatabaseConnection> database; … void main() { database = signal(…); … }
3
104
🚀Day 11 (11/2) #100daysofcodechallenge : 1️⃣ Fixed Flutter update glitch in VS Code 2️⃣ Nailed down a solid database connection 3️⃣ Crushed two challenging DP questions. #Flutter #VSCode #DatabaseConnection #DP #CodingJourney #CodeNewbie
1
166
In this TypeScript example, the DatabaseConnection class utilizes the Singleton pattern with lazy initialization. The private constructor ensures that the database connection cannot be instantiated directly.
1
8
🚀 Day 6 of the #BackendChallenge: Successfully connected my backend to MongoDB today! Explored the intricacies of establishing that crucial link, understanding databases, and laying the groundwork for storing and retrieving data #MongoDB #DatabaseConnection #BackendDevelopment
2
84
Learn to connect PostgreSQL in Azure Cosmos DB effortlessly with this guide using pgAdmin and unleash the potential of your database workloads. #AzureCosmosDB #PostgreSQL #DatabaseConnection #pgAdmin 👉 learn.microsoft.com/azure/co…
4
12
999
Dependency Injection (DI): Dependency Injection is a design pattern that allows us to eliminate hard-coded dependencies and make our applications loosely coupled, extendable, and maintainable. We use a DI container to manage our classes and their dependencies. When a class needs another class to perform its duties, the DI container injects that dependency. This is the core idea behind Dependency Injection. Here’s a simple example: In this example, the User class depends on the DatabaseConnection class. Instead of creating a DatabaseConnection inside the User class, we’re injecting it through the constructor. This makes our code more flexible and testable. Remember, the key benefit of DI is the ability to swap dependencies without changing the class that uses them. It’s also worth noting that DI is not about how those dependencies are instantiated, but rather how they’re passed to the client class. 💻#CodingWithWilmer #PHP #YiiFramework #Yii2 #Yii3 #DepedencyInjection #DiContainer
2
5
189
28 Aug 2023
PHP MySQL Tutorial: Fetching Data from Database Step-by-Step | Geekboots YouTube: youtube.com/shorts/xdJYeLVL5… Source Code: geekboots.com/php/fetch-mysq… #coding #php #MySQL #webdesign #webdevelopment #databaseconnection #webdeveloper
2
3
52
🐍contextlib in Python - Let's consider a real-life example involving a database connection. 🐍 Database connections need to be managed properly to ensure they are established and terminated correctly. Many database libraries provide their context managers, but for the sake of this example, let's imagine we're using a hypothetical database library that does not natively support the `with` statement. Here's how we might use the `contextlib` module to create a context manager for such a database connection: In the example above: 👉 We have a `DatabaseConnection` class that simulates connecting to, querying, and disconnecting from a database. 👉 We then define a `database_manager` function decorated with `@contextlib.contextmanager`. This function: - Creates an instance of `DatabaseConnection`. - Connects to the database. - Yields the database connection (making it available within the `with` block). - Ensures that the connection is closed after the `with` block is exited, regardless of whether the block was exited normally or due to an exception. 👉 By using the `database_manager` in a `with` statement, we ensure that the database connection is properly established and closed without having to manually handle it every time. This greatly reduces the risk of leaving lingering connections and makes the code more readable and maintainable. ------------------ 👉 If you enjoyed this explanation: ✅1. Give me a follow @rohanpaul_ai Like & Retweet this tweet ✅2. Also checkout my recent Python book, covering over 100 Python Core concepts like this across 350 pages, with associated questions, most commonly asked in Interviews, 🐍 rohanpaul.gumroad.com/l/pyth… ------------ #python #100daysofcode #softwareengineer #programming #coding #programmer #developer #coder #code #computerscience #technology #pythonprogramming #software #webdevelopment #webdeveloper #tech #codinglife #algorithms #algorithm #datastructures #programmers #analytics #leetcode #MachineLearning #ArtificialIntelligence #datascience #nlp #100daysofmlcode #nlp #textprocessing #programminglife #hacking #learntocode #softwaredeveloper #interview
🐍In Python, why I should Consider contextlib and with Statements for Reusable try/finally Behavior🐍 👉 When developing in Python, we often encounter scenarios where we must set up resources before a block of code and ensure those resources are properly cleaned up afterward, regardless of whether the code block succeeded or failed. A classic example is file handling: opening a file, reading or writing to it, and ensuring it gets closed. 👉 Traditionally, one might use the `try/finally` pattern to ensure that resources are appropriately cleaned up. The `try` block contains our main operation, and the `finally` block ensures that cleanup operations are executed. ```python file = open("example.txt", "r") try: data = file.read() finally: file.close() ``` 👉 The limitation here is that it’s repetitive, especially if we're frequently performing similar operations. There's also the risk that we might forget to include the necessary cleanup operations in the `finally` block. 👉 Enter the `with` statement. The `with` statement creates a context in which resources can be managed. When we use an object within a `with` statement, Python ensures that the object’s setup and cleanup operations are automatically managed for us. ```python with open("example.txt", "r") as file: data = file.read() ``` In the above code, the file is automatically closed when the block inside `with` is exited, even if an exception is raised. 👉 So, how does this magic work? Objects used within a `with` statement must implement two methods: `__enter__()` and `__exit__()`. The `__enter__()` method is called when the block is entered, and `__exit__()` is called when the block is exited. 👉 But what if we have our custom resources that don't natively support the `with` statement? That's where the `contextlib` module comes in handy. Specifically, the `contextmanager` decorator in this module. 👉 By using the `contextmanager` decorator, we can quickly and easily create our context managers without explicitly defining a new class with `__enter__` and `__exit__` methods. Instead, we can define a generator function that yields exactly once. The pattern is quite intuitive: 1. Everything before the `yield` is equivalent to the `__enter__` method. 2. Everything after the `yield` is equivalent to the `__exit__` method. Here's an example: ```python from contextlib import contextmanager @contextmanager def managed_resource(*args, **kwds): # Code to acquire resource, e.g. resource = acquire_resource(*args, **kwds) try: yield resource finally: # Code to release resource, e.g. resource.release() ``` 👉 By defining our context manager using `contextmanager`, we can now use the `managed_resource` function within a `with` statement, making our code cleaner and more robust. 👉 In conclusion, the `with` statement and the `contextlib` module provide us with powerful tools to manage resources effectively and elegantly. It abstracts away the repetitive setup and cleanup operations, ensuring that our code remains DRY (Don't Repeat Yourself) and minimizing the chances of resource leaks or other related errors. By adopting this approach, we can write more reliable, readable, and Pythonic code. ------------------ 👉 If you enjoyed this explanation: ✅1. Give me a follow @rohanpaul_ai Like & Retweet this tweet ✅2. Also checkout my recent Python book, covering over 100 Python Core concepts like this across 350 pages, with associated questions, most commonly asked in Interviews, 🐍 rohanpaul.gumroad.com/l/pyth… ------------ #python #100daysofcode #softwareengineer #programming #coding #programmer #developer #coder #code #computerscience #technology #pythonprogramming #software #webdevelopment #webdeveloper #tech #codinglife #algorithms #algorithm #datastructures #programmers #analytics #leetcode #MachineLearning #ArtificialIntelligence #datascience #nlp #100daysofmlcode #nlp #textprocessing #programminglife #hacking #learntocode #softwaredeveloper #interview
2
7
995
DatabaseConnection.​java (Static fileds for success and shit)
4
2,273
Time for some recreational weekend hacking 💾 The objective for today: allow request handlers and type constructors in pavex to take references (e.g. &DatabaseConnection) as input arguments. Expect graph manipulations, code generation and a fair amount of rustdoc digging 🧐
1
1
22
Super fácil, un ejemplo para Oracle sería así: .dataBaseConnection { driver: hostName: port: sid: }
How To Fix The “Error Establishing a Database Connection” in WordPress? bit.ly/3o2tUW0 #WordPress #DatabaseConnection #Development #WPPlugins
1
1
Quizás eliminaría comentarios, buscaría mejor nombres de métodos y variables que fueran más descriptivos, por ejemplo: databaseConnection Normalmente los comentarios deberían explicar por qué el código es así, y no qué hace (eso lo debe explicar el propio código)
1
27 Aug 2021
RDSのDatabaseConnectionのアラートのしきい値ってどうやって決めるのかな? 接続上限とかCPU使用率くらいを参考にして決めるべきなのかな? モバイルエンジニアなのになんでこんな事やってるか知りたい。
1