How to get Bash version number in Mac OS
Following command can be used to know the bash version in Mac OS.
Map<Integer, String> map = new HashMap<>();
map.put(1,"Argentina");
map.put(2,"France");
map.put(3,"Brazil");
map.put(4,"Germany");
//EntrySet Iterator
System.out.println("\nEntrySet foreach");
Iterator<Entry<Integer, String>> it = map.entrySet().iterator();
while(it.hasNext()) {
Map.Entry<Integer, String> keyVal = it.next();
System.out.println(keyVal.getKey() + " " + keyVal.getValue());
}
//EntrySet and foreach
System.out.println("\nEntrySet foreach");
Set<Entry<Integer, String>> entrySet = map.entrySet();
entrySet.forEach((e-> { System.out.println(e.getKey() + " " + e.getValue());}));
//Keyset Iterator
System.out.println("\nKeyset Iterator");
Iterator<Integer> kit = map.keySet().iterator();
while(kit.hasNext()) {
Integer key = kit.next();
System.out.println(key + " " + map.get(key));
}
//Keyset For loop
System.out.println("\nKeyset For loop");
for (Integer key : map.keySet()) {
System.out.println(key + " " + map.get(key));
}
//map foreach (Java 8 Lambda)
System.out.println("\nUsing Map.foreach (Java 8 Lambda");
map.forEach((key,value)-> {System.out.println(key + " " + value);});
import java.util.LinkedHashMap;
import java.util.Map;
public class MapRemoveEntry {
public static void main(String argv[]) {
LinkedHashMap<Integer, String> map = new LinkedHashMap<Integer, String>() {
private static final long serialVersionUID = 1L;
protected boolean removeEldestEntry(Map.Entry<Integer,String> eldest) {
return size() > 4;
}
};;
map.put(0, "A");
map.put(1, "B");
map.put(2, "C");
map.put(3, "D");
map.put(4, "E");
map.forEach((k,v) -> { System.out.println("key = " + k + " value = " + v);});
}
}
key = 1 value = B key = 2 value = C key = 3 value = D key = 4 value = E
package java17.sealed;
public abstract sealed class Tesla permits Model3, ModelS, TeslaSUV{
public abstract Integer maxRange();
public String basePrice() {
return "25000 USD";
}
}
//Subclass 1
public final class Model3 extends Tesla {
@Override
public Integer maxRange() {
return 200;
}
}
//Subclass 2
public final class ModelS extends Tesla {
@Override
public Integer maxRange() {
return 400;
}
}
//Subclass3 (non-sealed)
public non-sealed class TeslaSUV extends Tesla {
@Override
public Integer maxRange() {
// TODO Auto-generated method stub
return null;
}
}
package java17.sealed;
public sealed class BMWCars {
public final class BMW3 extends BMWCars implements ElectricVehicle{
}
public final class BMWI extends BMWCars implements Vehicle {
}
public non-sealed class BMWJV extends BMWCars implements Vehicle {
}
}
package Java14;
public record AddressRecord(String street, String city, Integer zip, String state, String country) {
}
package Java14;
public class AddressRecordDemo {
public static void main (String arg[]) {
AddressRecord address1 = new AddressRecord("1044 Main Street", "Livermore", 94550, "CA", "USA");
System.out.println(address1.street());
System.out.println(address1.city());
System.out.println(address1.state());
}
}
final class MyCustomClass {
}
import java.lang.reflect.Modifier;
public class JavaReflectionModifiers {
public static void main(String[] args) {
//prints 16
System.out.println(MyCustomClass.class.getModifiers());
//returns true
Modifier.isFinal(MyCustomClass.class.getModifiers());
}
}
final class MyCustomClass {
}
package Java14;
import java.lang.reflect.Modifier;
public class JavaReflectionModifiers {
public static void main(String[] args) {
System.out.println(MyCustomClass.class.getModifiers());
//prints true
System.out.println(Modifier.isFinal(MyCustomClass.class.getModifiers()));
//prints true
System.out.println(Modifier.isFinal(String.class.getModifiers()));
//prints false
System.out.println(Modifier.isFinal(Number.class.getModifiers()));
}
}
final class MyCustomClass {
}
record MobilePhone(String brand, String modelName, Number osVersion, boolean canFlip) {
}
package Java14;
import java.lang.reflect.Modifier;
public class RecordFinalTest {
public static void main(String[] args) {
MobilePhone phone1 = new MobilePhone("Samsung", "Galaxy1", 1, false);
//false
System.out.println(Modifier.isFinal(phone1.getClass().getModifiers()));
//false
System.out.println(Modifier.isFinal(MobilePhone.class.getModifiers()));
}
}
class MyLinkedList<E> {
/* first points to head of the list */
public Node<E> first = null;
/* last points to tail of the list */
public Node<E> last = null;
/**
* Add item to tail (end) of the List
*
* @param item
* @return
*/
public boolean add(E item) {
Node<E> newNode = new Node<E>(last, item, null);
if (last == null) {
// last points to the new node created
first = newNode;
} else {
last.next = newNode;
}
// update last so that it points to the new node
last = newNode;
return true;
}
static class Node<E> {
public E value;
public Node<E> next;
public Node<E> prev;
Node(Node<E> prev, E element, Node<E> next) {
this.value = element;
this.next = next;
this.prev = prev;
}
}
}
//create instance
MyLinkedList<Integer> list = new MyLinkedList<Integer>();
//add values 1,2,3,4,5
list.add(1);
list.add(2);
list.add(3);
list.add(4);
list.add(5);
//Get the first node (head node) and then print it by traversing all nodes
MyLinkedList.Node<Integer> node = list.first;
while (node != null) {
System.out.println("Content of Node: " + node.value);
node = node.next;
}
Content of Node: 1 Content of Node: 2 Content of Node: 3 Content of Node: 4 Content of Node: 5
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/themes/prism.min.css" integrity="sha256-ko4j5rn874LF8dHwW29/xabhh8YBleWfvxb8nQce4Fc=" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/prism.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/prismjs@1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
</head>
<pre>
<code class="language-java">
Java Code here
</code>
</pre>
<pre>
<code class="language-javascript">
Javascript Code here
</code>
</pre>
package java17.sealed;
public abstract sealed class Tesla permits Model3, ModelS, TeslaSUV{
public abstract Integer maxRange();
public String basePrice() {
return "25000 USD";
}
}
//Subclass 1
public final class Model3 extends Tesla {
@Override
public Integer maxRange() {
return 200;
}
}
//Subclass 2
public final class ModelS extends Tesla {
@Override
public Integer maxRange() {
return 400;
}
}
//Subclass3 (non-sealed)
public non-sealed class TeslaSUV extends Tesla {
@Override
public Integer maxRange() {
// TODO Auto-generated method stub
return null;
}
}
package java17.sealed;
public sealed class BMWCars {
public final class BMW3 extends BMWCars implements ElectricVehicle{
}
public final class BMWI extends BMWCars implements Vehicle {
}
public non-sealed class BMWJV extends BMWCars implements Vehicle {
}
}
This article shows how to install Maven (3.6.3) on macOS Monterey(version 12.2.1) with M1 processor.
x apache-maven-4.0.0-alpha-3/bin/mvn.cmd x apache-maven-4.0.0-alpha-3/bin/mvn x apache-maven-4.0.0-alpha-3/README.txt x apache-maven-4.0.0-alpha-3/LICENSE x apache-maven-4.0.0-alpha-3/NOTICE x apache-maven-4.0.0-alpha-3/lib/ x apache-maven-4.0.0-alpha-3/lib/aopalliance.license x apache-maven-4.0.0-alpha-3/lib/commons-cli.license x apache-maven-4.0.0-alpha-3/lib/commons-codec.license x apache-maven-4.0.0-alpha-3/lib/commons-lang3.license x apache-maven-4.0.0-alpha-3/lib/failureaccess.license x apache-maven-4.0.0-alpha-3/lib/guava.license x apache-maven-4.0.0-alpha-3/lib/guice.license x apache-maven-4.0.0-alpha-3/lib/httpclient.license x apache-maven-4.0.0-alpha-3/lib/httpcore.license
Apache Maven 4.0.0-alpha-3 (2ccf57baa5191468f9911fe85fd99672ac3bacb9) Maven home: /Users/SiddB/DevRuntime/apache-maven-4.0.0-alpha-3 Java version: 18.0.1.1, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-18.0.1.1.jdk/Contents/Home Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "12.2.1", arch: "aarch64", family: "mac"