Skip to content

Instantly share code, notes, and snippets.

View ShmuelMofrad's full-sized avatar
💭
I may be slow to respond.

Samuel Mofrad ShmuelMofrad

💭
I may be slow to respond.
View GitHub Profile
@ShmuelMofrad
ShmuelMofrad / LogicAndOr.java
Created November 29, 2017 17:36
Truth table - AND & OR in Java
public class LogicAndOr {
public static void main(String[] args) {
boolean result;
result = isAndTrueOrFalse(true, true, true);
System.out.println("And 1: " + result);
result = isAndTrueOrFalse(false, true, true);
System.out.println("And 2: " + result);
@ShmuelMofrad
ShmuelMofrad / IntegerOrString.java
Created November 29, 2017 17:41
Integer.getInteger and Integer.valueOf in java
public class IntegerOrString {
public static void main(String[] args) {
String object1 = "S124";
String object2 = "124-ab45";
String object3 = "124";
int result1, result2, result3;
/* public static Integer getInteger(String nm) */
@ShmuelMofrad
ShmuelMofrad / Java-Maven-Project.md
Last active November 29, 2017 18:00
How to create a Java project with Maven in terminal

How to create a Java project with Maven in terminal

Java, Maven

in your workspace run terminal and write:

$ mvn archetype:generate -DinteractiveMode=false  -DgroupId=one.unus -DartifactId=one.unus.project
-Dpackage=one.unus.project.app -Dversion=0.0.1
@ShmuelMofrad
ShmuelMofrad / NotImplementedException.java
Created November 29, 2017 18:18
Exception to throw in java for not supported or implemented method
public class NotImplementedException {
public static void main(String[] args) {
NewUseCase();
}
static void NewUseCase() {
//TODO Should be implemented.
throw new UnsupportedOperationException("not yet implemented and should be implemented!");
@ShmuelMofrad
ShmuelMofrad / ListIsNotNull.java
Created November 29, 2017 18:24
This class has checked whether a list is null
import java.util.Collections;
import java.util.List;
public class ListIsNotNull {
public static void main(String[] args) {
if(myList() != null) {
System.out.println(true);
} else {
@ShmuelMofrad
ShmuelMofrad / MyClassCannotExtendFinalClass.java
Created November 29, 2017 18:37
You cannot extend a class that is marked as final - java
public class MyClassCannotExtendFinalClass extends String{
/*
* cannot subclass the final class String.
* String is a final class.
* You cannot extend a class that is marked as final.
*
*/
}
@ShmuelMofrad
ShmuelMofrad / SeeClassPath.java
Created November 29, 2017 18:44
How to get classpath from classloader?
import java.net.URL;
import java.net.URLClassLoader;
public class SeeClassPath {
public static void main(String[] args) {
getClasspathFromClassloader();
}
static void getClasspathFromClassloader() {
@ShmuelMofrad
ShmuelMofrad / IPv4.java
Created November 29, 2017 18:55
IPv4 - represents a Network Interface address
import java.net.InterfaceAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
public class IPv4 {
public static void main(String[] args) throws SocketException {
getIPv4();
}
@ShmuelMofrad
ShmuelMofrad / HaveYouDesktop.java
Created November 29, 2017 19:06
Check if you have desktop - java
import java.awt.Desktop;
public class HaveYouDesktop {
public static void main(String[] args) {
if(isDesktopSupported()) {
System.out.println("Yes, Desktop Supported!");
} else {
System.out.println("Not Desktop Supported!");
}
@ShmuelMofrad
ShmuelMofrad / javap.md
Created November 29, 2017 19:20
Javap - Disassembles class files.

Javap - Disassembles class files.

path: [jdk-path] / bin

$ javap -help
 
Usage: javap <options> <classes>