Knowledge in Java Classes

System properties in Java

System properties.The System class provides access to the configuratoin of the current working environment. You can access them, viaSystem.getProperty("property_name"), for example System.getProperty("path.separator"); The following lists describes the most important properties."line.separator" - Sequence used by operating system to separate lines in text files"user.dir" - User working directory"user.home" - User home directory == Schedule tasksJava allows you to schedule tasks. A scheduled tasks can perform once or several times.java.util.Timer and java.util.TimerTask can be used to schedule tasks. The object which implementsTimeTask will then be performed by the Timer based on the given interval.package schedule; import java.util.TimerTask; public class MyTask extends TimerTask { private final String string; private int count = 0; public MyTask(String string) { this.string = string; } @Override public void run() { count++; System.out.println(string + " called " + count); } } package schedule; import java.util.Timer; public class ScheduleTest { public static void main(String[] args) { Timer timer = new Timer(); // wait 2 seconds (2000 milli-secs) and then start timer.schedule(new MyTask("Task1"), 2000); for (int i = 0; i < 100; i++) { // wait 1 seconds and then again every 5 seconds timer.schedule(new MyTask("Task " + i), 1000, 5000); } } }

Compare Strings in Java

Compare Strings in JavaTo compare the String objects s1 and s2, use the s1.equals(s2) method.A String comparison with == is incorrect, as == checks for object reference equality. == sometimes gives the correct result, as Java uses a String pool. The following example would work with ==.This would work as expected.String a = "Hello"; String b = "Hello"; if (a==b) { // if statement is true // because String pool is used and // a and b point to the same constant } This comparison would fail.String a = "Hello"; String b = new String("Hello"); if (a==b) { } else { // if statement is false // because String pool is used and // a and b point to the same constant }

The while loop in Java

The while loopA while loop is a repetition control structure that allows you to write a block of code which is executed until a specific condition evaluates to false. The syntax is the following.while(expression) { // block of code to run } The following shows an example for a while loop.public class WhileTest { public static void main(String args[]) { int x = 1; while (x < 10) { System.out.println("value of x : " + x); x++; } } }

Switch in Java

SwitchThe switch statement can be used to handle several alternatives if they are based on the same constant value.switch (expression) { case constant1: command; break; // will prevent that the other cases or also executed case constant2: command; break; ... default: } // Example: switch (cat.getLevel()) { case 0: return true; case 1: if (cat.getLevel() == 1) { if (cat.getName().equalsIgnoreCase(req.getCategory())) { return true; } } case 2: if (cat.getName().equalsIgnoreCase(req.getSubCategory())) { return true; } } // you can also use the same logic for different constants public static void main(String[] args) { for (int i = 0; i < 6; i++) { switch (i) { case 1: case 5: System.out.println("Hello"); break; default: System.out.println("Default"); break; } } } }

Base Java language structure

Base Java language structure1)ClassA class is a template that describes the data and behavior associated with an instance of that class.A class is defined by the class keyword and must start with a capital letter. The body of a class is surrounded by {}.package test; class MyClass { } The data associated with a class is stored in variables ; the behavior associated to a class or object is implemented withmethods.A class is contained in a text file with the same name as the class plus the .java extension. It is also possible to define inner classes, these are classes defined within another class, in this case you do not need a separate file for this class2)ObjectAn object is an instance of a class.The object is the real element which has data and can perform actions. Each object is created based on the class definition. The class can be seen as the blueprint of an object, i.e., it describes how an object is created.

Java Getting Started

Java InstallSome PCs might have Java already installed.To check if you have Java installed on a Windows PC, search in the start bar for Java or type the following in Command Prompt (cmd.exe):C:\Users\Your Name>java -versionIf Java is installed, you will see something like this (depending on version):java version "11.0.1" 2018-10-16 LTSJava(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)If you do not have Java installed on your computer, you can download it for free from oracle.com.

JavaScript Tutorial

JavaScript TutorialExamples in Each ChapterWith our "Try it Yourself" editor, you can edit the source code and view the result.ExampleMy First JavaScriptClick me to display Date and TimeWe recommend reading this tutorial, in the sequence listed in the left menu.Learn by ExamplesExamples are better than 1000 words. Examples are often easier to understand than text explanations.This tutorial supplements all explanations with clarifying "Try it Yourself" examples.JavaScript ExamplesIf you try all the examples, you will learn a lot about JavaScript, in a very short time!Why Study JavaScript?JavaScript is one of the 3 languages all web developers must learn:  1. HTML to define the content of web pages  2. CSS to specify the layout of web pages  3. JavaScript to program the behavior of web pagesWeb pages are not the only place where JavaScript is used. Many desktop and server programs use JavaScript. Node.js is the best known. Some databases, like MongoDB and CouchDB, also use JavaScript as their programming language.Did You Know?JavaScript and Java are completely different languages, both in concept and design.JavaScript was invented by Brendan Eich in 1995, and became an ECMA standard in 1997.ECMA-262 is the official name of the standard. ECMAScript is the official name of the language.You can read more about the different JavaScript versions in the chapter JS Versions.Learning SpeedIn this tutorial, the learning speed is your choice.Everything is up to you.If you are struggling, take a break, or reread the material.Always make sure you understand all the "Try-it-Yourself" examples.JavaScript ReferencesW3Schools maintains a complete JavaScript reference, including all HTML and browser objects.The reference contains examples for all properties, methods and events, and is continuously updated according to the latest web standards.Complete JavaScript Reference

User Defined Exceptions in Java

This Power Point Presentation is about User Defined Exceptions in Java.

Swings in Java

It explains about Graphical User interface concepts And difference between AWT and SWINGS.

Head First Java

It is the PDF of Head First Java Programming book All the topics are covered in this book it is also considered the best programming book

The Stream API - Java Tutorials

This PDF is about The Stream API - Java Tutorials . This is a part of book by Luliana Cosmina.

Working with Files - Java Tutorials

This PDF is about Working with Files - Java Tutorials . This is a part of book by Luliana Cosmina.