In this post under Java LDAP, I will show with example how to retrieve an attribute of an existing ldap entry. For our example we will take the below ldap entry. Please note in the above screenshot, all the attributes have only one value except attribute “telephoneNumber” which has 2 values. Below is the complete…… Continue reading Retrieving attribute of an ldap entry
Tag: Java
InitialDirContext lookup method
In this post under Java LDAP, I will show how to lookup for an entry in LDAP directory tree using ldap distinguished name. Below is the complete main class for your reference Main class 1 package package2; 2 3 import java.util.Hashtable; 4 5 import javax.naming.Context; 6 import javax.naming.NamingException; 7 import javax.naming.directory.DirContext; 8 import javax.naming.directory.InitialDirContext; 9…… Continue reading InitialDirContext lookup method
Connecting to LDAP server
In this post under Java LDAP, I will explain how to connect to LDAP server with an example. Below is the complete code Main Code 1 import java.util.Hashtable; 2 3 import javax.naming.Context; 4 import javax.naming.NamingException; 5 import javax.naming.directory.DirContext; 6 import javax.naming.directory.InitialDirContext; 7 8 public class LDAPDemo1 { 9 public static void main(String[] args) { 10…… Continue reading Connecting to LDAP server
Adding and accessing static members to Java Record
In this post under Java, I will show with example how to add and access static members in Java Record. Below is the structure of “Student” Record with static members Student 1 package core.record;2 3 public record Student(int id, String name, int age) {4 public static int noOfStudents;5 public static void display() {6 System.out.println(“Number of…… Continue reading Adding and accessing static members to Java Record
Simple Java Record Example
In this post under Java, I will introduce you with example to Java’s Record classes. Introduced in Java 16, is a immutable data class, whose main purpose is hold read only data. Below shows how to create Record class. Person Record package core.record;public record Person(int id, String name, int age) {} We save the file…… Continue reading Simple Java Record Example
Merging two character arrays
In this post under Java. I will show with example how to merge two character arrays into one. Below is the complete code for your reference. Main Class 1 package core.string; 2 3 public class Example1 { 4 public static void main(String[] args) { 5 char[] inputArray1 = {‘a’, ‘b’, ‘c’}; 6 char[] inputArray2 =…… Continue reading Merging two character arrays
Merging text files
In this post under Java I will with example how to merge two or more text files. Below is the complete code for your reference Main class 1 package io;2 3 import java.io.*;4 5 public class IOExample3 {6 private static int BYTES_TO_BE_READ = 1000;7 private char buffer[] = new char[BYTES_TO_BE_READ];8 9 public static void main(String[]…… Continue reading Merging text files
Creating text file of user specified size with random data
In this post under Java, I will show with example how to create a text file of user specified size with random data. Below is the complete code for you example Main class 1 package io;2 3 import java.io.BufferedWriter;4 import java.io.File;5 import java.io.FileWriter;6 import java.io.IOException;7 import java.util.Random;8 9 public class IOExample1 {10 private Random random;11…… Continue reading Creating text file of user specified size with random data
Uncompressing a gzip file
In this post under Java, I will show with example how to uncompress a gzip format file. For decompressing a gzip file, we will use java provided “GZIPInputStream” class. Below is the main code for your reference Main class 1 package zip; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import java.io.FileOutputStream; 6 import java.io.IOException;…… Continue reading Uncompressing a gzip file
Compressing a file in gzip format
In this post under Java, I will show with example how to compress a single file in gzip format. For compressing a file in gzip format, we will use java provided “GZIPOutputStream” class. Below is the main code for your reference Main Class 1 package zip; 2 3 import java.io.File; 4 import java.io.FileInputStream; 5 import…… Continue reading Compressing a file in gzip format