Skip to content

Instantly share code, notes, and snippets.

View Audhil's full-sized avatar
🎯
Focusing

Mohammed Audhil Audhil

🎯
Focusing
View GitHub Profile
@Audhil
Audhil / WaitNotifyDemo.java
Created August 1, 2020 19:56
wait() & notify() of Object class - for ref: https://www.youtube.com/watch?v=A1tnVMpWHh8
public class WaitNotifyDemo {
public static void main(String[] args) {
Q q = new Q();
new Producer(q);
new Consumer(q);
}
static class Q {
private int num;
@Audhil
Audhil / DeepCloneDemo.java
Created July 30, 2020 19:28
Deep Copy / clone in java - that supports changing member class data as well
public class DeepCloneDemo {
public static void main(String[] args) throws CloneNotSupportedException {
Employee employee = new Employee("audhil", 31, new Address(11, 782382));
System.out.println("employee:" + employee);
Employee employee2 = (Employee) employee.clone();
System.out.println("employee2:" + employee2);
employee2.setAddress(new Address(33, 4342));
System.out.println("employee:" + employee);
System.out.println("employee2:" + employee2);
@Audhil
Audhil / ShallowCloneDemo.java
Last active July 30, 2020 19:29
Shallow Copy in Java - it doesn't support member classes, suitable for classes with only primitive types
public class ShallowCloneDemo {
public static void main(String[] args) throws CloneNotSupportedException {
Employee employee = new Employee("audhil", 31);
System.out.println(employee);
Employee employee2 = (Employee) employee.clone();
System.out.println(employee2);
employee2.setAge(33);
employee2.setName("yup");
System.out.println(employee2);
}
@Audhil
Audhil / primitives.java
Created July 26, 2020 18:32
memory required for each data type in Java
// https://blog.udemy.com/java-data-types/?utm_source=adwords&utm_medium=udemyads&utm_campaign=DSA_Catchall_la.EN_cc.INDIA&utm_content=deal4584&utm_term=_._ag_82569850245_._ad_437477497173_._kw__._de_c_._dm__._pl__._ti_dsa-449490803887_._li_9061910_._pd__._&matchtype=b&gclid=CjwKCAjw0_T4BRBlEiwAwoEiAd5tg5iZ8c_k9pQxw5pX5HJoQKHjCc21ylREUKzHurajr3l7v2u5LhoCvKsQAvD_BwE
public static void main(String[] args) {
byte d = 127; // 2^7 = -128 -> 2^7-1 = 127 - 8 bits = 1 byte
short sh = 32767; // 16 bits = 2 bytes
int in = 2147483647; // 32 bits = 4 bytes
long lo = 9223372036854775807L; // 64 bits = 8 bytes
float fl = 23.44f; // 32 bits = 4 bytes
double db = 342.4; // 64 bits = 8 bytes
char ch = 'a'; // 16 bits - 2 byte
boolean bool = false; // 1 bit
@Audhil
Audhil / MainActivity.kt
Created July 7, 2020 08:22
viewmodel creation - gist 8
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
// extn func from activity-ktx lib
val viewModel: MainViewModel by viewModels()
}
@Audhil
Audhil / MainViewModel.kt
Created July 7, 2020 08:18
viewmodel injection - dagger-hilt - gist 8
class MainViewModel
@ViewModelInject
constructor() : ViewModel()
@Audhil
Audhil / build.gradle
Created July 7, 2020 08:13
hilt viewmodel dependencies - gist 7
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha01"
kapt "androidx.hilt:hilt-compiler:1.0.0-alpha01"
@Audhil
Audhil / MainActivity.kt
Last active July 6, 2020 19:21
mainActivity - gist 5
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
@Inject
lateinit var dummyClass: DummyClass
}
@Audhil
Audhil / APIModule.kt
Created July 6, 2020 18:57
module - gist 5
@Module
@InstallIn(ApplicationComponent::class)
class APIModule {
@Provides
fun giveAPIService(): API = Retrofit.Builder().build().create(API::class.java)
}
@Audhil
Audhil / DummyClass.kt
Created July 6, 2020 18:46
DummyClass - gist 4
class DummyClass
@Inject
constructor()