Decimal to Hexadecimal Converter
Hexadecimal value:
Hex to Decimal ConverterHex to Decimal Converter
Decimal Value:
Binary to Decimal ConverterIt is all about java. Writings on java technology, programming concepts and knowledge articles especially for beginners
Hexadecimal value:
Hex to Decimal ConverterDecimal Value:
Binary to Decimal ConverterClasses and objects both are treated in similar way in all programming languages. Java is not exception.
Consider a physical class room with lot of real world objects. What we Observe in class room..?
So, a programmer needs to instruct the computer, how to create a class room object and it's subsequent objects. like, chair, table, teacher and student etc.
If programmer wants to create or develop a School application, he would need to create:
Let us now create School application with above mentioned objects and classes using java programming language.
public class School_Application{
public Student students;
public Teacher teachers;
public ClassRoom classRoom;
public School_Application(Student students, Teacher teachers, ClassRoom classRoom){
this.students = students;
this.teachers = teachers;
this.classRoom = classRoom;
}
}
Subsequently, programmer needs to create, Student, Teacher and ClassRoom classes and respective objects in main() method.
Objects in java are created using new operator. Example:
Happy coding! :)
Writing a coding solution to a problem can be done in many ways. If the solution can be obtained with less number of code lines, then it is easy to understand and maintain.
But what if code is large with having millions of lines. Moreover maintenance and readability becomes difficult as the code base grows... Right?
Every programming language mandates few norms in order to name variables, classes and functions etc. For ex: Java uses class names first letter to be a upper case and rest to be lower case letters.
But if we dig little bit more, naming conventions are not limited to only upper case or lower case letters and using alphanumeric letters etc.
Naming a variable must be enough concise as naming your first child's name...
int final static MAX_LENGHT = 2; [Correct]
Cyclomatic complexity is a measure or metric to estimate complexity level of a snippet or block of code.
Usually developing a large and scalable application, requires better design. Adhering to SOLID principles yields better scalable and easily maintainable applications.
There are five SOLID principles. They are:
DRY stands for Do Not Repeat Yourself. Sometimes, There could be a need to use same or similar set of lines of code to be used multiple times in the same application. For ex. String utilities, DB connections or updating records in database etc.
Writing frequently used code snippets multiple times is not a good practice. Instead move this code to a function or method and use this method in places where ever required.
Sometimes there are some lines or instructions in code base, which are completely not executed in all cases at all. This is considered as dead code.
Dead code reduces the quality with respect to the readability.
The reason for this difference is, the pattern of comments is identified by API document generator tools and generates API documents.
Java supports 8 different primitive data types. They are:
| GUI that represents Windows File Manager |
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
public void makeDirectory(String path, String dirName) {
Path dirPath = Path.of(path, dirName);
File dir = new File(dirPath.toString());
boolean isCreated = dir.mkdir();
if (isCreated)
System.out.println("A new directory with the name " + dir.getPath() + " created!");
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
manager.makeDirectory("e:\\", "students");
}
}
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
public void createFile(String dirPath, String dirName, String fileName) throws IOException {
Path filePath = Path.of(dirPath, dirName, fileName);
File file = new File(filePath.toString());
boolean isFileCreated = file.createNewFile();
if (isFileCreated)
System.out.println("A new file with the name " + file.getPath() + " created!");
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
manager.createFile("e:\\", "students", "student_1");
}
}
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
manager.listFiles("e:\\", "pinterest");
}
}
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
Path dir = Path.of(dirPath, dirName);
File dirToBeDeleted = new File(dir.toString());
if (dirToBeDeleted.exists()) {
boolean isDeleted = dirToBeDeleted.delete();
if(isDeleted)
System.out.println("File deleted!");
else
System.out.println("Could not delete file. File is being used by other program or application.");
}
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
manager.deleteDirectory("e:\\", "pinterest");
}
}
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
Path filePath = Path.of(dirPath, dirName, fileName);
File file = new File(filePath.toString());
FileReader reader = new FileReader(file.getAbsolutePath());
BufferedReader bufferedRead = new BufferedReader(reader);
String line = null;
while((line = bufferedRead.readLine()) != null) {
System.out.println(line);
}
bufferedRead.close();
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
manager.readFile("e:\\", "pinterest", "demo.txt");
}
}
package com.allabtjava.fileio;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Path;
public class FileManager {
public FileManager() {
}
Path filePath = Path.of(dirPath, dirName, fileName);
File file = new File(filePath.toString());
FileWriter writer = new FileWriter(file);
BufferedWriter bufferedWriter = new BufferedWriter(writer);
bufferedWriter.write("allabtjava.com is a web site, has information about java technologies \n");
bufferedWriter.write("This article explains about, files and IO management with java programming language.");
bufferedWriter.close();
}
public static void main(String args[]) throws IOException {
FileManager manager = new FileManager();
}
}
Swing library and it's categorization of components and controls Basically, Swing library provides around 50+ components. These all com...