Computer Memory

Memory is major part of computers that categories into several types. Memory is best storage part to the computer users to save information, programs and etc, The computer memory offer several kinds of storage media some of them can store data temporarily and some them can store permanently. Memory consists of instructions and the data saved into computer through Central Processing Unit (CPU).

Sixteen Thorns by Maureen Brannigan. $6.99 from Smashwords.com
The ancient treasure, The Rock of Ages, has been stolen. Megan Cameron (journalist and hotel co-owner) worries her godmother is the thief. Unusual people arrive on Arran, Scotland, including handsome, mysterious Ben. Megan unearths information about the Rock. Her world and heart are turned upside down. Her suspicions are quashed in a harrowing stand-off with the true thief on the Holy Isle.

The performance of computer mainly based on memory and CPU. Memory is internal storage media of computer that has several names such as majorly categorized into two types, Main memory and Secondary memory.

1. Primary Memory / Volatile Memory:

Primary Memory also called as volatile memory because the memory can’t store the data permanently. Primary memory select any part of memory when user want to save the data in memory but that may not be store permanently on that location. It also has another name i.e. RAM.

Random Access Memory (RAM):

The primary storage is referred to as random access memory (RAM) due to the random selection of memory locations. It performs both read and write operations on memory. If power failures happened in systems during memory access then you will lose your data permanently. So, RAM is volatile memory. RAM categorized into following types.

DRAM
SRAM
DRDRAM

2. Secondary Memory / Non Volatile Memory:

Secondary memory is external and permanent memory that is useful to store the external storage media such as floppy disk, magnetic disks, magnetic tapes and etc cache devices. Secondary memory deals with following types of components.

Read Only Memory (ROM) :

ROM is permanent memory location that offer huge types of standards to save data. But it work with read only operation. No data lose happen whenever power failure occur during the ROM memory work in computers.

ROM memory has several models such names are following.

1. PROM: Programmable Read Only Memory (PROM) maintains large storage media but can’t offer the erase features in ROM. This type of RO maintains PROM chips to write data once and read many. The programs or instructions designed in PROM can’t be erased by other programs.

2. EPROM : Erasable Programmable Read Only Memory designed for recover the problems of PROM and ROM. Users can delete the data of EPROM thorough pass on ultraviolet light and it erases chip is reprogrammed.

3. EEPROM: Electrically Erasable Programmable Read Only Memory similar to the EPROM but it uses electrical beam for erase the data of ROM.

Cache Memory: Mina memory less than the access time of CPU so, the performance will decrease through less access time. Speed mismatch will decrease through maintain cache memory. Main memory can store huge amount of data but the cache memory normally kept small and low expensive cost. All types of external media like Magnetic disks, Magnetic drives and etc store in cache memory to provide quick access tools to the users.

Beginnners should learn these simple Programming Languages

1. Python

The coolest coding language to learn for the first time beginners is Python. Python is open source and free to use, even for commercial applications. It is usually referred to as a scripting language, allowing programmers to create out large numbers of easily readable and functional code in short periods of time. It’s also dynamic, and supports object-oriented, procedural, and functional programming styles, among others. Python is one of the most widely used high-level programming languages today.

Python is used by companies such as Google, Yahoo! and NASA. Django is the web application framework written by Python, which powers very popular sites such as Instagram, Pinterest and The New York Times.


2. Ruby

Ruby is simple, readable and for people who don’t have any kind of programming experience. Ruby is a dynamic, object-oriented scripting language that is used in the development of websites and mobile apps. It is the language that powers their framework, Ruby on Rails, which is behind websites such as Twitter, Groupon and GitHub. It is also mostly used for backend development, and popular sites such as Airbnb, Shopify, Bloomberg, Hulu, and Slideshare.

When learning Ruby, you don’t have to learn a billion new commands, like in some other coding languages. Its developer, Yukihiro Matsumoto, has designed it to be easy and practical.

It is easy to learn with a helpful 20 minute quick start guide on the official Ruby website. There are a lot of documentation available as well as great resources that will help you to understand Ruby from the very beginning.


3. JavaScript
JavaScript is a primarily client-side scripting language used for front-end development. Java is a programming language while JavaScript is a scripting language. JavaScript is the most commonly used programming language to create cool websites and games for the web. It is dynamic and is flexible to use on object-oriented programming. It derives much of its syntax from The C Language.

It runs on every single platform and is already in your browser for you to start learning, which means you need not install it. If you want to build anything for the web, then JavaScript must be on your list of programs to learn. However, JavaScript is also known to be a difficult language as it is untyped and thus is difficult to debug.


4. Java

Java is one of the most popular and general purpose programming language in the world. It is a class-based, object-oriented language and designed to be portable, which means that you can find it on all platforms, operating systems and devices.

Java is usually used to build Android apps, desktop apps, and video games. It is also commonly used as a server-side language for enterprise-level backend development. In addition, it adds to the capabilities of the C++ language. So, if you already have knowledge of C++, it will help with learning Java.
Java programming is a highly sought after skill, as having knowledge of it opens a lot of avenues in terms of employment. If you want to give it a try, go to Learn Java Online and start with the lessons today.

5. C/C++

C is often used to program system software and is the lingua franca of Operating Systems. C has influenced almost all programming languages, especially C++. So, if you know C well, you would probably have less difficulty picking up other popular languages.
On the other hand, C++ is a powerful language based on C, which has added object-oriented features like classes to the language, along with virtual functions and templates. C++ is another of the world’s most popular programming languages and is designed for programming systems software. It is still widely used to build games/game engines, desktop apps, mobile apps, and web apps. C++ is powerful and fast, which has been used to build software such as Adobe Systems, Amazon, Paypal, Chrome, and more. Much like C, C++ is generally considered harder for beginners to learn on their own. 
x

Overview of Computers

Two systems of computers:
1) PC – the Personal Computer              
2) Mac – the Apple Macintosh.

Two designs of computers:
1) desktop
2) laptop (notebook)

Computer architecture:  
Main components of a computer            Multimedia devices                  Other peripheral devices

1)  computer                                        1)  CD-ROM / DVD drive         1)  printer            
2)  monitor                                          2)  video card                              2)  scanner  
3)  hard disk/ hard drive                      3)  soundcard                              3) CD-recorder,CD-R/CD- RW  4)  keyboard                                        4)  speakers                                4)  modem      
5)  mouse / trackball /                         5)  headphones / headset             5)  USB flash drive                
    touch pad                                        6)  microphone                             6)  webcam            
                                                                                                                 7)  digital camera
                                                                                                                 8)  digital voice recorder
                                                                                                                 9)  camcorder
Inside the Computer

1) Processor:
The CPU (Central Processing Unit), a complete computation engine that is fabricated on a single chip, is the computer’s brain. It is sometimes referred to as the central processor, microprocessor, or just processor. Two typical components of a CPU are: 1) the arithmetic logic unit (ALU), which performs arithmetic and logical operations, and 2) the control unit, which extracts instructions from memory and decodes and executes them, calling on the ALU when necessary.

2) Memory:
ROM (Read Only Memory) is the computer’s permanent, long-term memory. Tere are types of ROM called PROM that can be altered. The P stands for programmable. ROM's purpose is to store the basic input/output system (BIOS) that controls the start-up, or boot process.
RAM (Random Access Memory) is a working area where the operating system (e.g. Windows), programs and data in current use are kept, ready to be accessed by the processor. It is the best known form of computer memory. However, RAM, unlike ROM, is emptied when the computer is switched off. The more RAM you have, the quicker and more powerful your computer is.
There are two basic types of RAM: dynamic RAM (DRAM) and static RAM (SRAM).
The two types differ in the technology they use to hold data. DRAM, the more common type, needs to be refreshed thousands of times per second. SRAM does not need to be refreshed, which makes it faster, but it is also more expensive than DRAM.

Memory is measure in the following units:
-  1 byte = 8 bits (Each 1 or 0 is called a bit (i.e. binary digit). Each character (i.e. a letter, a number, a space, or a punctuation mark) has its own arrangements of 8 bits, e.g. 01000001 = “A”, 01000010 = “B”.
-  1 KB (kilobyte) = 1024 (210) bytes
-  1 MB (megabyte) = 1024 (210) KB
-  1 GB (gigabyte) = 1024 (210) MB
     
Cache (pronounced as "cash") is a buffer (made of a small number of very fast memory chips) between main memory and the processor. It temporarily stores recently accessed or frequently-used data. Whenever the processor needs to read data, it looks in this cache area first. If it finds the data in the cache, then the processor does not need to do more time-consuming reading of data from the main memory. Memory caching allows data to be accessed more quickly.

Storage Devices
The most common forms of storage devices in a home computer are:
- Hard disk drive
- Floppy disk
- CD-ROM
- CD-R and CD-RW
- DVD-ROM
- USB flash drives

Monitor
There are two types of monitors available for PCs: the traditional CRT (cathode ray tube) and the newer LCD (liquid crystal display). The CRT is used for both televisions and computers. It produces a good quality image at a number of different settings for a reasonable price. LCD monitors, also known as flat panel displays, are used in laptop (or notebook) computers and more frequently for desktops as well. They are lighter and smaller (only inches thick) than CRTs with reduced electromagnetic emissions and power consumption.

Video Card
The card here is a jargon for an electronic circuit board. Video cards are also known as graphics cards, which are responsible for displaying 2D and 3D images on your monitor. 2D graphics are the regular pictures and images that appear on your screen while 3D graphics are mostly used in games and imaging.

Sound Card
A sound card is an electronic circuit board that is mounted inside the computer to control sound output to speakers or headphones, to record sound input from a microphone connected to the computer, and to manipulate sound stored on a disk. Sound cards are essential for multimedia applications and have become common on modern personal computers.
Many sound cards are also Windows-compatible. Many multimedia applications require the system to have a Windows-compatible sound card to run properly.

Ports
A port is an interface on a computer to which you can connect a device. Personal computers have various types of ports. Internally, there are several ports for connecting disk drives, monitors, and keyboards. Externally, personal computers have ports for connecting modems, printers, mice, and other peripheral devices.

There are three common types of external ports that usually come with a computer:

1) Parallel ports (for most printers)
2) Serial ports (for most modems and some mice)
3) USB (Universal Serial Bus) ports (for about every peripheral made in a USB version)

Java - Basic Syntax

When we consider a Java program, it can be defined as a collection of objects that communicate via invoking each other's methods. Let us now briefly look into what do class, object, methods, and instance variables mean.

Object − Objects have states and behaviors. Example: A dog has states - color, name, breed as well as behavior such as wagging their tail, barking, eating. An object is an instance of a class.

Class − A class can be defined as a template/blueprint that describes the behavior/state that the object of its type supports.

Methods − A method is basically a behavior. A class can contain many methods. It is in methods where the logics are written, data is manipulated and all the actions are executed.

Instance Variables − Each object has its unique set of instance variables. An object's state is created by the values assigned to these instance variables.

Java - Overview

Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform (Java 1.0 [J2SE]).

With the advancement of Java and its widespread popularity, multiple configurations were built to suit various types of platforms.

The new J2 versions were renamed as Java SE, Java EE, and Java ME respectively. Java is guaranteed to be Write Once, Run Anywhere.

Java is 

Object Oriented − In Java, everything is an Object. Java can be easily extended since it is based on the Object model.

Platform Independent − Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.

Simple − Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master.

Secure − With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.

Architecture-neutral − Java compiler generates an architecture-neutral object file format, which makes the compiled code executable on many processors, with the presence of Java runtime system.

Portable − Being architecture-neutral and having no implementation dependent aspects of the specification makes Java portable. Compiler in Java is written in ANSI C with a clean portability boundary, which is a POSIX subset.

Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking.

Multithreaded − With Java's multithreaded feature it is possible to write programs that can perform many tasks simultaneously. This design feature allows the developers to construct interactive applications that can run smoothly.

Interpreted − Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and light-weight process.

High Performance − With the use of Just-In-Time compilers, Java enables high performance.

Distributed − Java is designed for the distributed environment of the internet.

Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.

History of Java

James Gosling initiated Java language project in June 1991 for use in one of his many set-top box projects. The language, initially called ‘Oak’ after an oak tree that stood outside Gosling's office, also went by the name ‘Green’ and ended up later being renamed as Java, from a list of random words.

Sun released the first public implementation as Java 1.0 in 1995. It promised Write Once, Run Anywhere (WORA), providing no-cost run-times on popular platforms.

On 13 November, 2006, Sun released much of Java as free and open source software under the terms of the GNU General Public License (GPL).

On 8 May, 2007, Sun finished the process, making all of Java's core code free and open-source, aside from a small portion of code to which Sun did not hold the copyright.

Java String - Programming Examples

1. How to compare two strings in Java ?

2. How to search the last position of a substring ?

3. How to remove a particular character from a string ?

4. How to replace a substring inside a string by another one ?

5. How to reverse a String?

6. How to search a word inside a string ?

7. How to convert a string totally into upper case?

8. How to optimize string concatenation ?

How to optimize string concatenation ?

Following example shows performance of concatenation by using "+" operator and StringBuffer.append() method.

public class StringConcatenate {
   public static void main(String[] args) {
      long startTime = System.currentTimeMillis();
     
      for(int i = 0;i<5000 i="" p="">         String result = "This is"
            + "testing the"
            + "difference"+ "between"
            + "String"+ "and"+ "StringBuffer";
      }
      long endTime = System.currentTimeMillis();
      System.out.println("Time taken for string"
         + "concatenation using + operator : "
         + (endTime - startTime)+ " ms");
      long startTime1 = System.currentTimeMillis();
     
      for(int i = 0;i<5000 i="" p="">         StringBuffer result = new StringBuffer();
         result.append("This is");
         result.append("testing the");
         result.append("difference");
         result.append("between");
         result.append("String");
         result.append("and");
         result.append("StringBuffer");
      }
      long endTime1 = System.currentTimeMillis();
      System.out.println("Time taken for String concatenation"
         + "using StringBuffer : "
         + (endTime1 - startTime1)+ " ms");
   }
}

Result
The above code sample will produce the following result. The result may vary.

Time taken for stringconcatenation using + operator : 0 ms
Time taken for String concatenationusing StringBuffer : 22 ms

-------------------------------------------------------------------------------------------------------------

How to do string concatenation ?

Following example shows concatenation string. This method returns a String with the value of the String passed into the method, appended to the end of the String, used to invoke this method.

public class HelloWorld {
   public static void main(String []args) {
      String s = "Hello";
      s = s.concat("word");
      System.out.print(s);
   }
}

Result
The above code sample will produce the following result. The result may vary.

Helloword

How to convert a string totally into upper case?

Following example changes the case of a string to upper case by using String toUpperCase() method.

public class StringToUpperCaseEmp {
   public static void main(String[] args) {
      String str = "string abc touppercase ";
      String strUpper = str.toUpperCase();
      System.out.println("Original String: " + str);
      System.out.println("String changed to upper case: " + strUpper);
   }
}

Result
The above code sample will produce the following result.

Original String: string abc touppercase 
String changed to upper case: STRING ABC TOUPPERCASE 

How to search a word inside a string ?

This example shows how we can search a word within a String object using indexOf() method which returns a position index of a word within the string if found. Otherwise it returns -1.

public class SearchStringEmp{
   public static void main(String[] args) {
      String strOrig = "Hello readers";
      int intIndex = strOrig.indexOf("Hello");
     
      if(intIndex == - 1) {
         System.out.println("Hello not found");
      } else {
         System.out.println("Found Hello at index " + intIndex);
      }
   }
}

Result
The above code sample will produce the following result.

Found Hello at index 0

This example shows how we can search a word within a String object

public class HelloWorld {
   public static void main(String[] args) {
      String text = "The cat is on the table";
      System.out.print(text.contains("the"));
   }
}

Result
The above code sample will produce the following result.

true

How to reverse a String?

Following example shows how to reverse a String after taking it from command line argument .The program buffers the input String using StringBuffer(String string) method, reverse the buffer and then converts the buffer into a String with the help of toString() method.

public class StringReverseExample{
   public static void main(String[] args) {
      String string = "abcdef";
      String reverse = new StringBuffer(string).reverse().toString();
      System.out.println("\nString before reverse: "+string);
      System.out.println("String after reverse: "+reverse);
   }
}

Result
The above code sample will produce the following result.

String before reverse:abcdef
String after reverse:fedcba

Example

Following another example shows how to reverse a String after taking it from command line argument

import java.io.*;
import java.util.*;

public class HelloWorld {
   public static void main(String[] args) {
      String input = "tutorialspoint";
      char[] try1 = input.toCharArray();
      for (int i = try1.length-1;i>=0;i--) System.out.print(try1[i]);
   }
}

The above code sample will produce the following result.

tniopslairotut 

How to replace a substring inside a string by another one ?

This example describes how replace method of java String class can be used to replace character or substring by new one.

public class StringReplaceEmp{
   public static void main(String args[]){
      String str = "Hello World";
      System.out.println( str.replace( 'H','W' ) );
      System.out.println( str.replaceFirst("He", "Wa") );
      System.out.println( str.replaceAll("He", "Ha") );
   }
}


Result
The above code sample will produce the following result.

Wello World
Wallo World
Hallo World

How to remove a particular character from a string ?

Following example shows hoe to remove a character from a particular position from a string with the help of removeCharAt(string,position) method.

public class Main {
   public static void main(String args[]) {
      String str = "this is Java";
      System.out.println(removeCharAt(str, 3));
   }
   public static String removeCharAt(String s, int pos) {
      return s.substring(0, pos) + s.substring(pos + 1);
   }
}


Result
The above code sample will produce the following result.

this is Java

How to search the last position of a substring ?

This example shows how to determine the last position of a substring inside a string with the help of strOrig.lastIndexOf(Stringname) method.

public class SearchlastString {
   public static void main(String[] args) {
      String strOrig = "Hello world ,Hello Reader";
      int lastIndex = strOrig.lastIndexOf("Hello");
     
      if(lastIndex == - 1){
         System.out.println("Hello not found");
      } else {
         System.out.println("Last occurrence of Hello is at index "+ lastIndex);
      }
   }
}

Result

The above code sample will produce the following result.

Last occurrence of Hello is at index 13

Example

This another example shows how to determine the last position of a substring inside a string with the help of strOrig.lastIndexOf(Stringname) method.

public class HelloWorld{
   public static void main(String []args) {
      String t1 = "Tutorialspoint";
      int index = t1.lastIndexOf("p");
      System.out.println(index);
   }
}

The above code sample will produce the following result.

9

How to compare two strings in Java ?

Following example compares two strings by using str compareTo (string), str compareToIgnoreCase(String) and str compareTo(object string) of string class and returns the ascii difference of first odd characters of compared strings.

public class StringCompareEmp{
   public static void main(String args[]){
      String str = "Hello World";
      String anotherString = "hello world";
      Object objStr = str;

      System.out.println( str.compareTo(anotherString) );
      System.out.println( str.compareToIgnoreCase(anotherString) );
      System.out.println( str.compareTo(objStr.toString()));
   }
}

Result
The above code sample will produce the following result.

-32
0
0

String compare by equals()

This method compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

public class StringCompareequl{
   public static void main(String []args){
      String s1 = "tutorialspoint";
      String s2 = "tutorialspoint";
      String s3 = new String ("Tutorials Point");
      System.out.println(s1.equals(s2));
      System.out.println(s2.equals(s3));
   }
}

The above code sample will produce the following result.

true 

false 

String compare by == operator
public class StringCompareequl{
   public static void main(String []args){
      String s1 = "tutorialspoint";
      String s2 = "tutorialspoint";
      String s3 = new String ("Tutorials Point");
      System.out.println(s1 == s2);
      System.out.println(s2 == s3);
   }
}

The above code sample will produce the following result.

true

false 

Environment in Java programming

Commonly used examples:-

1. How to compile a java file?

2. How to run a class file?

3. How to debug a java file?

4. How to set classpath?

5. How to view current classpath?

6. How to set destination of the class file?

7. How to run a compiled class file?

8. How to check version of java running on your system?

9. How to set classpath when class files are in .jar file?

How to set classpath when class files are in .jar file?

Following example shows how to set class path when classes are stored in a .jar or .zip file.

c:> java -classpath C:\java\myclasses.jar utility.testapp.main

Result

The above code sample will produce the following result.

Class path set.

How to check version of java running on your system?

Following example shows how to check version of java installed on your system using version argument with java command.

java -version

Result

The above code sample will produce the following result.

java version "1.6.0_13"
Java(TM) SE Runtime Environment (build 1.6.0_13-b03)
Java HotSpot(TM) Client VM (build 11.3-b02, mixed mode, sharing)

How to run a class file?

Following example shows how to run a class file from command prompt using java command.

c:\jdk\demoapp>java First 

Result

The above code sample will produce the following result.

Demo application executed.

How to set destination of the class file?

Following example shows how to set destination of the class file that will be created after compiling a java file using -d option with javac command.

c:> javac demo.java -d c:\myclasses 

Result

The above code sample will produce the following result.

Demo application executed.

How to view current classpath?

Following example shows how to view current classpath using echo command.

C:> echo %CLASSPATH%

Result

The above code sample will produce the following result.

.;C:\Program Files\Java\jre1.6.0_03\lib\ext\QTJava.zip

How to set classpath?

Following example shows how to set classpath.

C:> java -classpath C:\java\DemoClasses utility.demoapp.main

Result

The above code sample will produce the following result.

Class path set.

How to set destination of the class file?

Following example shows how to debug a java file using =g option with javac command.

c:> javac demo.java -g

Result

The above code sample will produce the following result.

Demo.java will debug.

How to set multiple classpath in Java?

Following example shows how to set multiple classpath. Multiple class paths are separated by a semicolon.

c:> java -classpath C:\java\MyClasse1;C:\java\MyClass2 
   utility.testapp.main

Result

The above code sample will produce the following result.

Class path set.

How to Compile a Java file

Following example shows how to compile a java file using javac command.

c:\jdk\demoapp> javac First.java 


Result

The above code sample will produce the following result.

First.java compile successfully.